120 lines
3.3 KiB
Dart
120 lines
3.3 KiB
Dart
import 'package:auto_route/auto_route.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:get_it_mixin/get_it_mixin.dart';
|
|
import 'package:remever/common/resources.dart';
|
|
import 'package:remever/components/extensions/context.dart';
|
|
import 'package:remever/components/notifiers/home_screen_data.dart';
|
|
import 'package:remever/screens/collections/cubit/collection_cubit.dart';
|
|
|
|
@RoutePage()
|
|
class CollectionScreen extends StatelessWidget with GetItMixin {
|
|
CollectionScreen({super.key});
|
|
|
|
/// Флаг что надо показывать Fab
|
|
bool get _showFab {
|
|
return watchOnly<CollectionData, bool>((CollectionData d) => d.showFAB);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocProvider<CollectionCubit>(
|
|
create: (context) => CollectionCubit(),
|
|
|
|
child: Scaffold(
|
|
backgroundColor: AppColors.bg,
|
|
// appBar: const CollectionsAppBar(),
|
|
body: _buildMain(context),
|
|
floatingActionButton: Builder(
|
|
builder: (BuildContext context) {
|
|
return AnimatedOpacity(
|
|
opacity: _showFab ? 1.0 : 0.0,
|
|
duration: const Duration(milliseconds: 200),
|
|
child: FloatingActionButton(
|
|
backgroundColor: AppColors.primary,
|
|
onPressed: () {},
|
|
// context.read<HomeCubit>().toCrudCollection(CrudType.CREATE),
|
|
child: const Icon(Icons.add),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
///
|
|
/// Построение основго экрана
|
|
///
|
|
Widget _buildMain(BuildContext context) {
|
|
return BlocBuilder<CollectionCubit, CollectionState>(
|
|
builder: (context, state) {
|
|
return state.when(
|
|
loading: () => _LoadingList(),
|
|
data:
|
|
() => const Column(
|
|
children: <Widget>[
|
|
// CollectionsFilters(),
|
|
_CollectionList(),
|
|
],
|
|
),
|
|
empty: () => _EmptyList(),
|
|
error: () => _ErrorList(),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _LoadingList extends StatelessWidget {
|
|
const _LoadingList();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const Placeholder(color: Colors.green);
|
|
}
|
|
}
|
|
|
|
class _ErrorList extends StatelessWidget {
|
|
const _ErrorList();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const Placeholder(color: Colors.brown);
|
|
}
|
|
}
|
|
|
|
class _EmptyList extends StatelessWidget {
|
|
const _EmptyList();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const Placeholder(color: Colors.red);
|
|
}
|
|
}
|
|
|
|
class _CollectionList extends StatelessWidget {
|
|
const _CollectionList();
|
|
|
|
// @override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
print('build _CollectionList');
|
|
final CollectionCubit collectionCubit = context.read<CollectionCubit>();
|
|
collectionCubit.initScrollListener();
|
|
|
|
return Expanded(
|
|
child: ListView.builder(
|
|
controller: collectionCubit.collectionController,
|
|
itemCount: 20,
|
|
padding: const EdgeInsets.symmetric(horizontal: 16).r,
|
|
itemBuilder:
|
|
(BuildContext context, int index) => Padding(
|
|
padding: const EdgeInsets.only(bottom: 8).r,
|
|
// child: const CollectionCard(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|