The argument type 'User?' can't be assigned to the parameter type 'Future<Object?>?'

922

I don't typically do that with a FutureBuilder. Once you have a user, you don't need to async it.

final FirebaseAuth_auth = FirebaseAuth.instance();    
final User? user;
user = _auth.currentUser;

Then, if user != null ....create your ListView else, return a CircularProgressIndicator or whatever.

Look up Net Ninja for some nice videos for getting yourself set up with all that, just having a stream based on userChanges() for your project. More robust setup.

Share:
922
Ahsan Naushad
Author by

Ahsan Naushad

Updated on December 22, 2022

Comments

  • Ahsan Naushad
    Ahsan Naushad over 1 year

    With reference to the recent changes regarding FirebaseUser to User. FirebaseAuth.instance.currentUser() is not found at all (while throughing error "The expression doesn't evaluate to a function, so it can't be invoked."
    The solution to that however was to simply remove the paranthesis as FirebaseAuth.instance.currentUser. But now we have another error that it isn't a future type i.e "The argument type User can't be assigned to the parameter type Future<Object?>?".

    Following is my code block.

    return FutureBuilder(
                future: FirebaseAuth.instance.currentUser,
                builder: (ctx, futureSnapshot) => ListView.builder(
                  reverse: true, //  So that 1st message goes to last.
                  itemCount: chatDocument.length,
                  itemBuilder: (ctx, index) => MessageBubble(
                    message: chatDocument[index]['text'],
                    isMe: chatDocument[index]['userId'],
                  ),
                ),
              );
    

    In the above code block I intend to provide future to my `FutureBuilder`. In summary previously `FirebaseUser` object did return a future, but probably `User` doesn't anymore. How may I handle this case?
    Thanks in advance.
    • Fatima ayaa
      Fatima ayaa almost 3 years
      you have to remove FutureBuilder , and use FirebaseAuth.instance.currentUser syimply because it is not a Future
    • Ahsan Naushad
      Ahsan Naushad almost 3 years
      Yup. That works. Thank you.