'Bad state: field does not exist within the DocumentSnapshotPlatform Flutter Firestore
I'm having troubles with the error in the question title, followed the official flutter tutorial: https://www.youtube.com/watch?v=DqJ_KjFzL9I
Solved all errors that the IDE marked, and now my code has no errors but only get this message when I run the app.
my firestore db:

My code:
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class Cloudtest extends StatefulWidget {
const Cloudtest({Key? key}) : super(key: key);
@override
_CloudtestState createState() => _CloudtestState();
}
class _CloudtestState extends State<Cloudtest> {
Widget _buildListItem(BuildContext context,DocumentSnapshot document){
return ListTile(
title: Text(document['name'])
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: StreamBuilder(
stream: FirebaseFirestore.instance.collection('todo').snapshots(),
builder: (context,AsyncSnapshot snapshot){
if (!snapshot.hasData) return const Text('Loading...');
return ListView.builder(
itemCount: snapshot.data!.docs.length,
itemBuilder: (context,index) =>
_buildListItem(context,snapshot.data!.docs[index]),
);
}
),
);
}
}
What I expected to get was a list with the elements in the database, I call this page with a button in another flutter page, the rest of the app works fine. Any help aprecciated!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
