【发布时间】:2020-05-11 10:52:21
【问题描述】:
我有一个个人资料屏幕。并从云存储中获取数据并显示在个人资料屏幕中。
我想在检索数据时没有问题,但问题是在显示时。我不知道我怎么搞砸了? 现在错误只显示“加载”文本。 帮帮我
class Profile extends StatefulWidget {
@override
_ProfileState createState() => _ProfileState();
}
class _ProfileState extends State<Profile> {
bool userFlag = false;
var users;
@override
void initState() {
// TODO: implement initState
super.initState();
UserManagement().getData().then((QuerySnapshot docs){
userFlag = true;
users = docs.documents[0].data;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Profile'),
),
body: Container(
padding: EdgeInsets.all(50),
child: Column(
children:<Widget>[
name(),
],
),
),
);
}
Widget name() {
return Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
"Name",
style: TextStyle(fontWeight: FontWeight.w600,fontSize: 18),
),
SizedBox(
width: 45,
),
userFlag ? Text(users['Name'],
style: TextStyle(fontWeight: FontWeight.w400,fontSize: 18),
)
:Text('Loading'),
],
),
);
}
获取我拥有的数据:
getData(){
return Firestore.instance
.collection('users').getDocuments();
}
【问题讨论】:
标签: database firebase flutter google-cloud-firestore flutter-layout