问题描述
我正在开发一款Flutter应用程序,发现如何从Firebase读取product_name和price并将其显示在列表中的障碍
我尝试了这段代码,但它以文本形式返回整个JSON树
class _BeveragesProductsstate extends State<BeveragesProducts> {
var _firebaseRef = FirebaseDatabase().reference().child('Products');
@override
Widget build(BuildContext context) {
// Todo: implement build
return Scaffold(
appBar: AppBar(
title: Text(' Beverages Products'),),body: Column(
mainAxisAlignment: MainAxisAlignment.start,children: <Widget>[
Expanded(
child: StreamBuilder(
stream: _firebaseRef.onValue,builder: (context,snap) {
if (snap.hasData &&
!snap.hasError &&
snap.data.snapshot.value != null) {
Map data = snap.data.snapshot.value;
List item = [];
print("data $data");
data.forEach(
(index,data) => item.add({"key": index,...data}));
print(item);
return ListView.builder(
reverse: true,itemCount: item.length,itemBuilder: (context,index) {
return Column(
children: <Widget>[
Text("$data"),],);
});
}
},);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)