I'm calling show my dialog when a button is pushed to display the progress of an upload which is in the parent.
Throughout the upload function's parts I'm updating state like setState(() => _progress = _progress + 0.05);
for example. However my dialog value is not correctly being updated as well. I think that the dialog is not rebuilding. How do I get the dialog to listen to this value and rebuild when it's updated?
Dialog code:
Future<void> _showMyDialog() async {
return showDialog<void>(
context: context,
barrierDismissible: true, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
insetPadding: EdgeInsets.all(10.0),
content: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return Container(
height: MediaQuery.of(context).size.width * 0.3,
width: MediaQuery.of(context).size.width * 0.9,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Uploading...",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 20),
),
SizedBox(height: 30),
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10)),
child: LinearProgressIndicator(
minHeight: 15,
value: _progress,
))
])),
);
}));
},
);
Trigger dialog code:
onPressed: () async {
setState(() => loading = true);
_showMyDialog();
await uploadAudio();
setState(() => loading = false);
},