Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
driver_requests.dart
Go to the documentation of this file.
1import '../../data/driver_requests_repository.dart';
2import 'widgets/request_card.dart';
3import '../request_details/request_details.dart';
4import 'package:flutter/material.dart';
5import 'package:flutter_screenutil/flutter_screenutil.dart';
6import 'package:flutter_bloc/flutter_bloc.dart';
7
8import '../../../../core/UI/widgets/custom_scaffold.dart';
9import '../../../../core/UI/theme/color_palette.dart';
10import '../../../../features/auth/presentation/bloc/authentication_bloc/authentication_bloc.dart';
11import '../../models/driver_request.dart';
12
13class DriverRequestsScreen extends StatefulWidget {
14 const DriverRequestsScreen({super.key});
15
16 @override
17 State<DriverRequestsScreen> createState() => _DriverRequestsScreenState();
18}
19
20class _DriverRequestsScreenState extends State<DriverRequestsScreen> {
21 List<DriverRequest> _requests = [];
22 bool _isLoading = true;
24
25 @override
26 void initState() {
27 super.initState();
29 }
30
31 Future<void> _loadRequests() async {
32 try {
33 setState(() {
34 _isLoading = true;
35 _error = null;
36 });
37
38 final requests = await DriverRequestsRepository.getMockedRequests();
39
40 setState(() {
41 _requests = requests;
42 _isLoading = false;
43 });
44 } catch (e) {
45 setState(() {
46 _error = 'Failed to load requests: $e';
47 _isLoading = false;
48 });
49 }
50 }
51
52 Future<void> _showSignOutDialog() async {
53 final confirm = await showDialog<bool>(
54 context: context,
55 builder: (context) => AlertDialog(
56 title: const Text('Sign Out'),
57 content: const Text('Are you sure you want to sign out?'),
58 actions: [
59 TextButton(
60 onPressed: () => Navigator.of(context).pop(false),
61 child: const Text('Cancel'),
62 ),
63 TextButton(
64 onPressed: () => Navigator.of(context).pop(true),
65 child: const Text('Sign Out'),
66 ),
67 ],
68 ),
69 );
70
71 if (confirm == true && mounted) {
72 context.read<AuthenticationBloc>().add(SignOutEvent());
73 }
74 }
75
76 @override
77 Widget build(BuildContext context) {
78 return CustomScaffold(
79 title: 'Driver Requests',
80 isLeadingVisible: false,
81 backgroundColor: ColorPalette.antiFlashWhite,
82 actions: [
83 IconButton(
85 icon: const Icon(Icons.logout),
86 tooltip: 'Sign Out',
87 ),
88 ],
89 body: _buildBody(),
90 );
91 }
92
93 Widget _buildBody() {
94 if (_isLoading) {
95 return const Center(
96 child: CircularProgressIndicator(),
97 );
98 }
99
100 if (_error != null) {
101 return Center(
102 child: Column(
103 mainAxisAlignment: MainAxisAlignment.center,
104 children: [
105 Icon(
106 Icons.error_outline,
107 size: 48.sp,
109 ),
110 SizedBox(height: 16.h),
111 Text(
112 _error!,
113 style: TextStyle(
114 fontSize: 14.sp,
116 ),
117 textAlign: TextAlign.center,
118 ),
119 SizedBox(height: 16.h),
120 ElevatedButton(
122 child: const Text('Retry'),
123 ),
124 ],
125 ),
126 );
127 }
128
129 return Padding(
130 padding: EdgeInsets.all(16.sp),
131 child: Column(
132 crossAxisAlignment: CrossAxisAlignment.start,
133 children: [
134 _buildHeader(),
135 SizedBox(height: 14.h),
136 Expanded(
138 ),
139 ],
140 ),
141 );
142 }
143
144 Widget _buildHeader() {
145 return Column(
146 crossAxisAlignment: CrossAxisAlignment.start,
147 children: [
148 Text(
149 'Active Requests',
150 style: TextStyle(
151 fontSize: 18.sp,
152 fontWeight: FontWeight.bold,
154 ),
155 ),
156 SizedBox(height: 2.h),
157 Text(
158 '${_requests.length} requests found',
159 style: TextStyle(
160 fontSize: 12.sp,
162 ),
163 ),
164 ],
165 );
166 }
167
169 if (_requests.isEmpty) {
170 return Center(
171 child: Column(
172 mainAxisAlignment: MainAxisAlignment.center,
173 children: [
174 Icon(
175 Icons.inbox_outlined,
176 size: 48.sp,
178 ),
179 SizedBox(height: 16.h),
180 Text(
181 'No requests found',
182 style: TextStyle(
183 fontSize: 16.sp,
185 ),
186 ),
187 ],
188 ),
189 );
190 }
191
192 return ListView.separated(
193 itemCount: _requests.length,
194 separatorBuilder: (context, index) => SizedBox(height: 16.h),
195 itemBuilder: (context, index) {
196 return AnimatedContainer(
197 duration: Duration(milliseconds: 300 + (index * 100)),
198 curve: Curves.easeOutCubic,
199 child: RequestCard(
200 request: _requests[index],
201 onViewMore: () => _handleViewMore(_requests[index]),
202 ),
203 );
204 },
205 );
206 }
207
209 Navigator.push(
210 context,
211 MaterialPageRoute(
212 builder: (context) => RequestDetailsScreen(request: request),
213 ),
214 );
215 }
216}
override void initState()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
static const darkGrey
static const antiFlashWhite
static const grey
const DriverRequestsScreen({super.key})
override State< DriverRequestsScreen > createState()
abstract class CollectionsToScheduleEvent extends Equatable request
Widget _buildBody(ElearningV2State state)
final Widget child
final EdgeInsets padding
class Partner String
Widget _buildHeader()
DriverRequest({ required this.id, required this.driverName, required this.creationDate, required this.stations, required this.startPoint, required this.endPoint, })
class DriverRequestsScreen extends StatefulWidget _requests
void _handleViewMore(DriverRequest request)
Widget _buildRequestsList()
Widget _buildBody()
String _error
Future< void > _loadRequests() async
Future< void > _showSignOutDialog() async
bool _isLoading
final Color color
Definition failures.dart:1
final VoidCallback onPressed
final String tooltip
const RequestDetailsScreen({ super.key, required this.request, })
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,),),),],)