Flutter:错误状态:streambuilder中的DocumentSnapshotPlatform中不存在字段



在红屏中显示此错误时,我更新了我的包,但此错误再次显示

生成StreamBuilder<时引发以下StateError;查询快照<映射<一串动态>gt>(dirty,state:StreamBuilderBaseState<QuerySnapshot<Map<String,dynamic>>,异步快照<查询快照<映射<字符串,动态>gt>gt#eea86(:错误状态:DocumentSnapshotPlatform 中不存在字段

导致错误的相关小部件是:StreamBuilder<查询快照<映射<字符串,动态>gt>StreamBuilder:file:///C:/Users/flutt/Desktop/New%20folder/MarcJr-main/Logsyntax MarcJr master/lib/pages/Ecommerce/SellerDashboard/SoldItemScreen。dart:34:20

当抛出异常时,这是堆栈:#0 DocumentSnapshotPlatform.get_findKeyValueInMap(包:cloud_firestore_platform_interface/src/platform_innterface/platform-interface_document_snapshot.dart:87:7(#1 DocumentSnapshotPlatform.get_findComponent(包:cloud_firestore_platform_interface/src/platform_innterface/platform-interface_document_snapshot.dart:105:23(#2 DocumentSnapshotPlatform.get(包:cloud_firestore_platform_interface/src/platform_innterface/platform-interface_document_snapshot.dart:121:12(#3_JsonDocumentSnapshot.get(包:cloud_firestore/src/document_snapshot.dart:92:48(#4_JsonDocumentSnapshot。[](包:cloud_firestore/src/document_snapshot.dart:96:40(#5_SoldItemScreenState.build。。(包:marcjrfoundation/pages/Econmmerce/SellerDashboard/SoldItemScreen。dart:63:39(#6 MappedListIterable.elementAt(dart:_internal/iterable.dart:413:31(#7 ListIterator.moveNext(dart:_internal/iterable.dart:342:26(#8个新的_GrowableList_有效长度Iterable(dart:core-patch/growable_array.dart:189:27(#9新_GrowableList.of(dart:core-patch/growable_array.dart:150:28(#10新List.of(dart:core-patch/array_patch.dart:51:28(#11 ListIterable.toList(dart:_internal/iterable.dart:213:44(#12_SoldItemScreenState.build.(包:marcjrfoundation/pages/Ecommerce/SellerDashboard/SoldItemScreen。dart:89:22(#13 StreamBuilder.build(包:flutter/src/widgets/async.dart:444:81(#14_StreamBuilderBaseState.build(包:flutter/src/widgets/async.dart:124:48(#15 StatefulElement.build(包:flutter/src/widgets/framework.dart:4992:27(#16 ComponentElement.performRebuild(包:flutter/src/widgets/framework.dart:4878:15(#17 StatefulElement.performRebuild(包:flutter/src/widgets/framework.dart:5050:11(#18 Element.rebuild(包:flutter/src/widgets/framework。dart:4604:5(#19 BuildOwner.buildScope(包:flutter/src/widgets/framework.dart:2667:19(

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:marcjrfoundation/services/SharedPreferences/sharedprefs_helper.dart';
import 'package:marcjrfoundation/services/device_size.dart';
import 'package:websafe_svg/websafe_svg.dart';
import '../ProductItem/sellerProductItem.dart';
class SoldItemScreens extends StatefulWidget {
static final String tag = '/soldItemScreen';
@override
_SoldItemScreensState createState() => _SoldItemScreensState();
}
class _SoldItemScreensState extends State<SoldItemScreens> {
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: Text(
'Sold Products',
style: TextStyle(
fontSize: ResponsiveWidget.isSmallScreen(context) ? 17.0 : 25.0),
),
),
body: Column(
children: [
SizedBox(
height: 10.0,
),
Container(
color: Color(0xffF7F7F7),
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection("items")
.where('seller', isEqualTo: parentIdGlobal)
.where('isSold', isEqualTo: true)
.snapshots(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (!snapshot.hasData)
return Center(
child: CircularProgressIndicator(),
);
List<DocumentSnapshot<Object>> docs = snapshot.data!.docs;
if (docs.length == 0) {
return Center(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: WebsafeSvg.asset(
'assets/images/sold-out.svg',
fit: BoxFit.cover,
height: MediaQuery.of(context).size.height / 5,
),
),
);
}
return ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: docs.map((DocumentSnapshot doc) {
bool isSold = doc['isSold'];
bool isLiked = doc['isLiked'];
String itemId = doc['itemId'];
String seller = doc['seller'];
String sellerName = doc['sellerName'];
String title = doc['title'];
String desc = doc['desc'];
String price = doc['price'];
String condition = doc['condition'];
String category = doc['category'];
String location = doc['location'];
String itemImage = doc['imageDownloadUrl'];
return SellerProductItem(
itemId: itemId,
seller: seller,
sellerName: sellerName,
title: title,
desc: desc,
price: price,
itemImage: itemImage,
isLiked: isLiked,
isSold: isSold,
category: category,
condition: condition,
location: location,
);
}).toList(),
);
},
),
),
],
),
);
}
}

根据cloud_firestore的当前版本(3.4.8(,

代码的下一行出现问题。

List<DocumentSnapshot<Object>> docs = snapshot.data!.docs;

您选择的数据类型不正确。CCD_ 1是CCD_。

您可以用下面的代码片段替换代码中的streamBuilder。

StreamBuilder(
stream: FirebaseFirestore.instance
.collection("items")
.where('seller', isEqualTo: parentIdGlobal)
.where('isSold', isEqualTo: true)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return CircularProgressIndicator();
}
final List<QueryDocumentSnapshot<Map<String, dynamic>>> docSnapList =
snapshot.data?.docs ?? [];
if (docSnapList.isEmpty) {
return Center(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: WebsafeSvg.asset(
'assets/images/sold-out.svg',
fit: BoxFit.cover,
height: MediaQuery.of(context).size.height / 5,
),
),
);
}
final List<Map<String, dynamic>> docList = docSnapList.map((QueryDocumentSnapshot<Map<String, dynamic>> queryDocumentSnapshot) => queryDocumentSnapshot.data()).toList();
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: docList.length,
itemBuilder: (context, index) {
bool isSold = docList[index]['isSold'];
bool isLiked = docList[index]['isLiked'];
String itemId = docList[index]['itemId'];
String seller = docList[index]['seller'];
String sellerName = docList[index]['sellerName'];
String title = docList[index]['title'];
String desc = docList[index]['desc'];
String price = docList[index]['price'];
String condition = docList[index]['condition'];
String category = docList[index]['category'];
String location = docList[index]['location'];
String itemImage = docList[index]['imageDownloadUrl'];
return SellerProductItem(
itemId: itemId,
seller: seller,
sellerName: sellerName,
title: title,
desc: desc,
price: price,
itemImage: itemImage,
isLiked: isLiked,
isSold: isSold,
category: category,
condition: condition,
location: location,
);
},
);
},
);

最新更新