【发布时间】:2021-06-19 14:55:46
【问题描述】:
我想显示我的 firebase cloudfirestore 中的数据,如图所示:
在设置页面中,我想显示登录用户的所有信息。 这是设置代码(德语中的“einstellungen”):
class einstellungen extends StatelessWidget {
final user = FirebaseAuth.instance.currentUser;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.red,
title: Text("Einstellungen"),
),
backgroundColor: Colors.orange,
body: SingleChildScrollView(
child: Column(
children: [
Container(
margin: const EdgeInsets.only(
left: 8.0, right: 8.0, top: 10.0, bottom: 5.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white.withOpacity(0.2),
),
child: Column(
children: [
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Text('Benutzer:',
style: TextStyle(fontWeight: FontWeight.bold)),
),
),
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.only(
bottom: 10.0, left: 10.0, right: 10.0),
child: Text(''),
),
),
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Text('Spitzname:',
style: TextStyle(fontWeight: FontWeight.bold)),
),
),
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.only(
bottom: 10.0, left: 10.0, right: 10.0),
child: Text(''),
),
),
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Text('E-Mail:',
style: TextStyle(fontWeight: FontWeight.bold)),
),
),
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.only(
bottom: 10.0, left: 10.0, right: 10.0),
child: Text(''), // here should print the email address from firestore
),
),
Text(''),
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Text('Hinweis: ',
style: TextStyle(fontWeight: FontWeight.bold)),
),
),
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Text(
'Wenn Du dein Konto löschen oder dein Passwort zurücksetzen möchtest, schreibe bitte eine Email an medien@visuhome.de'),
),
),
Text(''),
],
)),
Container(
margin: const EdgeInsets.only(
left: 8.0, right: 8.0, top: 3.0, bottom: 3.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white.withOpacity(0.2),
),
child: Row(
children: [
ButtonNutzung(),
Text("Nutzungsbedingungen",
style:
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
],
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Divider(),
),
SizedBox(height: 10),
if (user.uid != null)
Text(
'Cloud User-ID: ' + user.uid,
style: TextStyle(color: Colors.black),
),
SizedBox(height: 10),
Padding(
padding: const EdgeInsets.all(10.0),
child: Divider(),
),
GestureDetector(
onTap: _launchURL2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 20.0, right: 20.0),
child: Text(
'created by visuhome',
style: TextStyle(
fontWeight: FontWeight.w300,
fontSize: 12,
color: Colors.black),
),
),
Image(
//AssetImage oder SizedBox mit child und width
image: AssetImage('assets/visuhome_logo_black_flutter.png'),
fit: BoxFit.fitHeight,
height: 30,
),
Padding(
padding: const EdgeInsets.only(left: 20.0, right: 20.0),
child: Text(
'Version 1.0',
style: TextStyle(
fontWeight: FontWeight.w300,
fontSize: 12,
color: Colors.black),
),
),
],
),
),
],
),
),
);
}
}
如您所见,我确实从FirebaseAuth.instance.currentUser 获取信息,因此显示了来自登录用户的userid。但我也想要firestore中用户数据的信息。
我猜有人可以帮忙解决这个基本的 firestore 技巧吗?我是新来的。尝试了很多,但找不到适合我的例子的解决方案。非常感谢
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore