flutter - CircularProgressIndicator 未及时触发
问题描述
有一个状态类
class _SignUpFormState extends State<SignUpForm> {
bool _isProcessing = false;
...
我在哪里构建方法
_isProcessing ? CircularProgressIndicator() : SizedBox(),
_isProcessing 在这个函数中被触发
void _submit() {
setState(() {
_isProcessing = true;
});
// doing something heavy that takes a while
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TabPage(),
),
);
问题是CircularProgressIndicator
在导航到其他屏幕之前运行了很短的时间。它不应该像上面代码中显示的那样在长期过程之前运行吗?
解决方案
你的重心不是异步的(因为你的方法不是异步的)那么它就不需要时间了。
如果您想显示 CircularProgressIndicator 一段时间,那么您可以使您的方法异步并添加未来延迟。
推荐阅读
- php - 如何获取 Twig 数组中的关键位置?
- git - 如何撤消 git checkout -B 分支?
- javascript - 之前配置的 ChromeDriver 服务仍在运行
- android - Searchview 在单击文本后显示矩形
- vertica - 如何将 Avro 记录数组加载到 Vertica ARRAY
- android - 如何将音频数据从 Android 流式传输到 WebSocket 服务器?
- java - 在 Java 中处理对象数组
- unity3d - GetComponent 重置布尔值
- php - 未设置可下载的 Woocommerce 产品内容
- javascript - HTML5 中的日期输入:使用纯 JavaScript 突出显示每个星期一