Android 在构建StreamBuilder时引发了以下断言<;QuerySnapshot>;(脏,状态:_StreamBuilderBaseState<;QuerySnapshot,AsyncSnapshot
我在我的多供应商应用程序中遇到此错误。当我在应用程序中添加新产品时,它会转到“未发布”部分,然后您必须从该部分发布它。当我添加单个产品时,没有问题(我想是因为它不会发生在单个产品上。)但是当我添加第二个产品并转到未发布的页面时,我得到了这个错误。 ''' '''Android 在构建StreamBuilder时引发了以下断言<;QuerySnapshot>;(脏,状态:_StreamBuilderBaseState<;QuerySnapshot,AsyncSnapshot,android,firebase,flutter,dart,visual-studio-code,Android,Firebase,Flutter,Dart,Visual Studio Code,我在我的多供应商应用程序中遇到此错误。当我在应用程序中添加新产品时,它会转到“未发布”部分,然后您必须从该部分发布它。当我添加单个产品时,没有问题(我想是因为它不会发生在单个产品上。)但是当我添加第二个产品并转到未发布的页面时,我得到了这个错误。 ''' ''' 类未发布的产品扩展了无状态小部件{ @凌驾 小部件构建(构建上下文){ FirebaseServices_services=FirebaseServices(); 返回容器( 孩子:StreamBuilder( 流: _服务。产品。其中
类未发布的产品扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
FirebaseServices_services=FirebaseServices();
返回容器(
孩子:StreamBuilder(
流:
_服务。产品。其中(‘已发布’,isEqualTo:
false)。快照(),
生成器:(上下文,快照){
if(snapshot.hasError){
返回文本(“出错了…”);
}
if(snapshot.connectionState==connectionState.waiting){
返回中心(
子对象:CircularProgressIndicator(),
);
}
返回SingleChildScrollView(
孩子:FittedBox(
子:数据表(
是的,
数据行高度:60,
headingRowColor:MaterialStateProperty.all(Colors.Gray[200]),表示所有颜色,
栏目:[
数据列(
标签:展开(子项:文本('Jobs')),
),
数据列(
标签:文本(“图像”),
),
数据列(
标签:文本(“信息”),
),
数据列(
标签:文本(“操作”),
),
],
行:_productDetails(snapshot.data、context),
),
),
);
},
),
);
}
列表\u产品详细信息(QuerySnapshot快照,上下文){
List newList=snapshot.docs.map((DocumentSnapshot文档){
如果(文档!=null){
返回数据行(单元格:[
数据单元(容器)(
孩子:ListTile(
contentPadding:EdgeInsets.zero,
标题:世界其他地区(
儿童:[
正文(
“名称:”,
样式:TextStyle(fontWeight:fontWeight.bold,fontSize:
15),
),
扩大(
子项:文本(document.data()['productName'],
样式:TextStyle(字体大小:15)),
],
),
字幕:世界其他地区(
儿童:[
正文(
“SKU:”,
样式:TextStyle(fontWeight:fontWeight.bold,fontSize:
12),
),
文本(document.data()['sku'],样式:TextStyle(fontSize:
12)),
],
),
),
)),
数据单元(容器)(
孩子:填充(
填充:常数边集全部(3.0),
孩子:排(
儿童:[
图像网络(
document.data()['productImage'],
宽度:50,
),
],
),
),
)),
数据单元(图标按钮(
已按下:(){
导航器。推(
上下文
材料路线(
生成器:(上下文)=>EditViewProduct(
productId:document.data()['productId'],
),
),
);
},
图标:图标(Icons.info\u轮廓),
)),
数据单元(弹出按钮(document.data()),
]);
}
}).toList();
返回newList;
}
小部件弹出按钮(数据,{BuildContext}){
FirebaseServices_services=FirebaseServices();
返回弹出菜单按钮(
onSelected:(字符串值){
如果(值==“发布”){
_服务.出版产品(
id:data['productId'],
);
}
如果(值==“删除”){
_deleteProduct(id:data['productId']);
}
},
itemBuilder:(构建上下文)=>[
常数PopupMenuItem(
值:“发布”,
孩子:ListTile(
前导:图标(图标。检查),
标题:文本(“发布”),
),
),
常数PopupMenuItem(
值:“删除”,
孩子:ListTile(
前导:图标(图标。删除轮廓),
标题:文本(“删除作业”),
),
),
]);
}
}
'''
在所有密钥中使用空安全性
document?.data()['your_key'] ?? "default data"
了解有关空安全性的更多信息
Here is my code
class UnPublishedProducts extends StatelessWidget {
@override
Widget build(BuildContext context) {
FirebaseServices _services = FirebaseServices();
return Container(
child: StreamBuilder(
stream:
_services.products.where('published', isEqualTo:
false).snapshots(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return Text('Something went wrong..');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
return SingleChildScrollView(
child: FittedBox(
child: DataTable(
showBottomBorder: true,
dataRowHeight: 60,
headingRowColor: MaterialStateProperty.all(Colors.grey[200]),
columns: <DataColumn>[
DataColumn(
label: Expanded(child: Text('Jobs')),
),
DataColumn(
label: Text('Image'),
),
DataColumn(
label: Text('Info'),
),
DataColumn(
label: Text('Actions'),
),
],
rows: _productDetails(snapshot.data, context),
),
),
);
},
),
);
}
List<DataRow> _productDetails(QuerySnapshot snapshot, context) {
List<DataRow> newList = snapshot.docs.map((DocumentSnapshot document) {
if (document != null) {
return DataRow(cells: [
DataCell(Container(
child: ListTile(
contentPadding: EdgeInsets.zero,
title: Row(
children: [
Text(
'Name: ',
style: TextStyle(fontWeight: FontWeight.bold, fontSize:
15),
),
Expanded(
child: Text(document.data()['productName'],
style: TextStyle(fontSize: 15))),
],
),
subtitle: Row(
children: [
Text(
'SKU: ',
style: TextStyle(fontWeight: FontWeight.bold, fontSize:
12),
),
Text(document.data()['sku'], style: TextStyle(fontSize:
12)),
],
),
),
)),
DataCell(Container(
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Row(
children: [
Image.network(
document.data()['productImage'],
width: 50,
),
],
),
),
)),
DataCell(IconButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EditViewProduct(
productId: document.data()['productId'],
),
),
);
},
icon: Icon(Icons.info_outline),
)),
DataCell(popUpButton(document.data())),
]);
}
}).toList();
return newList;
}
Widget popUpButton(data, {BuildContext context}) {
FirebaseServices _services = FirebaseServices();
return PopupMenuButton<String>(
onSelected: (String value) {
if (value == 'publish') {
_services.publishProduct(
id: data['productId'],
);
}
if (value == 'delete') {
_services.deleteProduct(id: data['productId']);
}
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'publish',
child: ListTile(
leading: Icon(Icons.check),
title: Text('Publish'),
),
),
const PopupMenuItem<String>(
value: 'delete',
child: ListTile(
leading: Icon(Icons.delete_outline),
title: Text('Delete job'),
),
),
]);
}
}
document?.data()['productName'] ?? "-"
document?.data()['your_key'] ?? "default data"