1import 'package:easy_localization/easy_localization.dart';
2import 'package:fluentui_system_icons/fluentui_system_icons.dart';
3import 'package:flutter/material.dart';
4import 'package:flutter_bloc/flutter_bloc.dart';
5import 'package:flutter_screenutil/flutter_screenutil.dart';
7import '../../../../../../core/UI/widgets/show_documents_option.dart';
8import '../../../../../../core/common/entities/collection_entity.dart';
9import '../../../../../../core/services/documents_service.dart';
10import '../../../../../../core/ui/widgets/loading.dart';
11import '../../../../../../core/ui/widgets/stats_card.dart';
12import '../../../../../../core/ui/theme/color_palette.dart';
13import '../../../../../../core/ui/widgets/empty_content.dart';
14import '../../../bloc/history_collections/history_collections_bloc.dart';
15import '../../../../../../core/ui/widgets/collection_item/collection_item.dart';
16import '../../../../../auth/presentation/bloc/authentication_bloc/authentication_bloc.dart';
17import '../widgets/triple_tab_selector.dart';
23 State<HistoryCollectionsView>
createState() => _HistoryCollectionsViewState();
26class _HistoryCollectionsViewState
extends State<HistoryCollectionsView> {
37 final authState = context.read<AuthenticationBloc>().state;
38 if (authState is AuthenticatedState) {
40 context.read<HistoryCollectionsBloc>().add(
41 LoadHistoryCollectionsWithDateRangeEvent(
42 userId: authState.session.uid ?? 0,
48 context.read<HistoryCollectionsBloc>().add(
50 userId: authState.session.uid ?? 0,
59 final DateTimeRange? picked = await showDateRangePicker(
61 firstDate: DateTime(2020),
62 lastDate: DateTime.now(),
65 start: DateTime.now().subtract(
const Duration(days: 7)),
68 builder: (context,
child) {
70 data: Theme.of(context).copyWith(
71 colorScheme: Theme.of(context).colorScheme.copyWith(
72 primary: ColorPalette.lightGreen,
73 onPrimary: Colors.white,
90 Widget
build(BuildContext context) {
94 firstTabName:
"common.this_week".tr(),
95 secondTabName:
"common.this_month".tr(),
96 thirdTabName:
"common.calendar".tr(),
98 onTabSelected: (index) {
101 }
else if (index == 1) {
103 }
else if (index == 2) {
114 width:
double.infinity,
116 padding: EdgeInsets.symmetric(vertical: 5.sp, horizontal: 10.sp),
118 mainAxisAlignment: MainAxisAlignment.spaceBetween,
121 width: MediaQuery.sizeOf(context).width * 0.8,
123 "transactions_history.select_date_message".tr(),
124 style: Theme.of(context).textTheme.titleSmall?.copyWith(
126 fontWeight: FontWeight.w400,
131 style: OutlinedButton.styleFrom(
136 child:
const Icon(FluentIcons.calendar_20_regular),
143 child: BlocBuilder<HistoryCollectionsBloc, HistoryCollectionsState>(
144 buildWhen: (previous, current) =>
145 current is HistoryCollectionsLoading ||
147 current is HistoryCollectionsError,
148 builder: (context, state) {
150 if (state.collections.isEmpty) {
151 return EmptyContent(text:
"common.no_pending_collections".tr());
153 return ListView.builder(
154 physics:
const AlwaysScrollableScrollPhysics(),
155 itemCount: state.collections.length + 2,
156 itemBuilder: (context, index) {
158 if (_selectedPeriod ==
"calendar" && _dateRange != null) {
160 padding: EdgeInsets.only(left: 15.sp, top: 15.sp, right: 15.sp),
162 "${"transactions_history.from
".tr()} ${_formatDate(_dateRange?.start)} ${"transactions_history.to
".tr()} ${_formatDate(_dateRange?.end)}",
163 style: Theme.of(context)
167 color: ColorPalette.grey,
168 fontWeight: FontWeight.w600,
173 return const SizedBox();
177 padding: EdgeInsets.all(15.sp),
179 title:
"transactions_history.completed_collections".tr(),
180 number: state.collections.length.toString(),
182 gradient:
const LinearGradient(
183 begin: Alignment.topLeft,
184 end: Alignment.bottomRight,
196 icon: Icons.receipt_long_outlined,
200 DocumentsService.instance
201 .getCollectionVoucherDocument(
202 state.collections[index - 2].reference ??
'',
210 child: CollectionItem(
222 if (state is HistoryCollectionsError) {
223 return EmptyContent(text: state.failure.message);
225 return const Loading();
234 if (
date == null)
return '';
235 return '${date.year}-${date.month.toString().padLeft(2, '0
')}-${date.day.toString().padLeft(2, '0
')}';
240 .fold<
double>(0, (prev, element) => prev + (element.volume ?? 0))
243 return '$quanitity L';
override void initState()
class App extends StatefulWidget build(BuildContext context)
sealed class CheckInOutEvent extends Equatable userId
sealed class CollectionsState extends Equatable collections
const LoadHistoryCollectionsEvent({ required this.userId, required this.period, })
const HistoryCollectionsLoaded({required this.collections})
Future< void > _showDateRangePicker() async
String _formatDate(DateTime? date)
int _getTabSelectionIndex()
class HistoryCollectionsView extends StatefulWidget _selectedPeriod
void _loadHistoryCollections()
String _getCollectionQuantity(List< CollectionEntity > collections)
abstract class PeriodEvent extends Equatable period
class DocumentOption showDocumentOptions(BuildContext context, List< DocumentOption > options,)
DocumentOption({ required this.icon, required this.title, required this.color, required this.onTap, })
Future< void > _showDateRangePicker(BuildContext context) async
class SearchWeeklyCollectionsEvent extends WeeklyCollectionsEvent collection
style Text( '${ 'scheduling.reference'.tr()}:${collection.internalCode}', style:Theme.of(context).textTheme.bodySmall,)
style SizedBox(height:2.h)
style Column(crossAxisAlignment:CrossAxisAlignment.end, children:[Container(padding:EdgeInsets.symmetric(horizontal:8.w, vertical:4.h), decoration:BoxDecoration(color:ColorPalette.tiffanyBlue.withValues(alpha:0.1), borderRadius:BorderRadius.circular(12),), child:Text(collection.type ?? '', style:Theme.of(context).textTheme.bodySmall?.copyWith(color:ColorPalette.tiffanyBlue, fontWeight:FontWeight.bold,),),),],)