@@ -7,6 +7,9 @@ import 'package:flutter/foundation.dart';
7
7
import 'package:flutter/material.dart' ;
8
8
import 'package:google_fonts/google_fonts.dart' ;
9
9
10
+ // https://github.com/FilledStacks/responsive_builder/blob/master/lib/src/sizing_information.dart#L85
11
+ final _mobileExtraLarge = 480.0 ;
12
+
10
13
void main () async {
11
14
WidgetsFlutterBinding .ensureInitialized ();
12
15
await Firebase .initializeApp ();
@@ -98,7 +101,7 @@ class _LoginPageState extends State<LoginPage> {
98
101
return Center (
99
102
child: Container (
100
103
padding: EdgeInsets .symmetric (horizontal: 16 ),
101
- width: widthScreen > 480 ? 480 : double .infinity,
104
+ width: widthScreen > _mobileExtraLarge ? _mobileExtraLarge : double .infinity,
102
105
child: Column (
103
106
mainAxisAlignment: MainAxisAlignment .center,
104
107
children: [
@@ -137,7 +140,12 @@ class _LoginPageState extends State<LoginPage> {
137
140
),
138
141
keyboardType: TextInputType .emailAddress,
139
142
validator: (value) {
140
- return value == null || value.isEmpty ? 'Enter an email address' : null ;
143
+ if (value == null || value.isEmpty) {
144
+ return 'Enter an email address' ;
145
+ } else {
146
+ final isEmailValid = RegExp (r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+" ).hasMatch (value);
147
+ return isEmailValid ? null : 'Invalid email' ;
148
+ }
141
149
},
142
150
textInputAction: TextInputAction .next,
143
151
),
@@ -276,15 +284,16 @@ class _LoginPageState extends State<LoginPage> {
276
284
(_) => false ,
277
285
);
278
286
} on FirebaseAuthException catch (error) {
279
- // TODO: buat UI pesan error gagal login
280
287
final errorCode = error.code;
288
+ var errorMessage = '' ;
281
289
if (errorCode == 'user-not-found' ) {
282
- debugPrint ( 'No user found for that email.' ) ;
290
+ errorMessage = 'No user found for that email.' ;
283
291
} else if (errorCode == 'wrong-password' ) {
284
- debugPrint ( 'Wrong password provided for that user.' ) ;
292
+ errorMessage = 'Wrong password provided for that user.' ;
285
293
} else {
286
- debugPrint ( 'error: ${ error . toString ()}' ) ;
294
+ errorMessage = '$ error ' ;
287
295
}
296
+ _showSnackBar (context, errorMessage, widthScreen);
288
297
setState (() => isLoading = false );
289
298
}
290
299
}
@@ -439,3 +448,25 @@ EdgeInsets _setPaddingButton() {
439
448
}
440
449
return padding;
441
450
}
451
+
452
+ void _showSnackBar (BuildContext context, String message, double widthScreen) {
453
+ if (widthScreen > _mobileExtraLarge) {
454
+ ScaffoldMessenger .of (context).showSnackBar (
455
+ SnackBar (
456
+ content: Text (
457
+ message,
458
+ ),
459
+ behavior: SnackBarBehavior .floating,
460
+ width: _mobileExtraLarge,
461
+ ),
462
+ );
463
+ } else {
464
+ ScaffoldMessenger .of (context).showSnackBar (
465
+ SnackBar (
466
+ content: Text (
467
+ message,
468
+ ),
469
+ ),
470
+ );
471
+ }
472
+ }
0 commit comments