forked from eatvio/eatvio_app
67 lines
2.6 KiB
Dart
67 lines
2.6 KiB
Dart
import 'package:eatvio_app/core/utils/pagination_utils.dart';
|
|
import 'package:eatvio_app/core/widgets/data_error_widget.dart';
|
|
import 'package:eatvio_app/core/widgets/loader.dart';
|
|
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_cubit.dart';
|
|
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_state.dart';
|
|
import 'package:eatvio_app/features/feed/presentation/widgets/diet_filter_bottom_sheet.dart';
|
|
import 'package:eatvio_app/features/feed/presentation/widgets/diets_widget.dart';
|
|
import 'package:eatvio_app/features/feed/presentation/widgets/filter_badge.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
class Diets extends StatelessWidget {
|
|
const Diets({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return RefreshIndicator(
|
|
onRefresh: () => context.read<DietsCubit>().loadDiets(),
|
|
child: BlocBuilder<DietsCubit, DietsState>(
|
|
builder: (BuildContext context, DietsState state) {
|
|
if (state.isLoading) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.grey.shade200,
|
|
body: const Loader(),
|
|
);
|
|
} else if (state.errorMessage != null) {
|
|
return DataErrorWidget(onReload: () => context.read<DietsCubit>().loadDiets());
|
|
} else {
|
|
return Stack(
|
|
children: [
|
|
const SizedBox.expand(),
|
|
NotificationListener<ScrollNotification>(
|
|
onNotification: (notification) {
|
|
loadNewContent(notification, context.read<DietsCubit>().loadNextPage);
|
|
return false;
|
|
},
|
|
child: ListView.separated(
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
shrinkWrap: true,
|
|
physics: const BouncingScrollPhysics(),
|
|
itemBuilder: (context, index) {
|
|
return DietsWidget(diet: state.dietsList[index], index: index);
|
|
},
|
|
separatorBuilder: (context, index) {
|
|
return const SizedBox(height: 8);
|
|
},
|
|
itemCount: state.dietsList.length,
|
|
),
|
|
),
|
|
Positioned(
|
|
right: 0,
|
|
bottom: 74,
|
|
child: FilterBadge(
|
|
filterBottomSheet: DietFilterBottomSheet(
|
|
dietsCubit: context.read<DietsCubit>(),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|