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(), ); }, ); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)