Getting subfield data flutter firestore
i have a education collection with currentuser uid as document, inside there is some of subfield i created with form. then i want to display it with listview after get the data with get firestore function.
Future _getDataEducation() async {
await FirebaseFirestore.instance
.collection("education")
.doc(FirebaseAuth.instance.currentUser!.uid)
.get()
.then((snapshot) async {
if (snapshot.exists) {
if (mounted) {
setState(() {
SD = snapshot.data()!["SD"];
SMP = snapshot.data()!["SMP"];
SMA = snapshot.data()!["SMA"];
College = snapshot.data()!["College"]; //how to write it correctly? with subfield
});
}
}
});
}
this is how i display it but it gets null because i didn't get it correctly in _getDataEducation()
Container(
height: 400,
child: ListView(
children: [
SizedBox(
height: 20,
),
Column(
children: [
Text(
SD == null
? Text("no data").toString()
: SD!,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 24),
开发者_运维技巧 ),
const SizedBox(
height: 5,
),
Text(
SMP == null
? Text("no data").toString()
: SMP!,
style: const TextStyle(
color: Colors.grey, fontSize: 16),
),
const SizedBox(
height: 5,
),
Text(
SMA == null
? Text("no data").toString()
: SMA!,
style: const TextStyle(
color: Colors.grey, fontSize: 16),
),
Text(
College == null
? Text("no data").toString()
: College!,
style: const TextStyle(
color: Colors.grey, fontSize: 16),
),
],
),
],
),
),
how to display subfield firestore in flutter?
精彩评论