Click here to Skip to main content
15,309,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im trying to display clickable list of premise that the user added. how to call data from a subcollection firebase after the user logged in?
#flutterfire #flutter #firebase

What I have tried:

<pre>class list_premise extends StatefulWidget {
  const list_premise({Key? key}) : super(key: key);

  @override
  _list_premiseState createState() => _list_premiseState();
}

class _list_premiseState extends State<list_premise> {
  final Stream<QuerySnapshot> _usersStream =
      FirebaseFirestore.instance.collection('users').snapshots();

//   @override
//   void initState() {
//     super.initState();
//     FirebaseFirestore.instance
//         .collection("users")
//         .doc(user!.uid)
//         .get()
//         .then((value) {
//       this.loggedInUser = UserModel.fromMap(value.data());
//       setState(() {});
//     });

// final Stream<QuerySnapshot> _usersStream = FirebaseFirestore.instance.collection('users').doc(user!.uid).collection('premises').snapshots();
//   }

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
      stream: _usersStream,
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (snapshot.hasError) {
          return Text('Something went wrong');
        }

        if (snapshot.connectionState == ConnectionState.waiting) {
          return Text("Loading");
        }

        return ListView(
          children: snapshot.data!.docs.map((DocumentSnapshot document) {
            Map<String, dynamic> data =
                document.data()! as Map<String, dynamic>;
            return ListTile(
              title: Text(data['name']),  
            );
          }).toList(),
        );
      },
    );
  }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900