首页 > 解决方案 > 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在导航到其他屏幕之前运行了很短的时间。它不应该像上面代码中显示的那样在长期过程之前运行吗?

标签: flutter

解决方案


你的重心不是异步的(因为你的方法不是异步的)那么它就不需要时间了。

如果您想显示 CircularProgressIndicator 一段时间,那么您可以使您的方法异步并添加未来延迟。


推荐阅读