Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
unloading_history_view.dart
Go to the documentation of this file.
1import 'package:easy_localization/easy_localization.dart';
2import 'package:flutter/material.dart';
3import 'package:flutter_bloc/flutter_bloc.dart';
4import 'package:flutter_screenutil/flutter_screenutil.dart';
5
6import '../../../../../core/ui/theme/color_palette.dart';
7import '../../../../../core/ui/widgets/custom_scaffold.dart';
8import '../../../../../core/ui/widgets/empty_content.dart';
9import '../../../../../core/ui/widgets/error_widget.dart';
10import '../../../../../core/ui/widgets/loading.dart';
11import '../../../../../core/ui/widgets/stats_card.dart';
12import '../../../../auth/presentation/bloc/authentication_bloc/authentication_bloc.dart';
13import '../../bloc/unloading_bloc.dart';
14import '../../bloc/unloading_event.dart';
15import '../../bloc/unloading_state.dart';
16import '../widgets/unloading_history_collection_item.dart';
17
19 const UnloadingHistoryView({super.key});
20
21 @override
22 State<UnloadingHistoryView> createState() => _UnloadingHistoryViewState();
23}
24
25class _UnloadingHistoryViewState extends State<UnloadingHistoryView> {
26 @override
27 void initState() {
28 super.initState();
30 }
33 final authState = context.read<AuthenticationBloc>().state;
34 if (authState is AuthenticatedState) {
35 context.read<UnloadingBloc>().add(
36 GetHistoryUnloadingEvent(userId: authState.session.uid ?? 0),
37 );
38 }
39 }
40
41 double _calculateTotalVolume(List<dynamic> history) {
42 double total = 0;
43 for (var item in history) {
44 total += item.quantityUnloaded ?? 0;
45 }
46 return total;
47 }
48
49 @override
50 Widget build(BuildContext context) {
51 return CustomScaffold(
52 backgroundColor: ColorPalette.antiFlashWhite,
53 body: BlocBuilder<UnloadingBloc, UnloadingState>(
54 builder: (context, state) {
55 if (state is UnloadingLoading) {
56 return Loading();
57 } else if (state is UnloadingError) {
58 return CustomErrorWidget(
59 message: "unloading.connection_failed".tr(),
60 onReload: _loadUnloadingHistory,
61 );
62 } else if (state is HistoryUnloadingLoaded) {
63 final history = state.history..sort(
64 (a, b) => (b.deliveredOn?? DateTime.now()).compareTo(a.deliveredOn?? DateTime.now()),
65 );
66
67 return SingleChildScrollView(
69 crossAxisAlignment: CrossAxisAlignment.start,
70 children: [
71 SizedBox(height: 16.sp),
72 Padding(
73 padding: EdgeInsets.symmetric(horizontal: 15.sp),
74 child: StatsCard(
75 unit: "unloading.deliveries".tr(),
76 gradient: LinearGradient(
77 colors: [
78 ColorPalette.blue.withValues(alpha: 0.9),
79 ColorPalette.tiffanyBlue.withValues(alpha: 0.9),
80 ],
81 ),
82 title: 'unloading.completed_deliveries'.tr(),
83 number: history.length.toString(),
85 ),
86 ),
87 SizedBox(height: 16.sp),
88 if (history.isEmpty)
89 // Replace empty content text
90 Center(
91 child: Padding(
92 padding: EdgeInsets.only(top: 90.sp),
93 child: EmptyContent(text: 'unloading.no_history_available'.tr()),
94 ),
95 )
96 else
97 ...List.generate(
98 history.length,
99 (index) => UnloadingHistoryCollectionItem(
100 id: history[index].id ?? 0,
101 status: history[index].status ?? 'Unknown',
102 deliveryDate: history[index].deliveredOn?.toString() ?? '',
103 quantityUnloaded: history[index].quantityUnloaded?.toString() ?? '--',
104 quantityWeighted: history[index].quantityWeight?.toString() ?? '--',
105 reference: history[index].reference ?? '',
106 warehouseRepresentative: history[index].warehouseResponsible ?? '--',
107 number: (index + 1).toString(),
108 ),
109 ),
110 SizedBox(height: 16.sp),
111 ],
112 ),
113 );
114 } else {
115 return EmptyContent(text: 'No data available');
116 }
117 },
118 ),
119 );
120 }
121
122 String formatVolume(dynamic volume) {
123 if (volume == null) return "--";
124 double volumeValue =
125 volume is double ? volume : double.tryParse(volume.toString()) ?? 0.0;
126 if (volumeValue > 999) {
127 return '${(volumeValue / 1000).toStringAsFixed(2)} MT';
128 } else {
129 return '$volumeValue KG';
130 }
131 }
132}
override void initState()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
sealed class CheckInOutEvent extends Equatable userId
static const antiFlashWhite
static const blue
static const tiffanyBlue
const UnloadingHistoryView({super.key})
override State< UnloadingHistoryView > createState()
final Widget child
final EdgeInsets padding
final String subtitle
class Partner String
final String message
Definition failures.dart:0
final String title
const UnloadingHistoryView({super.key})
String formatVolume(dynamic volume)
void _loadUnloadingHistory()
double _calculateTotalVolume(List< dynamic > history)
const HistoryUnloadingLoaded({required this.history})
class PendingUnloadingCollectionsLoaded extends UnloadingState history
const UnloadingError({required this.message})
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,),),),],)