Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
unloading_confirmation_dialog.dart
Go to the documentation of this file.
1import 'package:easy_localization/easy_localization.dart';
2import 'package:flutter/material.dart';
3import 'package:flutter_screenutil/flutter_screenutil.dart';
4import 'package:flutter_bloc/flutter_bloc.dart';
5
6import '../../../../../core/ui/theme/color_palette.dart';
7import '../../domain/entities/warehouse_responsible_entity.dart';
8import '../bloc/unloading_bloc.dart';
9import '../bloc/unloading_event.dart';
10import '../bloc/unloading_state.dart';
11
13 required BuildContext context,
14 required Function(String user, double firstWeight) onConfirm,
15 required String userId,
16}) {
17 String? selectedUser;
18 final TextEditingController firstWeightController = TextEditingController();
19
20 // Trigger the event to load warehouse responsible list
21 context.read<UnloadingBloc>().add(GetWarehouseResponsibleListEvent(userId: int.parse(userId)));
22
23 showDialog(
24 context: context,
25 builder: (BuildContext context) {
26 return BlocBuilder<UnloadingBloc, UnloadingState>(
27 builder: (context, state) {
28 if (state is GetWarehouseResponsibleLoading) {
29 return Dialog(
30 shape: RoundedRectangleBorder(
31 borderRadius: BorderRadius.circular(16.sp),
32 ),
33 child: Container(
34 padding: EdgeInsets.all(20.sp),
36 mainAxisSize: MainAxisSize.min,
37 children: [
38 CircularProgressIndicator(),
39 SizedBox(height: 16.sp),
40 Text('Loading warehouse responsible list...')
41 ],
42 ),
43 ),
44 );
45 } else if (state is GetWarehouseResponsibleLoaded) {
46 final List<WarehouseResponsibleEntity> responsibleList = state.warehouseResponsibleList;
47
48 return StatefulBuilder(
49 builder: (context, setState) {
50 bool isFormValid() {
51 return selectedUser != null &&
52 firstWeightController.text.isNotEmpty &&
53 double.tryParse(firstWeightController.text) != null;
54 }
55
56 return Dialog(
57 shape: RoundedRectangleBorder(
58 borderRadius: BorderRadius.circular(14.sp),
59 ),
60 elevation: 0,
61 backgroundColor: Colors.transparent,
62 child: SingleChildScrollView(
63 child: Container(
64 padding: EdgeInsets.all(20.sp),
65 decoration: BoxDecoration(
66 color: Colors.white,
67 borderRadius: BorderRadius.circular(16.sp),
68 boxShadow: [
69 BoxShadow(
70 color: Colors.black.withValues(alpha: 0.1),
71 blurRadius: 10,
72 offset: const Offset(0, 5),
73 ),
74 ],
75 ),
77 mainAxisSize: MainAxisSize.min,
78 children: [
79 Container(
80 padding: EdgeInsets.all(12.sp),
81 decoration: BoxDecoration(
82 color: ColorPalette.darkGreen.withValues(alpha: 0.1),
83 shape: BoxShape.circle,
84 ),
85 child: Icon(
86 Icons.check_circle_outline,
88 size: 40.sp,
89 ),
90 ),
91 SizedBox(height: 16.sp),
92 Text(
93 'unloading.confirmation_dialog.title'.tr(),
94 style: TextStyle(
95 fontSize: 20.sp,
96 fontWeight: FontWeight.bold,
97 color: Colors.black87,
98 ),
99 ),
100 SizedBox(height: 8.sp),
101 Text(
102 'unloading.confirmation_dialog.instruction'.tr(),
103 textAlign: TextAlign.center,
104 style: TextStyle(
105 fontSize: 14.sp,
106 color: Colors.grey[600],
107 ),
108 ),
109 SizedBox(height: 24.sp),
110 Container(
111 padding: EdgeInsets.symmetric(horizontal: 12.sp),
112 decoration: BoxDecoration(
113 borderRadius: BorderRadius.circular(8.sp),
114 border: Border.all(color: Colors.grey[300]!),
115 ),
116 child: DropdownButtonHideUnderline(
117 child: DropdownButton<String>(
118 isExpanded: true,
119 hint: Text(
120 'unloading.confirmation_dialog.select_responsible'.tr(),
121 style: TextStyle(
122 fontSize: 16.sp,
123 color: Colors.grey[600],
124 ),
125 ),
126 value: selectedUser,
127 icon: Icon(Icons.arrow_drop_down, color: ColorPalette.darkGreen),
128 elevation: 16,
129 style: TextStyle(
130 fontSize: 16.sp,
131 color: Colors.black87,
132 ),
133 onChanged: (String? newValue) {
134 setState(() {
135 selectedUser = newValue;
136 });
137 },
138 items: responsibleList.map<DropdownMenuItem<String>>((WarehouseResponsibleEntity responsible) {
139 return DropdownMenuItem<String>(
140 value: responsible.id?.toString(),
141 child: Text(responsible.warehouseResponsible ?? "--"),
142 );
143 }).toList(),
144 ),
145 ),
146 ),
147 SizedBox(height: 16.sp),
148 Container(
149 padding: EdgeInsets.symmetric(horizontal: 12.sp),
150 decoration: BoxDecoration(
151 borderRadius: BorderRadius.circular(8.sp),
152 border: Border.all(color: ColorPalette.grey.withValues(alpha: 0.5)),
153 ),
154 child: TextField(
155 controller: firstWeightController,
156 keyboardType: TextInputType.number,
157 onChanged: (_) => setState(() {}), // Refresh state to update button
158 decoration: InputDecoration(
159 border: InputBorder.none,
160 hintText: 'unloading.confirmation_dialog.enter_weight'.tr(),
161 hintStyle: TextStyle(
162 fontSize: 16.sp,
163 color: Colors.grey[600],
164 ),
165 labelText: 'unloading.confirmation_dialog.first_weight'.tr(),
166 labelStyle: TextStyle(
167 fontSize: 16.sp,
168 color: Colors.grey[600],
169 ),
170 suffixText: 'kg',
171 suffixStyle: TextStyle(
172 fontSize: 16.sp,
173 color: Colors.grey[600],
174 ),
175 ),
176 ),
177 ),
178
179 SizedBox(height: 24.sp),
180 Row(
181 children: [
182 Expanded(
183 child: TextButton(
184 onPressed: () {
185 Navigator.of(context).pop();
186 },
187 style: TextButton.styleFrom(
188 padding: EdgeInsets.symmetric(vertical: 12.sp),
189 shape: RoundedRectangleBorder(
190 borderRadius: BorderRadius.circular(8.sp),
191 side: BorderSide(color: ColorPalette.red),
192 ),
193 ),
194 child: Text(
195 'unloading.cancel'.tr(),
196 style: TextStyle(
197 fontSize: 16.sp,
199 ),
200 ),
201 ),
202 ),
203 SizedBox(width: 12.sp),
204 Expanded(
205 child: TextButton(
206 onPressed: isFormValid()
207 ? () {
208 Navigator.of(context).pop();
209 onConfirm(
210 selectedUser!,
211 double.parse(firstWeightController.text)
212 );
213 }
214 : null,
215 style: TextButton.styleFrom(
216 padding: EdgeInsets.symmetric(vertical: 12.sp),
217 backgroundColor: isFormValid() ? ColorPalette.darkGreen.withValues(alpha: 0.1) : null,
218 shape: RoundedRectangleBorder(
219 borderRadius: BorderRadius.circular(8.sp),
220 side: BorderSide(
221 color: isFormValid() ? ColorPalette.darkGreen : ColorPalette.grey,
222 ),
223 ),
224 ),
225 child: Text(
226 'common.confirm'.tr(),
227 style: TextStyle(
228 fontSize: 16.sp,
229 fontWeight: FontWeight.w500,
230 color: isFormValid() ? ColorPalette.darkGreen : ColorPalette.grey,
231 ),
232 ),
233 ),
234 ),
235 ],
236 ),
237 ],
238 ),
239 ),
240 ),
241 );
242 },
243 );
244 } else if (state is GetWarehouseResponsibleError) {
245 return Dialog(
246 shape: RoundedRectangleBorder(
247 borderRadius: BorderRadius.circular(16.sp),
248 ),
249 child: Container(
250 padding: EdgeInsets.all(20.sp),
251 child: Column(
252 mainAxisSize: MainAxisSize.min,
253 children: [
254 Icon(Icons.error_outline, color: Colors.red, size: 48.sp),
255 SizedBox(height: 16.sp),
256 Text('Error: ${state.message}'),
257 SizedBox(height: 16.sp),
258 TextButton(
259 onPressed: () {
260 Navigator.of(context).pop();
261 },
262 child: Text('Close'),
263 )
264 ],
265 ),
266 ),
267 );
268 } else {
269 return Dialog(
270 shape: RoundedRectangleBorder(
271 borderRadius: BorderRadius.circular(16.sp),
272 ),
273 child: Container(
274 padding: EdgeInsets.all(20.sp),
275 child: Column(
276 mainAxisSize: MainAxisSize.min,
277 children: [
278 CircularProgressIndicator(),
279 SizedBox(height: 16.sp),
280 Text('Loading...')
281 ],
282 ),
283 ),
284 );
285 }
286 },
287 );
288 },
289 );
290}
AuthGuard _()
final Function(int) onReasonSelected
sealed class CheckInOutEvent extends Equatable userId
static const red
static const darkGreen
static const grey
final Widget child
final EdgeInsets padding
class Partner String
final Color color
Definition failures.dart:1
List< DashboardItem > get items
final VoidCallback onPressed
void showUnloadingConfirmationDialog({ required BuildContext context, required Function(String user, double firstWeight) onConfirm, required String userId, })
const GetWarehouseResponsibleListEvent({required this.userId})
const GetWarehouseResponsibleError({required this.message})
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,),),),],)