I had this problem where I couldn't access specific value and rather print everything out. I finger why it does that and though I post about it maybe it help someone.
I couldn't access specific value.
@override
void initState() {
/*get data*/
getData();
userId = FirebaseAuth.instance.currentUser!.uid;
super.initState();
}
getData() async {
try {
if (widget.listId != null) {
var userSnap = await FirebaseFirestore.instance
.collection('Lists')
.doc(widget.listId)
.get();
setState(() {
listData = userSnap.data()!;
_isloaded = true;
});
}
} catch (e) {
print(e.toString());
}
}
var userId;//the user visiting the page
var listData = {};
bool _isloaded =false;
here where it went wrong:
Text(
"$listData['Title']",
),
The output:
{uid: 8qqfIvsJ5fbkdOEeyrqiunYCBw52, Description: , Cover: , ListID: c79697b0-296e-11ed-8a73-b9da6639ae48, Access: true, Title: K, Tags: []}['Title']
solution
I shouldn't but it in "" and just write it without like this:
Text(
listData['Title'],
),
The output:
K
CodePudding user response:
Please replace
Text(
"$listData['Title']",
),
With
Text(
"${listData['Title']}",
),
You can read about string interpolation here.