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';
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';
22 State<UnloadingHistoryView>
createState() => _UnloadingHistoryViewState();
25class _UnloadingHistoryViewState
extends State<UnloadingHistoryView> {
33 final authState = context.read<AuthenticationBloc>().state;
34 if (authState is AuthenticatedState) {
35 context.read<UnloadingBloc>().add(
36 GetHistoryUnloadingEvent(
userId: authState.session.uid ?? 0),
44 total += item.quantityUnloaded ?? 0;
50 Widget
build(BuildContext context) {
51 return CustomScaffold(
53 body: BlocBuilder<UnloadingBloc, UnloadingState>(
54 builder: (context, state) {
55 if (state is UnloadingLoading) {
58 return CustomErrorWidget(
59 message:
"unloading.connection_failed".tr(),
63 final history = state.history..sort(
64 (a, b) => (b.deliveredOn?? DateTime.now()).compareTo(a.deliveredOn?? DateTime.now()),
67 return SingleChildScrollView(
69 crossAxisAlignment: CrossAxisAlignment.start,
73 padding: EdgeInsets.symmetric(horizontal: 15.sp),
75 unit:
"unloading.deliveries".tr(),
76 gradient: LinearGradient(
82 title:
'unloading.completed_deliveries'.tr(),
83 number:
history.length.toString(),
92 padding: EdgeInsets.only(top: 90.sp),
93 child: EmptyContent(text:
'unloading.no_history_available'.tr()),
99 (index) => UnloadingHistoryCollectionItem(
102 deliveryDate:
history[index].deliveredOn?.toString() ??
'',
103 quantityUnloaded:
history[index].quantityUnloaded?.toString() ??
'--',
104 quantityWeighted:
history[index].quantityWeight?.toString() ??
'--',
106 warehouseRepresentative:
history[index].warehouseResponsible ??
'--',
107 number: (index + 1).toString(),
115 return EmptyContent(text:
'No data available');
123 if (volume == null)
return "--";
125 volume is
double ? volume :
double.tryParse(volume.toString()) ?? 0.0;
126 if (volumeValue > 999) {
127 return '${(volumeValue / 1000).toStringAsFixed(2)} MT';
129 return '$volumeValue KG';
override void initState()
class App extends StatefulWidget build(BuildContext context)
sealed class CheckInOutEvent extends Equatable userId
static const antiFlashWhite
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,),),),],)