retrieving current user to show in personal profile

Viewed 46

hi im trying to retrive current user info from firebase but its showing me errors this error

enter image description here

this is my code

  final auth = FirebaseAuth.instance;
  final db = FirebaseFirestore.instance;
  User? user = FirebaseAuth.instance.currentUser;

Padding(
            padding: EdgeInsets.only(left: 20, right: 20),
            child: StreamBuilder(
              stream: db
                  .collection("Users")
                  .doc("list_students")
                  .collection("Students")
                  .doc(user!.uid)
                  .snapshots(),
              builder: (BuildContext context, AsyncSnapshot snapshot) {
                if (!snapshot.hasData) {
                  return Center();
                }
                return ListView.builder(
                    itemCount: snapshot.data.length,
                    itemBuilder: (BuildContext context, int index) {
                      return Stack;

this is a screenshots of my firebase enter image description here

2 Answers

First of all, try to print 'snapshot' and 'snapshot.data' for you've got proper data from firebase.

You need to cast snapshot.data as a List type before you can call the length method on snapshot.data. I cannot tell from your included code what is the underlying type for snapshot.data.

Another way is to specify AsyncSnapshot<List<String>> snapshot in the builder header, assuming the underlying data type is a List<String>.

Related