In my knowledge ,from cloud firestore collection you can query from subcollection, but not form tis Map
so if you get need only userItem then (you will get all data to the app and take needed data form app side)
void getItems() async {
var test;
FirebaseFirestore.instance
.collection("userData")
.doc(Constant.loginID)
.get()
.then((DocumentSnapshot doc) => print(doc.data['userItem']) );
or Create a model Class and use userItem object;
you can also do it from ui side
class UserInformation extends StatefulWidget {
@override
_UserInformationState createState() => _UserInformationState();
}
class _UserInformationState extends State<UserInformation> {
final Stream<QuerySnapshot> _usersStream =
FirebaseFirestore.instance.collection('users').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['userItem']),
);
}).toList(),
);
},
);
}
}