I thought I understood StreamBuilders but I have some doubts that are puzzling me.
I thought that a ConnectionState.waiting means that the connection with the stream is
You need to add listen:false
to your provider.
This is likely to be your Firestore rules. If it's like this:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
then you'll have t be authenticated to grab the data. You can test this quickly (but not permanently) by allowing access to the DB from anyone ...
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
... but please do change it to something more secure afterwards.
Encountered the same issue. Checking the code, if you passed a not null data, the status will be set to waiting.
If you want to make the status to be 'none', then you need to pass null first and pass the Stream
to the StreamBuilder
when the data is on fetching
.
I use a stream variable otherwise I would have the same error
Stream<List<List<User>>> friendUser;
@override
Widget build(BuildContext context) {
final
db = Provider.of<FirestoreDatabase>(context, listen: false);
friendUser = StreamZip([db.usersStream1(), db.usersStream2()]);
return Scaffold(
...
StreamBuilder<List<List<User>>>(
stream: friendUser,
//qui ont deja discuter
initialData: [],
builder: (context, snapshot) {...}),
);
}
I suggest you drop the if/else condition and use a switch to check for the ConnectionState.
switch(snapshot.connectionState){
case ConnectionState.waiting:
return Center(child:CircularProgressIndicator());
break;
default:
if(snapshot.hasError){
// Handle errors
}else if(!snapshot.hasData){
// Handle no data
}else {
// Check for null
var result = snapshot.data
if(result!=null){
//Handle the null value
} else {
}
}
break;
}