0

am trying to get some information for current user from firebase on flutter by using FutureBuilder. but its show me error says

 return new Scaffold(
      body: FutureBuilder(
        future: FirebaseFirestore.instance
            .collection('Users').where('email', isEqualTo: FirebaseAuth.instance.currentUser.email).get(),
        builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
          if (snapshot.data == null) {
            return Container(
              child: Center(
                child: CircularProgressIndicator(),
              ),
            );
          } else if (snapshot.connectionState == ConnectionState.done) {

            print(snapshot.data.docs.length);

            return Container(
              child: ListView(children: <Widget>[
                ListTile(
                  leading: Icon(Icons.person),
                  title: Text("Name: " +
                      snapshot.data.docs[0].get('Name') +
                      "\n" +
                      "Civil ID: " +
                      snapshot.data.docs[0].get('Civil ID')),
                  subtitle: Text(snapshot.data.docs[0].get('email')),
                ),
iKaka
  • 201
  • 1
  • 3
  • 8

1 Answers1

1
Try this

    FirebaseAuth auth = FirebaseAuth.instance;

 return new Scaffold(
      body: FutureBuilder(
        future: FirebaseFirestore.instance
            .collection('Users').where('email', isEqualTo: auth.currentUser.email).get(),
        builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {

          if (snapshot.data == null) {
            return Container(
              child: Center(
                child: CircularProgressIndicator(),
              ),
            );
          } else if (snapshot.connectionState == ConnectionState.done) {

            print(snapshot.data.docs.length);

            return Container(
              child: ListView(children: <Widget>[
                ListTile(
                  leading: Icon(Icons.person),
                  title: Text("Name: " +
                      snapshot.data.docs[0].get('Name') +
                      "\n" +
                      "Civil ID: " +
                      snapshot.data.docs[0].get('Civil ID')),
                  subtitle: Text(snapshot.data.docs[0].get('email')),
                ),




//If that don't work, you might have to upload a picture of how you structured your database
CharlyKeleb
  • 587
  • 4
  • 17