i am getting data by document id but i get this error:
Bad state: cannot get a field on a DocumentSnapshotPlatform which does not exist
and it's working, i can get the data from firebase by document id but it's giving the error in debug console.
I'm getting data with StreamBuilder:
StreamBuilder(
stream: _databaseService.productCollection.doc(docID).snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(
valueColor:
new AlwaysStoppedAnimation<Color>(Colorsx.mainColor),
),
);
}
var document1 = snapshot.data;
return Container(
decoration: BoxDecoration(
color: Colorsx.mainColor,
borderRadius: radius,
),
// color: Colorsx.mainColor,
child: Column(
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Chip(
label: LabelText1("Ürün Adı: "),
backgroundColor: Colorsx.mainColor,
),
Chip(
shadowColor: Colorsx.mainColor2,
elevation: 24,
label: LabelText1(document1["productName"] ?? ""),
backgroundColor: Colorsx.mainColor2,
),
],
),
),
],
),
);
},
),
i couldn't find what is the problem in here but according to my researches, it' related with the map . is there any idea?
It looks like _databaseService.productCollection.doc(docID)
may not point to an existing document at some point while this code runs. If you then call document1["productName"]
on it as you do, it'll raise the error you see.
So you need to decide what to render when this situation happens (even if only briefly). For example, you could just make the CircularProgressIndicator
stay on the screen until a document is available:
if (!snapshot.hasData || !snapshot.data.exists) {
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments