1

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.
  • 1
    you have to remove FutureBuilder , and use FirebaseAuth.instance.currentUser syimply because it is not a Future – Fatima ayaa Jun 10 '21 at 16:14

1 Answers1

1

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.

jbryanh
  • 1,193
  • 7
  • 17