Hey guys I was trying to build a streambuilder to access my cloud storage but I am unable to do streamsnapshot.data.doc due to that I am not able to use the documents for my application
This is my streambuilder code:
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class ChatScreen extends StatelessWidget {
const ChatScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: StreamBuilder(
stream: FirebaseFirestore
.instance
.collection('chats')
.snapshots(),
builder: (ctx, streamSnapshot) {
if (streamSnapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
return ListView.builder(
itemCount: streamSnapshot.data, **//not able to add .documents.length after this**
itemBuilder: (ctx, index) => Container(
padding: EdgeInsets.all(8.0),
child: Text('This is working'),
));
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
),
);
}
}
CodePudding user response:
You have to add the type of your object on your StreamBuilder like this :
StreamBuilder<YourObject>
After that, you will access to the documents
from the streamSnapshot