Asked  7 Months ago    Answers:  5   Viewed   451 times

I'm new to Flutter. I have an Issue with Firebase Auth/ Google Auth The FirebaseUser is not defined Code:

FirebaseAuth _auth = FirebaseAuth.instance;
GoogleSignIn googleSignIn = GoogleSignIn();

Future<FirebaseUser> currentUser() async { // The Issue is here in the Future<>
  final GoogleSignInAccount account = await googleSignIn.signIn();
  final GoogleSignInAuthentication authentication =
      await account.authentication;

  final GoogleAuthCredential credential = GoogleAuthProvider.getCredential(
      idToken: authentication.idToken, accessToken: authentication.accessToken);

  final AuthResult authResult = await _auth.signInWithCredential(credential);
  final FirebaseUser user = authResult.user; // and here as I can't define this FirebaseUser object to return

  return user;


    sdk: flutter

  cupertino_icons: ^0.1.3
  firebase_auth: ^0.18.0
  location: ^3.0.2
  page_transition: ^1.1.6
  google_sign_in: ^4.5.1
  flutter_facebook_login: ^3.0.0
  firebase_database: ^4.0.0

I also face the same issue with AuthResult

final AuthResult authResult = await _auth.signInWithCredential(credential);



Starting from Version firebase_auth 0.18.0:

In the newest version of firebase_auth, the class FirebaseUser was changed to User, and the class AuthResult was changed to UserCredential. Therefore change your code to the following:

    Future<User> currentUser() async {
      final GoogleSignInAccount account = await googleSignIn.signIn();
      final GoogleSignInAuthentication authentication =
          await account.authentication;

      final GoogleAuthCredential credential = GoogleAuthProvider.credential(
          idToken: authentication.idToken,
          accessToken: authentication.accessToken);

      final UserCredential authResult =
          await _auth.signInWithCredential(credential);
      final User user = authResult.user;

      return user;

FirebaseUser changed to User

AuthResult changed to UserCredential

GoogleAuthProvider.getCredential() changed to GoogleAuthProvider.credential()

onAuthStateChanged which notifies about changes to the user's sign-in state was replaced with authStateChanges()

currentUser() which is a method to retrieve the currently logged in user, was replaced with the property currentUser and it no longer returns a Future<FirebaseUser>.

Example of the above two methods:

FirebaseAuth.instance.authStateChanges().listen((event) {


var user = FirebaseAuth.instance.currentUser;

Deprecation of UserUpdateInfo class for firebaseUser.updateProfile method. Example:

Future updateName(String name, FirebaseUser user) async {
  var userUpdateInfo = new UserUpdateInfo();
  userUpdateInfo.displayName = name;
  await user.updateProfile(userUpdateInfo);
  await user.reload(); 


import 'package:firebase_auth/firebase_auth.dart' as firebaseAuth;
Future updateName(String name, auth.User firebaseUser) async {
  firebaseUser.updateProfile(displayName: name);
  await firebaseUser.reload();
Tuesday, June 1, 2021
answered 7 Months ago

This verification isn't as straightforward as you'd hope. First, there is the problem of recognizing that the user has verified their email. Second, there is the issue that there isn't any sort of a notification you can listen to that will automatically trigger a change in your app.

Check this thread for info about emailVerified:

I was only able to verify the user if I 1) Created their account, 2) Signed them in, 3) Then checked to make sure they verified their email.

final FirebaseAuth _auth = FirebaseAuth.instance;

var _authenticatedUser = await _auth.signInWithEmailAndPassword(email: _email, password: _password); 

//where _email and _password were simply what the user typed in the textfields.

if (_authenticatedUser.isEmailVerified) {
      } else {
        //Not verified

Part 2: How do you get your app to recognize that the user has confirmed their email? Find a way to trigger the function that checks confirmation. A button would be easy enough. If you want it to see "automatic" then I guess you could create a timer that checks for email verification every 10 seconds or so.

Tuesday, August 3, 2021
answered 4 Months ago

When you create a plugin other plugins can only access the classes in packages declared in the Export-Package section of the Open the plugin.xml editor and look at the 'Runtime' tab - it needs to have your package listed. Something like this:

enter image description here

Monday, August 30, 2021
answered 3 Months ago

Importing has nothing to do with loading classes or setting CLASSPATH.

Try this:

java -cp .;../lib/* Generator

Using the dot '.' as the first entry in the CLASSPATH assumes that the Generator.class file exists in the directory from which you're running java, and /lib is one level up from that directory. Adjust as needed if both of these are not correct.

Thursday, October 14, 2021
answered 2 Months ago
import 'package:badam/varify.dart';
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'dart:async';

import 'HomePage.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'FireBase Demo',
      theme: ThemeData(
      home: new LoginPage(),
      routes: <String, WidgetBuilder>{
        '/loginpage' : (BuildContext context) => Dash(),
        '/landpage' : (BuildContext context) => LoginPage(),
class LoginPage extends StatefulWidget {
  _LoginPageState createState() => _LoginPageState();

class _LoginPageState extends State<LoginPage> {
  String phoneNo, smsId, verificationId;

  Future<void> verifyPhone() async{
    final PhoneCodeAutoRetrievalTimeout autoRetrieve = (String verId){
      this.verificationId = verId;
    final PhoneCodeSent smsCodeSent = (String verId, [int forceCodeResend]){
      this.verificationId = verId;
        print('Signed In');
    final PhoneVerificationCompleted verifiedSuccess = (AuthCredential auth){
    final PhoneVerificationFailed verifyFailed = (AuthException e) {
    await FirebaseAuth.instance.verifyPhoneNumber(
      phoneNumber: phoneNo,
      timeout: const Duration(seconds: 5),
      verificationCompleted: verifiedSuccess,
      verificationFailed: verifyFailed,
      codeSent: smsCodeSent,
      codeAutoRetrievalTimeout: autoRetrieve,
  Future<bool> smsCodeDialoge(BuildContext context){
    return showDialog(context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return new AlertDialog(
          title: Text('Enter OTP'),
          content: TextField(
            onChanged: (value)  {
              this.smsId  = value;
          contentPadding: EdgeInsets.all(10.0),
          actions: <Widget>[
            new FlatButton(
                onPressed: (){
                    if(user != null){
                        MaterialPageRoute(builder: (context) => Dash()),


                child: Text('Done', style: TextStyle( color:,))

  Future<void> signIn(String smsCode) async {
    final AuthCredential credential = PhoneAuthProvider.getCredential(
      verificationId: verificationId,
      smsCode: smsCode,
     await FirebaseAuth.instance.signInWithCredential(credential)

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: Text('Sign In')
      body: Column(

        children: <Widget>[
          Text('Phone Auth',style: TextStyle(fontSize: 20,color:,),
            padding: const EdgeInsets.all(16.0),
            child: TextField(
              decoration: InputDecoration(
                hintText: 'Enter your phone number',
              onChanged: (value){
                this.phoneNo = value;
          SizedBox(height: 10.0),
            onPressed: verifyPhone,
            child: Text('Verify', style: TextStyle(color: Colors.white),),
            elevation: 7.0,


It worked for me, hope this helps you!

Sunday, November 7, 2021
answered 4 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :