firebase authentication request from flutter code example
Example 1: phone authentication firebase flutter
Future<void> _submitPhoneNumber() async {
String phoneNumber = "+91 " + _phoneNumberController.text.toString().trim();
print(phoneNumber);
void verificationCompleted(AuthCredential phoneAuthCredential) {
print('verificationCompleted');
...
this._phoneAuthCredential = phoneAuthCredential;
print(phoneAuthCredential);
}
void verificationFailed(AuthException error) {
...
print(error);
}
void codeSent(String verificationId, [int code]) {
...
print('codeSent');
}
void codeAutoRetrievalTimeout(String verificationId) {
...
print('codeAutoRetrievalTimeout');
}
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: phoneNumber,
timeout: Duration(milliseconds: 10000),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout,
);
}
Example 2: how to sign out user in flutter with firebase authentication
final FirebaseAuth _auth = FirebaseAuth.instance;
Future<void> _signOut() async {
await _auth.signOut();
}