提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我正在使用 flutter 和 Firebase Realtime 创建一个应用程序,其中我具有用户可以发布文章的功能。 我想要列出所有这些文章以及发布它的用户的名称。 但是如何显示他的名字,知道在数据库级别它只是记录发布帖子的人的 ID? 谢谢
我使用 Firebase Realtime 请求的代码:
ref = FirebaseDatabase.instance.reference().child("post").orderByKey();
FirebaseAnimatedList(
scrollDirection: Axis.vertical,
shrinkWrap: true,
query: ref,
itemBuilder: (BuildContext context, DataSnapshot snapshot,
Animation<double> animation, int index) {
return Container(
padding: EdgeInsets.all(10),
margin: EdgeInsets.only(bottom: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage(snapshot
.value["imagePost"]
.toString()),
fit: BoxFit.cover)),
),
SizedBox(
width: 10,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
RichText(
text: TextSpan(
//text: snapshot.value["user_id"].toString(),
text: "" +
FirebaseDatabase.instance
.reference()
.child('users')
.child(
"${snapshot.value["user_id"].toString()}")
.child('nom')
.toString(),
style: TextStyle(
color: Colors.grey[900],
fontSize: 14,
fontWeight: FontWeight.bold,
letterSpacing: 1),
),
),
SizedBox(
height: 3,
),
Text(
"${timeago.format(DateTime.parse("${DateTime.fromMillisecondsSinceEpoch(snapshot.value['createAt'])}"), locale: 'fr_short')}",
style: TextStyle(
fontSize: 12, color: Colors.grey),
),
],
)
],
),
],
),
SizedBox(
height: 20,
),
RichText(
text: TextSpan(
text: snapshot.value["description"].toString(),
style: TextStyle(
fontSize: 12,
color: Colors.grey[800],
height: 1.5,
letterSpacing: .7),
),
),
SizedBox(
height: 20,
),
snapshot.value["imagePost"].toString() != ''
? Container(
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
image: NetworkImage(
snapshot.value["imagePost"].toString()),
fit: BoxFit.cover),
),
)
: Container(
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: kPrimaryColor,
),
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
makeLikeButton(isActive: false),
Padding(
padding: EdgeInsets.only(
right: 10,
),
),
Row(
children: <Widget>[
makeLike(),
SizedBox(
width: 5,
),
Text(
"2.5K",
style: TextStyle(
fontSize: 10, color: Colors.grey[800]),
)
],
),
],
),
],
),
);
},
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.