我只是想显示保存在云Firestore中的用户的用户名。有人知道如何在云Firestore中显示用户名字符串吗?如果有人知道,请评论您的解决方案。
@override
Widget build(BuildContext context) {
lol()async{
var documents =
(await Firestore.instance.collection('SerX').get())
.docs;
}
return Scaffold(
appBar: AppBar(
bottom: PreferredSize(
child: Container(
color: Colors.blue,
height: 4.0,
),
preferredSize: Size.fromHeight(0)),
backgroundColor: Colors.black,
leading: IconButton(icon: Icon(Icons.arrow_back ,color: Colors.blue,),onPressed: (){
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => HomeScreen()));
},),
title: Text('Profile', style: TextStyle(
color:Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),
textAlign: TextAlign.center,
),
),
body: Container(
color: Colors.black,
child: ListView(
children: [
Stack(
children: [
Container(
margin: EdgeInsets.fromLTRB(140,100,0,0),
width: 130,
height: 130,
decoration: BoxDecoration(
border: Border.all(
width: 3,
color: Colors.blue,
),
boxShadow: [BoxShadow(
spreadRadius: 2, blurRadius: 10,
color: Colors.white.withOpacity(0.1),
offset: Offset(0,10),
),
],
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: (_image != null) ? FileImage(
_image)
: NetworkImage("https://www.senertec.de/wp-content/uploads/2020/04/blank-profile-picture-973460_1280.png"),
)
),
),
Positioned(
bottom: 0,
right: 150,
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
border: Border.all(width: 2, color: Colors.blue),
shape: BoxShape.circle,
color: Colors.white,
),
child: IconButton(icon: Icon(Icons.edit), color: Colors.blue, onPressed: (){
getImage(context);
},),
),
)
],
),
SizedBox(height: 40),
TextFormField(
style: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.blue, width: 1.0),
borderRadius: BorderRadius.circular(25.0),
),
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.white, width: 1.0),
borderRadius: BorderRadius.circular(25.0),
),
icon: Icon(Icons.edit, color: Colors.blue,),
contentPadding: EdgeInsets.only(bottom: 3),
labelText: "Username",
labelStyle: TextStyle(color: Colors.white),
floatingLabelBehavior: FloatingLabelBehavior.always,
prefixIcon: Icon(Icons.account_circle, color: Colors.blue,),
-> hintText: snapshot.data.data()["Username"], <-
hintStyle: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.bold,
fontFamily: 'Orbitron',
),
),
),
先谢谢您!先感谢您!先感谢您!先感谢您!先感谢您!预先谢谢你!
答案 0 :(得分:0)
如果您正在使用Firebase用户身份验证,则可以在firebaseUser的帮助下轻松访问用户用户名。 否则,如果您使用的是Firestore之类的数据库,则从该数据库中获取的数据将为JSON格式(如Maps)。
字符串userName = firebaseData ['userName'];