Skip to content

Instantly share code, notes, and snippets.

@yaizudamashii
Last active April 6, 2021 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaizudamashii/44b7d5e1295095ddfdc3946276f3cf6e to your computer and use it in GitHub Desktop.
Save yaizudamashii/44b7d5e1295095ddfdc3946276f3cf6e to your computer and use it in GitHub Desktop.
class EmailPasswordSignInModel with EmailAndPasswordValidators, ChangeNotifier {
EmailPasswordSignInModel({
@required this.firebaseAuth,
this.email = '',
this.password = '',
this.formType = EmailPasswordSignInFormType.signIn,
this.isLoading = false,
this.submitted = false,
});
final FirebaseAuth firebaseAuth;
String email;
String password;
EmailPasswordSignInFormType formType;
bool isLoading;
bool submitted;
Future<bool> submit() async {
try {
updateWith(submitted: true);
if (!canSubmit) {
return false;
}
updateWith(isLoading: true);
switch (formType) {
case EmailPasswordSignInFormType.signIn:
await firebaseAuth.signInWithCredential(
EmailAuthProvider.credential(email: email, password: password)
);
break;
case EmailPasswordSignInFormType.register:
UserCredential userCredential = await firebaseAuth.createUserWithEmailAndPassword(
email: email, password: password
);
await FirestoreService.createUser(userCredential);
break;
case EmailPasswordSignInFormType.forgotPassword:
await firebaseAuth.sendPasswordResetEmail(email: email);
updateWith(isLoading: false);
break;
}
return true;
} catch (e) {
updateWith(isLoading: false);
rethrow;
}
}
// ...略
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment