I am wanting to get the list of data from the cloud firestore. I have setup everything. With the following code, i am just able to get one data instead of all the list. And I am getting the following error : Bad state: field does not exist within the DocumentSnapshotPlatform
class HomePage extends StatefulWidget {
static const routeName = 'homePage';
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
late String id;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Latest"),
backgroundColor: Colors.black,
),
body: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection("latest").orderBy('number',descending: true).snapshots(),
builder: (context, snapshot) {
return !snapshot.hasData
? Center(child: CircularProgressIndicator())
: ListView.builder(
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) {
DocumentSnapshot data = snapshot.data!.docs[index];
return Stack(
alignment: Alignment.topCenter,
fit: StackFit.loose,
clipBehavior: Clip.hardEdge,
children: [
GestureDetector(
child: Container(
height: 200,
width: MediaQuery.of(context).size.width,
child: Card(
child: Center(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
data['name'],
textAlign: TextAlign.start,
style: const TextStyle(
color: Colors.indigo,
fontWeight: FontWeight.bold,
),
),
])),
)),
onTap: () {
},
)
],
// ),
);
},
);
},
),
);
}
}
CodePudding user response:
I think you should check the document fields name and also make sure all the fields exist in all documents.