我正在尝试将 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,
),
),
),
最佳答案
为了处理 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,
),
),
)
关于firebase - flutter :CircularProgressIndicator(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51663756/