Home > Software design >  FirebaseAuth.instance.currentUser() replacement?
FirebaseAuth.instance.currentUser() replacement?

Time:06-13

Im following a turtorial in flutter where i need to use FirebaseAuth.instance.currentUser() in a futurebuilder. This fuction that returns a Future no longer exist. is there any replacements whith the same fuction that returns a Future which i can use in the futurebuilder?

class Messages extends StatelessWidget { const Messages({Key? key}) : super(key: key);

@override

Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
      stream: FirebaseFirestore.instance
          .collection('chat')
          .orderBy('createdAt', descending: true)
          .snapshots(),
      builder: (ctx, chatSnapshot) {
        if (chatSnapshot.connectionState == ConnectionState.waiting) {
          return Center(
            child: CircularProgressIndicator(),
          );
        }
        final chatDocs = chatSnapshot.data!.docs;

        return FutureBuilder(
          future: FirebaseAuth.instance.currentUser(),  // <-<-<- THE ERROR
          builder: (ctx, futureSnapshot) {
          if (futureSnapshot.connectionState == ConnectionState.waiting) {
            return Center(child: CircularProgressIndicator());
          }

          return ListView.builder(
            reverse: true,
            itemCount: chatDocs.length,
            itemBuilder: (ctx, index) => MessageBubble(
              chatDocs[index]['text'],
              chatDocs[index]['userId'] == futureSnapshot.,
            ),
          );
        });
      },
    );
    }
   

    }

CodePudding user response:

You can create a resolved Future with Future#value containing the current User instance:

Future<User>.value(FirebaseAuth.instance.currentUser)
  • Related