Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
schedule_confirmation_screen.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';
5import 'package:go_router/go_router.dart';
6import 'package:lottie/lottie.dart';
7
8import '../../../../../core/constants/assets.dart';
9import '../../../../../core/ui/theme/color_palette.dart';
10import '../../../../../core/ui/widgets/custom_scaffold.dart';
11import '../../../../../core/services/service_locator.dart';
12import '../../../../../core/router/routes.dart';
13import '../../../../auth/presentation/bloc/authentication_bloc/authentication_bloc.dart';
14import '../../../domain/usecases/validate_scheduler_usecase.dart';
15
16class ScheduleConfirmationScreen extends StatefulWidget {
17 const ScheduleConfirmationScreen({super.key});
18
19 @override
20 State<ScheduleConfirmationScreen> createState() =>
21 _ScheduleConfirmationScreenState();
22}
23
24class _ScheduleConfirmationScreenState
25 extends State<ScheduleConfirmationScreen> {
26 bool _isSubmitting = false;
27
28 Future<void> _submit() async {
29 if (_isSubmitting) return;
30 setState(() {
31 _isSubmitting = true;
32 });
33
34 final authState = context.read<AuthenticationBloc>().state;
35 if (authState is! AuthenticatedState) {
36 setState(() => _isSubmitting = false);
37 return;
38 }
39
40 final now = DateTime.now();
41 final dateString = '${now.day.toString().padLeft(2, '0')}/${now.month.toString().padLeft(2, '0')}/${now.year}';
42
43 final usecase = sl<ValidateSchedulerUseCase>();
44 final result = await usecase(ValidateSchedulerParams(
45 timeStringValue: dateString,
46 driverId: authState.session.uid ?? 0,
47 ));
48
49 result.fold(
50 (failure) {
51 ScaffoldMessenger.of(context).showSnackBar(
52 SnackBar(
53 content: Text(failure.message),
54 backgroundColor: failure.color,
55 ),
56 );
57 setState(() => _isSubmitting = false);
58 },
59 (_) {
60 ScaffoldMessenger.of(context).showSnackBar(
61 SnackBar(
62 content: Text('scheduling.schedule_confirmed'.tr()),
63 backgroundColor: ColorPalette.lightGreen,
64 ),
65 );
66 setState(() => _isSubmitting = false);
67 context.pushReplacement(Routes.homeScreen.route);
68 },
69 );
70 }
71
72 @override
73 Widget build(BuildContext context) {
74 return PopScope(
75 canPop: false, // Prevent back navigation
76 child: CustomScaffold(
77 isLeadingVisible: false,
78 title: 'scheduling.confirm_schedule'.tr(),
79 body: Padding(
80 padding: const EdgeInsets.all(16.0),
82 crossAxisAlignment: CrossAxisAlignment.start,
83 children: [
84 SizedBox(height: 16.sp),
85 Text(
86 'scheduling.confirmation_text'.tr(),
87 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
88 fontSize: 14.sp,
89 ),
90 ),
91 SizedBox(height: 50.sp),
92 Center(
93 child: Lottie.asset(
95 height: 270.sp,
96 width: 270.sp,
97 ),
98 ),
99 const Spacer(),
100 SizedBox(
101 width: double.infinity,
102 child: ElevatedButton(
104 style: ElevatedButton.styleFrom(
105 backgroundColor: ColorPalette.lightGreen,
106 foregroundColor: Colors.white,
107 padding: const EdgeInsets.symmetric(vertical: 14),
108 ),
110 height: 20,
111 width: 20,
112 child: CircularProgressIndicator(
113 strokeWidth: 2, color: Colors.white,
114 ),
115 ) : Text('scheduling.Confirm'.tr()),
116 ),
117 ),
118 ],
119 ),
120 ),
121 ),
122 );
123 }
124}
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
AuthGuard _()
sealed class AuthenticationState extends Equatable failure
static const String successLottie
Definition assets.dart:22
static const lightGreen
const ScheduleConfirmationScreen({super.key})
override State< ScheduleConfirmationScreen > createState()
final Widget child
final EdgeInsets padding
final Color color
Definition failures.dart:1
final VoidCallback onPressed
Routes
Definition routes.dart:30
Future< void > _submit() async
class ScheduleConfirmationScreen extends StatefulWidget _isSubmitting
final sl
final String title
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,),),),],)