我正在使用带有CupertinoDeliversheet小部件的CupertinoModalPopup来显示一组选项供用户 Select .
我打算显示一个循环加载指示器,然后加上复选标记(勾选), 给用户一种他已经点击了该选项的印象,它是 使用Navingator.pop(上下文)弹出后保存. 首先,我try 使用100毫秒的延迟来实现这一点 future .点击按下后延迟 目前仅使用显示循环加载指示器的控件.但它不起作用.
这是我的代码,可以更好地解释我正在做的事情.仅发布相关代码.
@override
Widget build(BuildContext context) {
return CupertinoActionSheet(
title: KNText(
style: TextStyle(color: primaryTextColor),
'Video sound settings',
),
message: KNText(
style: TextStyle(color: primaryTextColor),
'Please choose from an option below :',
),
actions: <Widget>[
Container(
color: primaryColor,
child: CupertinoActionSheetAction(
onPressed: ({int index = 0}) async {
await Future.delayed(const Duration(milliseconds: 100), () {
setState(() {
VideosSoundSetting newType =
allVideosSoundSettings[index];
widget.onTypeChanged(newType);
_setEnabledInProgress(true);
Navigator.pop(context);
});
setState(() {
_enabledInProgress = false;
});
});
},
单击任意一个选项后,循环加载指示符(延迟:100毫秒),然后是勾选标记(延迟:50毫秒),以给用户一个成功的印象.目前下面仅配置循环加载指示器.
child: Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 153.0),
child: KNText(
style: TextStyle(color: primaryTextColor),
'Enabled',
),
),
_enabledInProgress
? const CircularProgressIndicator()
: Container()
],
),
)),
Container(
color: primaryColor,
child: CupertinoActionSheetAction(
// 单击任意一个选项后,循环加载指示符(延迟:100毫秒),然后是勾选标记(延迟:50毫秒),以给用户一个成功的印象.目前下面仅配置循环加载指示器.
onPressed: ({int index = 0}) async {
await Future.delayed(const Duration(milliseconds: 100), () {
setState(() {
VideosSoundSetting newType =
allVideosSoundSettings[index];
widget.onTypeChanged(newType);
_setEnabledInProgress(true);
Navigator.pop(context);
});
setState(() {
_enabledInProgress = false;
});
});
},
child: Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 150.0),
child: KNText(
style: TextStyle(color: primaryTextColor),
'Disabled',
),
),
_enabledInProgress
? const CircularProgressIndicator()
: Container()
],
),
)),
],
cancelButton: Container(
color: primaryColor,
child: CupertinoActionSheetAction(
isDefaultAction: true,
onPressed: () {
Navigator.pop(context);
},
child: const Row(children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 155.0),
child: KNText(
style: TextStyle(
color: Color.fromRGBO(255, 0, 0, 1.0),
fontWeight: FontWeight.w700),
'Cancel',
),
),
]),
),
));
}
void _setEnabledInProgress(bool enabledInProgress) {
_enabledInProgress = enabledInProgress;
}
正在工作的是:
选项和 Select 确实按照指定的以毫秒为单位的延迟工作
什么不是:
"启用"和"禁用"操作最后的循环进度指示器不会出现.修复持续时间延迟的循环进度指示器后,我打算调用复选标记勾选小部件,之后复选标记应该出现并从小部件本身弹出.
如果我能指出如何最好地实现上述目标的正确方向
- 加载指示器,延迟100毫秒.
- 复选标记勾选在加载指示器位于同一位置后立即出现,并在50毫秒后弹出
编辑于2024年4月29日
根据下面 comments 中从@anqit收到的指导,我确实取得了一些进展.已更新代码以反映更改.