【发布时间】:2021-11-19 11:51:08
【问题描述】:
我正在从 firestore 检索用户的名字,将其存储在一个变量中,然后尝试使用文本小部件显示它。 数据库查询肯定有效,因为我打印了它的结果。 另一方面,用于存储数据的变量在 Text 小部件中使用,但它不显示任何内容。
主页.dart
//get the specific document I need
DocumentReference userName = FirebaseFirestore.instance
.collection('users')
.doc(FirebaseAuth.instance.currentUser!.uid);
//Variable used to store the name
String firstName = '';
@override
Widget build(BuildContext context) {
//Get specific field from a document
userName.get().then((DocumentSnapshot ds) {
firstName = ds['firstName'];
print(firstName);
});
return Scaffold(
appBar: AppBar(
title: const Text('Homepage'),
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.only(
top: 20,
),
child: Text(firstName)),
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore