颤振:CircularProgressIndicator()

时间:2018-08-03 00:19:45

标签: firebase dart material-design flutter floating-action-button

我正在尝试将FloatingActionButton.extended更改为在按下后变为CircularProgressIndicator,等待ensureLoggedIn()功能完成然后移至下一个屏幕。

我的代码:

new FloatingActionButton.extended(
            elevation: 20.0,
            backgroundColor: Colors.white,
            onPressed: () async {
              await ensureLoggedIn();

              Navigator.push(
                  context, MaterialPageRoute(builder: (_) => HomeScreen()));
            },
            icon: Icon(
              Icons.insert_emoticon,
              size: 30.0,
              color: Colors.black,
            ),
            label: new Text(
              "JOIN NOW!",
              style: TextStyle(
                fontSize: 30.0,
                color: Colors.black,
              ),
            ),
          ),

1 个答案:

答案 0 :(得分:3)

为了处理loading变量,我做了一些更改。

将登录方法放在build方法之外,如下所示:

    login() async {
        setState(() {
          isLoading = true;
        });
        //your task here
        await ensureLoggedIn();
        setState(() {
          isLoading = false;
        });
        Navigator.push(context, MaterialPageRoute(builder: (_) => HomeScreen()));
      }   

您的小部件的一部分:

    isLoading
              ? CircularProgressIndicator()
              : new FloatingActionButton.extended(
                  elevation: 20.0,
                  backgroundColor: Colors.white,
                  onPressed: login,
                  icon: Icon(
                    Icons.insert_emoticon,
                    size: 30.0,
                    color: Colors.black,
                  ),
                  label: new Text(
                    "JOIN NOW!",
                    style: TextStyle(
                      fontSize: 30.0,
                      color: Colors.black,
                    ),
                  ),
                )