Flutter 在执行异步等待任务时显示小部件

Flutter 在执行异步等待任务时显示小部件,flutter,Flutter,我有以下执行函数的onTap事件: onTap: () async { await firestoreUserData.updateProfilePicture(url); }) 在执行等待时,是否可以显示某种加载指示器(小部件,如ProgressIndicator)?我不能使用futurebuilder,因为这是一个onTap事件 只需设置加载状态(在类中定义) 在您的构建中: Widget build(BuildContext context) { if(_isLoading)

我有以下执行函数的onTap事件:

onTap: () async {
  await firestoreUserData.updateProfilePicture(url);
})

在执行等待时,是否可以显示某种加载指示器(小部件,如ProgressIndicator)?我不能使用futurebuilder,因为这是一个onTap事件

只需设置加载状态(在类中定义)

在您的构建中:

Widget build(BuildContext context) {
    if(_isLoading)
         return Text("Loading");
    else
         //your stuff here.
}

进入tap时,您可以更新控制活动指示器外观与否的变量,但是,要使其出现,您需要通过setstate或stream或futurebuild更新小部件(如果它在全屏上,则为脚手架)。要删除活动指示器,请使用.themes()而不是wait并更新控制变量的状态,然后再次更新它将出现的小部件。感谢我通过创建全局bool并将状态设置为更改bool来实现它,如果bool为true,则在重建树时将显示加载指示器,等待完成后,它会再次将状态设置为false,将bool设置为“在等待执行时是否可能显示某种加载指示器(小部件,如ProgressIndicator)?我不能使用futurebuilder,因为这是一个onTap事件。”-是的,您可以使用
futurebuilder
,它是否为
onTap
事件并不重要
Widget build(BuildContext context) {
    if(_isLoading)
         return Text("Loading");
    else
         //your stuff here.
}