Hi this is my code but it gives me this error: Bad state: field does not exist within the DocumentSnapshotPlatform. im not sure where is the error.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class OrderSuccessful extends StatefulWidget {
@override
_OrderSuccessfulState createState() => _OrderSuccessfulState();
}
class _OrderSuccessfulState extends State<OrderSuccessful>{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Order Successful")),
resizeToAvoidBottomInset: true,
body: StreamBuilder(
stream: FirebaseFirestore.instance.collection('personalinfo').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
if (!snapshot.hasData){
return Text("no value");
}
return ListView(
children: snapshot.data!.docs.map((document){
return Text(document['personalinfo']);
}).toList(),
);
},
),
);
}
}
CodePudding user response:
You are trying to access a field named personalinfo
from the documents inside the collection in the named personalinfo
but unfortunlly this field doesn't exist.
So make sure that all the documents inside the personalinfo
collection contains a key named personalinfo
or just add a condition to check its existence before using it such as: document.contains('personalinfo')
.
The line you are using to access the field is:
return Text(document['personalinfo']);