【发布时间】:2022-08-14 19:19:30
【问题描述】:
我正在使用颤振和 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]),
)
],
),
],
),
],
),
);
},
),
-
您是否将用户列表存储在数据库中的某个位置?\'
-
是的,@FrankvanPuffelen
标签: flutter firebase firebase-realtime-database