Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
fast_sign_in_bottom_sheet.dart
Go to the documentation of this file.
1import 'package:flutter/material.dart';
2import 'package:flutter_bloc/flutter_bloc.dart';
3
4import '../../../../../core/error/failures.dart';
5import '../../../../../core/services/fast_sign_in_service.dart';
6import '../../domain/entities/credentials_entity.dart';
7import '../bloc/authentication_bloc/authentication_bloc.dart';
8
9class FastSignInBottomSheet extends StatefulWidget {
10 final String? email;
13
15 super.key,
16 required this.email,
17 required this.onSuccess,
18 required this.onCancel,
19 });
20
21 static Future<bool?> show(
22 BuildContext context, {
23 required String? email,
24 required Function onSuccess,
25 required Function onCancel,
26 }) {
27 return showModalBottomSheet<bool?>(
28 context: context,
29 isScrollControlled: true,
30 shape: const RoundedRectangleBorder(
31 borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
32 ),
33 builder: (context) => FastSignInBottomSheet(
34 email: email,
35 onSuccess: onSuccess,
36 onCancel: onCancel,
37 ),
38 );
39 }
40
41 @override
42 State<FastSignInBottomSheet> createState() => _FastSignInBottomSheetState();
43}
44
45class _FastSignInBottomSheetState extends State<FastSignInBottomSheet> {
46 final TextEditingController _passwordController = TextEditingController();
48 bool _isPasswordVisible = false;
49
50 @override
51 void dispose() {
52 _fastSignInService.setActive(false);
53 _passwordController.dispose();
54 super.dispose();
55 }
56
57 @override
58 Widget build(BuildContext context) {
59 return BlocListener<AuthenticationBloc, AuthenticationState>(
60 listener: (context, state) {
61 if (state is FastSignInLoaded) {
62 Navigator.of(context).pop(true);
63 widget.onSuccess();
64 } else if (state is FastSignInFailed) {
65 _showErrorSnackBar(context, state.failure);
66 }
67 },
68 child: Padding(
69 padding: EdgeInsets.only(
70 bottom: MediaQuery.of(context).viewInsets.bottom,
71 left: 16,
72 right: 16,
73 top: 16,
74 ),
76 mainAxisSize: MainAxisSize.min,
77 crossAxisAlignment: CrossAxisAlignment.start,
78 children: [
79 Row(
80 mainAxisAlignment: MainAxisAlignment.spaceBetween,
81 children: [
82 Text(
83 'Session Expired',
84 style: Theme.of(context).textTheme.titleLarge,
85 ),
86 IconButton(
87 icon: const Icon(Icons.close),
88 onPressed: () {
89 Navigator.of(context).pop(false);
90 widget.onCancel();
91 },
92 ),
93 ],
94 ),
95 const SizedBox(height: 16),
96 Text(
97 'Your session has expired. Please enter your password to continue.',
98 style: Theme.of(context).textTheme.bodyMedium,
99 ),
100 const SizedBox(height: 16),
101 Text(
102 'Email',
103 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
104 fontWeight: FontWeight.bold,
105 ),
106 ),
107 const SizedBox(height: 8),
108 Container(
109 padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
110 decoration: BoxDecoration(
111 color: Colors.grey[200],
112 borderRadius: BorderRadius.circular(8),
113 ),
114 child: Text(
115 widget.email ?? 'Unknown email',
116 style: Theme.of(context).textTheme.bodyMedium,
117 ),
118 ),
119 const SizedBox(height: 16),
120 Text(
121 'Password',
122 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
123 fontWeight: FontWeight.bold,
124 ),
125 ),
126 const SizedBox(height: 8),
127 TextField(
128 controller: _passwordController,
129 obscureText: !_isPasswordVisible,
130 decoration: InputDecoration(
131 filled: true,
132 fillColor: Colors.grey[200],
133 border: OutlineInputBorder(
134 borderRadius: BorderRadius.circular(8),
135 borderSide: BorderSide.none,
136 ),
137 suffixIcon: IconButton(
138 icon: Icon(
140 ? Icons.visibility_off
141 : Icons.visibility,
142 ),
143 onPressed: () {
144 setState(() {
145 _isPasswordVisible = !_isPasswordVisible;
146 });
147 },
148 ),
149 ),
150 ),
151 const SizedBox(height: 24),
152 BlocBuilder<AuthenticationBloc, AuthenticationState>(
153 builder: (context, state) {
154 final isLoading = state is FastSignInLoading;
155 return SizedBox(
156 width: double.infinity,
157 child: ElevatedButton(
158 onPressed: isLoading ? null : () {
159 if (_passwordController.text.isNotEmpty) {
160 context.read<AuthenticationBloc>().add(
162 reqEntity: CredentialsEntity(
163 email: widget.email ?? '',
164 password: _passwordController.text,
165 ),
166 ),
167 );
168 }
169 },
170 style: ElevatedButton.styleFrom(
171 padding: const EdgeInsets.symmetric(vertical: 16),
172 shape: RoundedRectangleBorder(
173 borderRadius: BorderRadius.circular(8),
174 ),
175 ),
176 child: isLoading ? const SizedBox(
177 height: 20,
178 width: 20,
179 child: CircularProgressIndicator(
180 strokeWidth: 2,
181 ),
182 ) : const Text('Sign In'),
183 ),
184 );
185 },
186 ),
187 const SizedBox(height: 24),
188 ],
189 ),
190 ),
191 );
192 }
193
194 void _showErrorSnackBar(BuildContext context, Failure failure) {
195 ScaffoldMessenger.of(context).showSnackBar(
196 SnackBar(
197 content: Text(failure.message),
198 backgroundColor: Colors.red,
199 ),
200 );
201 }
202 }
override void dispose()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
final FastSignInService _fastSignInService
sealed class AuthenticationEvent extends Equatable reqEntity
const FastSignInEvent({required this.reqEntity})
sealed class AuthenticationState extends Equatable failure
const FastSignInFailed({required this.failure})
bool isLoading
override State< FastSignInBottomSheet > createState()
static Future< bool?> show(BuildContext context, { required String? email, required Function onSuccess, required Function onCancel, })
const FastSignInBottomSheet({ super.key, required this.email, required this.onSuccess, required this.onCancel, })
final Function(bool) onTabSelected
final Widget child
final EdgeInsets padding
class Partner String
final Color color
Definition failures.dart:1
void _showErrorSnackBar(BuildContext context, Failure failure)
bool _isPasswordVisible
final VoidCallback onPressed
final _passwordController
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,),),),],)