当按下按钮以显示父级中的上传进度时,我正在调用显示我的对话框。
在整个上传功能的部分,我正在更新状态 setState(() => _progress = _progress + 0.05);
,例如。但是,我的对话框值也没有正确更新。我认为对话框没有重建。如何让对话框收听此值并在更新时重建?
对话框代码:
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,
))
])),
);
}));
},
);
触发对话代码:
onPressed: () async {
setState(() => loading = true);
_showMyDialog();
await uploadAudio();
setState(() => loading = false);
},