This project will help you build simple and light UI to sign-in users. No big dependencies!
/!\ This library is used in some of my apps and it will be updated as and when needed :) PR are welcome!
This package doesn't (yet) include simple buttons to sign-in users. I will advise you to use flutter_signin_button.
// Google Auth
SignInButton(Buttons.Google, onPressed: _signInWithGoogle)
// Email
SignInButtonBuilder(
icon: Icons.email,
text: 'Sign-in with email',
onPressed: _signInWithEmail,
backgroundColor: Colors.blueGrey[700],
)
// Phone
SignInButtonBuilder(
icon: Icons.phone,
text: 'Sign-in with phone',
onPressed: _signInWithPhone,
backgroundColor: Colors.blueGrey[700],
)
Requires firebase_auth. Please follow the installation instructions. Does NOT requires this plugin, as the UI is part of the firebase_auth plugin.
Future<FirebaseUser> _signInWithGoogle() async {
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
if (googleUser != null) {
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
AuthResult result = await _auth.signInWithCredential(credential);
return result?.user;
}
return null;
}
void _signInWithPhone() {
showDialog(
context: context,
builder: (context) {
return SignInPhonePage(onLoggedIn: (authResult) {
Navigator.of(context).pop();
});
},
);
}
void _signInWithEmail() {
showDialog(
context: context,
builder: (context) {
return SignInEmailPasswordPage(onLoggedIn: (authResult) {
Navigator.of(context).pop();
});
},
);
}