Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
history_collections_view.dart
Go to the documentation of this file.
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';
6
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';
18
19class HistoryCollectionsView extends StatefulWidget {
20 const HistoryCollectionsView({super.key});
21
22 @override
23 State<HistoryCollectionsView> createState() => _HistoryCollectionsViewState();
24}
25
26class _HistoryCollectionsViewState extends State<HistoryCollectionsView> {
28 DateTimeRange? _dateRange;
29
30 @override
31 void initState() {
32 super.initState();
34 }
35
37 final authState = context.read<AuthenticationBloc>().state;
38 if (authState is AuthenticatedState) {
39 if (_selectedPeriod == "calendar" && _dateRange != null) {
40 context.read<HistoryCollectionsBloc>().add(
41 LoadHistoryCollectionsWithDateRangeEvent(
42 userId: authState.session.uid ?? 0,
43 dateStart: _dateRange!.start,
44 dateEnd: _dateRange!.end,
45 ),
46 );
47 } else {
48 context.read<HistoryCollectionsBloc>().add(
50 userId: authState.session.uid ?? 0,
52 ),
53 );
54 }
55 }
56 }
57
58 Future<void> _showDateRangePicker() async {
59 final DateTimeRange? picked = await showDateRangePicker(
60 context: context,
61 firstDate: DateTime(2020),
62 lastDate: DateTime.now(),
63 initialDateRange: _dateRange ??
64 DateTimeRange(
65 start: DateTime.now().subtract(const Duration(days: 7)),
66 end: DateTime.now(),
67 ),
68 builder: (context, child) {
69 return Theme(
70 data: Theme.of(context).copyWith(
71 colorScheme: Theme.of(context).colorScheme.copyWith(
72 primary: ColorPalette.lightGreen,
73 onPrimary: Colors.white,
74 ),
75 ),
76 child: child!,
77 );
78 },
79 );
80
81 if (picked != null) {
82 setState(() {
83 _dateRange = picked;
85 });
86 }
87 }
88
89 @override
90 Widget build(BuildContext context) {
91 return Column(
92 children: [
93 TripleTabSelector(
94 firstTabName: "common.this_week".tr(),
95 secondTabName: "common.this_month".tr(),
96 thirdTabName: "common.calendar".tr(),
97 initialSelection: _getTabSelectionIndex(),
98 onTabSelected: (index) {
99 if (index == 0) {
100 _selectedPeriod = "week";
101 } else if (index == 1) {
102 _selectedPeriod = "month";
103 } else if (index == 2) {
104 _selectedPeriod = "calendar";
106 }
107 setState(() {
109 });
110 },
111 ),
112 if (_selectedPeriod == "calendar" && _dateRange == null)
113 Container(
114 width: double.infinity,
115 color: ColorPalette.orange.withValues(alpha: 0.1),
116 padding: EdgeInsets.symmetric(vertical: 5.sp, horizontal: 10.sp),
117 child: Row(
118 mainAxisAlignment: MainAxisAlignment.spaceBetween,
119 children: [
120 SizedBox(
121 width: MediaQuery.sizeOf(context).width * 0.8,
122 child: Text(
123 "transactions_history.select_date_message".tr(),
124 style: Theme.of(context).textTheme.titleSmall?.copyWith(
125 color: ColorPalette.orange.withValues(alpha: 0.8),
126 fontWeight: FontWeight.w400,
127 ),
128 ),
129 ),
130 OutlinedButton(
131 style: OutlinedButton.styleFrom(
132 backgroundColor:
133 ColorPalette.lightGreen.withValues(alpha: 0.1),
134 side: const BorderSide(color: ColorPalette.lightGreen),
135 ),
136 child: const Icon(FluentIcons.calendar_20_regular),
138 )
139 ],
140 ),
141 ),
142 Expanded(
143 child: BlocBuilder<HistoryCollectionsBloc, HistoryCollectionsState>(
144 buildWhen: (previous, current) =>
145 current is HistoryCollectionsLoading ||
146 current is HistoryCollectionsLoaded ||
147 current is HistoryCollectionsError,
148 builder: (context, state) {
149 if (state is HistoryCollectionsLoaded) {
150 if (state.collections.isEmpty) {
151 return EmptyContent(text: "common.no_pending_collections".tr());
152 }
153 return ListView.builder(
154 physics: const AlwaysScrollableScrollPhysics(),
155 itemCount: state.collections.length + 2,
156 itemBuilder: (context, index) {
157 if (index == 0) {
158 if (_selectedPeriod == "calendar" && _dateRange != null) {
159 return Padding(
160 padding: EdgeInsets.only(left: 15.sp, top: 15.sp, right: 15.sp),
161 child: Text(
162 "${"transactions_history.from".tr()} ${_formatDate(_dateRange?.start)} ${"transactions_history.to".tr()} ${_formatDate(_dateRange?.end)}",
163 style: Theme.of(context)
164 .textTheme
165 .titleSmall
166 ?.copyWith(
167 color: ColorPalette.grey,
168 fontWeight: FontWeight.w600,
169 ),
170 ),
171 );
172 }
173 return const SizedBox();
174 }
175 if (index == 1) {
176 return Padding(
177 padding: EdgeInsets.all(15.sp),
178 child: StatsCard(
179 title: "transactions_history.completed_collections".tr(),
180 number: state.collections.length.toString(),
181 subtitle: _getCollectionQuantity(state.collections),
182 gradient: const LinearGradient(
183 begin: Alignment.topLeft,
184 end: Alignment.bottomRight,
186 ),
187 ),
188 );
189 }
190 return InkWell(
191 onTap: () {
193 context,
194 [
196 icon: Icons.receipt_long_outlined,
197 title: 'Voucher',
199 onTap: () {
200 DocumentsService.instance
201 .getCollectionVoucherDocument(
202 state.collections[index - 2].reference ?? '',
203 context,
204 );
205 },
206 ),
207 ],
208 );
209 },
210 child: CollectionItem(
211 hidePriority: true,
212 isCompleted: true,
213 isHistory: true,
214 number: '',
215 collection: state.collections[index - 2],
216 showNumber: false,
217 ),
218 );
219 },
220 );
221 }
222 if (state is HistoryCollectionsError) {
223 return EmptyContent(text: state.failure.message);
224 }
225 return const Loading();
226 },
227 ),
228 ),
229 ],
230 );
231 }
232
234 if (date == null) return '';
235 return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
236 }
237
238 String _getCollectionQuantity(List<CollectionEntity> collections) {
239 String quanitity = collections
240 .fold<double>(0, (prev, element) => prev + (element.volume ?? 0))
241 .toInt()
242 .toString();
243 return '$quanitity L';
244 }
245
247 if (_selectedPeriod == "week") {
248 return 0;
249 } else if (_selectedPeriod == "month") {
250 return 1;
251 } else {
252 return 2;
253 }
254 }
255
256 // void _showDocumentOptions(CollectionEntity collection) {
257 // showDialog(
258 // context: context,
259 // builder: (BuildContext context) {
260 // return Dialog(
261 // backgroundColor: Colors.transparent,
262 // elevation: 0,
263 // child: Container(
264 // width: 300.w,
265 // decoration: BoxDecoration(
266 // color: Colors.white,
267 // borderRadius: BorderRadius.circular(20.r),
268 // boxShadow: [
269 // BoxShadow(
270 // color: Colors.black.withValues(alpha: 0.1),
271 // blurRadius: 10,
272 // spreadRadius: 1,
273 // ),
274 // ],
275 // ),
276 // child: Column(
277 // mainAxisSize: MainAxisSize.min,
278 // children: [
279 // Container(
280 // padding: EdgeInsets.symmetric(vertical: 15.sp),
281 // decoration: BoxDecoration(
282 // color: ColorPalette.lightGreen,
283 // borderRadius: BorderRadius.only(
284 // topLeft: Radius.circular(20.r),
285 // topRight: Radius.circular(20.r),
286 // ),
287 // ),
288 // child: Center(
289 // child: Text(
290 // 'Select Document Type',
291 // style: Theme.of(context).textTheme.titleMedium?.copyWith(
292 // fontWeight: FontWeight.bold,
293 // color: Colors.white,
294 // ),
295 // ),
296 // ),
297 // ),
298 // SizedBox(height: 20.h),
299 // Padding(
300 // padding: EdgeInsets.symmetric(horizontal: 15.w),
301 // child: Text(
302 // 'Choose which document you want to view:',
303 // textAlign: TextAlign.center,
304 // style: TextStyle(
305 // color: ColorPalette.grey,
306 // fontSize: 14.sp,
307 // ),
308 // ),
309 // ),
310 // SizedBox(height: 20.h),
311 // Row(
312 // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
313 // children: [
314 // _buildDocumentOption(
315 // icon: Icons.description_outlined,
316 // title: 'E-Manifest',
317 // color: ColorPalette.lightGreen,
318 // onTap: () {
319 // Navigator.pop(context);
320 // DocumentsService.instance.getManifestDocument(
321 // collection.reference ?? '',
322 // context
323 // );
324 // },
325 // ),
326 // _buildDocumentOption(
327 // icon: Icons.receipt_long_outlined,
328 // title: 'Voucher',
329 // color: ColorPalette.orange,
330 // onTap: () {
331 // Navigator.pop(context);
332 // DocumentsService.instance.getCollectionVoucherDocument(
333 // collection.reference ?? '',
334 // context
335 // );
336 // },
337 // ),
338 // ],
339 // ),
340 // SizedBox(height: 20.h),
341 // Divider(height: 1, color: Colors.grey.withValues(alpha: 0.3)),
342 // InkWell(
343 // onTap: () => Navigator.pop(context),
344 // borderRadius: BorderRadius.only(
345 // bottomLeft: Radius.circular(20.r),
346 // bottomRight: Radius.circular(20.r),
347 // ),
348 // child: Container(
349 // padding: EdgeInsets.symmetric(vertical: 15.sp),
350 // width: double.infinity,
351 // alignment: Alignment.center,
352 // child: Text(
353 // 'Cancel',
354 // style: TextStyle(
355 // color: Colors.grey,
356 // fontWeight: FontWeight.w500,
357 // fontSize: 16.sp,
358 // ),
359 // ),
360 // ),
361 // ),
362 // ],
363 // ),
364 // ),
365 // );
366 // },
367 // );
368 // }
369
370 // Widget _buildDocumentOption({
371 // required IconData icon,
372 // required String title,
373 // required Color color,
374 // required VoidCallback onTap,
375 // }) {
376 // return InkWell(
377 // onTap: onTap,
378 // borderRadius: BorderRadius.circular(15.r),
379 // child: Container(
380 // width: 120.w,
381 // padding: EdgeInsets.symmetric(vertical: 15.sp, horizontal: 10.w),
382 // decoration: BoxDecoration(
383 // color: color.withValues(alpha: 0.1),
384 // borderRadius: BorderRadius.circular(15.r),
385 // border: Border.all(color: color.withValues(alpha: 0.3)),
386 // ),
387 // child: Column(
388 // mainAxisSize: MainAxisSize.min,
389 // children: [
390 // Icon(icon, color: color, size: 40.sp),
391 // SizedBox(height: 10.h),
392 // Text(
393 // title,
394 // textAlign: TextAlign.center,
395 // style: TextStyle(
396 // color: color,
397 // fontWeight: FontWeight.w500,
398 // fontSize: 14.sp,
399 // ),
400 // ),
401 // ],
402 // ),
403 // ),
404 // );
405 // }
406}
override void initState()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
sealed class CheckInOutEvent extends Equatable userId
static const darkGrey
static const lightGreen
static const orange
static const grey
const HistoryCollectionsView({super.key})
override State< HistoryCollectionsView > createState()
sealed class CollectionsState extends Equatable collections
final Widget child
final EdgeInsets padding
final String subtitle
class Partner String
final Color color
Definition failures.dart:1
const LoadHistoryCollectionsEvent({ required this.userId, required this.period, })
const HistoryCollectionsLoaded({required this.collections})
Future< void > _showDateRangePicker() async
String _formatDate(DateTime? date)
DateTimeRange _dateRange
int _getTabSelectionIndex()
class HistoryCollectionsView extends StatefulWidget _selectedPeriod
void _loadHistoryCollections()
String _getCollectionQuantity(List< CollectionEntity > collections)
final String date
final VoidCallback onPressed
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, })
final VoidCallback onTap
final String title
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,),),),],)