I am using an AlertDialog
to show some data which I retrieve from firestore database. For that, I use the following code.
AlertDialog(
content: StreamBuilder<QuerySnapshot>(
stream: yourDataStream,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
// Return your loading widget here
return CircularProgressIndicator();
} else if (snapshot.hasError) {
// Handle any errors from the stream here if needed
return Text('Error: ${snapshot.error}');
} else if (snapshot.hasData) {
// Display your data when it's available
return Text(snapshot.data!);
} else {
return Text('Unexpected state');
}
},
),
)
My problem is when snapshot.hasData == true
, UI is not updating to show the available data. How can I fix this?
2
Answers
I think you should try to wrap up stream builder inside StatefulBuilder which will help you to update alert dialog.
once I tried this worked for me.
Let me know if it works or not for you.
Add your
Alert Dialog
content in aStateful Builder
and try using it like below. And let me know if it worked for you.