@@ -74,7 +74,7 @@ class AuthState extends AppState {
74
74
75
75
/// Verify user's credentials for login
76
76
Future <String ?> signIn (String email, String password,
77
- {required GlobalKey < ScaffoldState > scaffoldKey }) async {
77
+ {required BuildContext context }) async {
78
78
try {
79
79
isBusy = true ;
80
80
var result = await _firebaseAuth.signInWithEmailAndPassword (
@@ -84,17 +84,17 @@ class AuthState extends AppState {
84
84
return user! .uid;
85
85
} on FirebaseException catch (error) {
86
86
if (error.code == 'firebase_auth/user-not-found' ) {
87
- Utility .customSnackBar (scaffoldKey , 'User not found' );
87
+ Utility .customSnackBar (context , 'User not found' );
88
88
} else {
89
89
Utility .customSnackBar (
90
- scaffoldKey ,
90
+ context ,
91
91
error.message ?? 'Something went wrong' ,
92
92
);
93
93
}
94
94
cprint (error, errorIn: 'signIn' );
95
95
return null ;
96
96
} catch (error) {
97
- Utility .customSnackBar (scaffoldKey , error.toString ());
97
+ Utility .customSnackBar (context , error.toString ());
98
98
cprint (error, errorIn: 'signIn' );
99
99
100
100
return null ;
@@ -173,8 +173,7 @@ class AuthState extends AppState {
173
173
174
174
/// Create new user's profile in db
175
175
Future <String ?> signUp (UserModel userModel,
176
- {required GlobalKey <ScaffoldState > scaffoldKey,
177
- required String password}) async {
176
+ {required BuildContext context, required String password}) async {
178
177
try {
179
178
isBusy = true ;
180
179
var result = await _firebaseAuth.createUserWithEmailAndPassword (
@@ -197,7 +196,7 @@ class AuthState extends AppState {
197
196
} catch (error) {
198
197
isBusy = false ;
199
198
cprint (error, errorIn: 'signUp' );
200
- Utility .customSnackBar (scaffoldKey , error.toString ());
199
+ Utility .customSnackBar (context , error.toString ());
201
200
return null ;
202
201
}
203
202
}
@@ -260,22 +259,21 @@ class AuthState extends AppState {
260
259
}
261
260
262
261
/// Send email verification link to email2
263
- Future <void > sendEmailVerification (
264
- GlobalKey <ScaffoldState > scaffoldKey) async {
262
+ Future <void > sendEmailVerification (BuildContext context) async {
265
263
User user = _firebaseAuth.currentUser! ;
266
264
user.sendEmailVerification ().then ((_) {
267
265
Utility .logEvent ('email_verification_sent' ,
268
266
parameter: {userModel! .displayName! : user.email});
269
267
Utility .customSnackBar (
270
- scaffoldKey ,
268
+ context ,
271
269
'An email verification link is send to your email.' ,
272
270
);
273
271
}).catchError ((error) {
274
272
cprint (error.message, errorIn: 'sendEmailVerification' );
275
273
Utility .logEvent ('email_verification_block' ,
276
274
parameter: {userModel! .displayName! : user.email});
277
275
Utility .customSnackBar (
278
- scaffoldKey ,
276
+ context ,
279
277
error.message,
280
278
);
281
279
});
@@ -289,17 +287,17 @@ class AuthState extends AppState {
289
287
290
288
/// Send password reset link to email
291
289
Future <void > forgetPassword (String email,
292
- {required GlobalKey < ScaffoldState > scaffoldKey }) async {
290
+ {required BuildContext context }) async {
293
291
try {
294
292
await _firebaseAuth.sendPasswordResetEmail (email: email).then ((value) {
295
- Utility .customSnackBar (scaffoldKey ,
293
+ Utility .customSnackBar (context ,
296
294
'A reset password link is sent yo your mail.You can reset your password from there' );
297
295
Utility .logEvent ('forgot+password' , parameter: {});
298
296
}).catchError ((error) {
299
297
cprint (error.message);
300
298
});
301
299
} catch (error) {
302
- Utility .customSnackBar (scaffoldKey , error.toString ());
300
+ Utility .customSnackBar (context , error.toString ());
303
301
return Future .value (false );
304
302
}
305
303
}
0 commit comments