Android 颤振显示和隐藏警报对话框取决于动态值

Android 颤振显示和隐藏警报对话框取决于动态值,android,ios,flutter,mobile,widget,Android,Ios,Flutter,Mobile,Widget,在此代码段中,事件值是可以动态更改的流值 LocationPermissions().serviceStatus.listen((event) { if(event == ServiceStatus.disabled){ print('Location Disabled'); testAlert(context); // Show dialog }else{ testAlert(context); //I want hide dialog wh

在此代码段中,事件值是可以动态更改的流值

LocationPermissions().serviceStatus.listen((event) {
    if(event == ServiceStatus.disabled){
      print('Location Disabled');
      testAlert(context); // Show dialog
    }else{
      testAlert(context); //I want hide dialog when user enable location.How do?
      print('Location Enabled');
         }
}   
这是我的对话代码

void testAlert(BuildContext context){
  showDialog(
    context: context,
    builder: (BuildContext context) {
      // return object of type Dialog
      return AlertDialog(
        title: new Text("Location service disable"),
        content: new Text("You must enable your location access"),
        actions: <Widget>[
          // usually buttons at the bottom of the dialog
          new FlatButton(
            child: new Text("Go Setting"),
            onPressed: () {
              openLocationSetting();
              //visible ?Navigator.pop(context , true): Navigator.pop(context, false);

            },
          ),
        ],
      );
    },
  );
}
void testAlert(构建上下文){
显示对话框(
上下文:上下文,
生成器:(BuildContext上下文){
//返回对话框类型的对象
返回警报对话框(
标题:新文本(“位置服务禁用”),
内容:新文本(“您必须启用位置访问”),
行动:[
//通常是对话框底部的按钮
新扁平按钮(
子项:新文本(“Go设置”),
已按下:(){
openLocationSetting();
//可见?Navigator.pop(上下文,true):Navigator.pop(上下文,false);
},
),
],
);
},
);
}

显示和隐藏的方式取决于事件值。谢谢。

当用户启用了
位置
后,不要调用对话框方法,只需删除这一行
testAlert(上下文)

}

更新:-

void testAlert(BuildContext context){
  showDialog(
    context: context,
    builder: (BuildContext context) {
      // return object of type Dialog
      return AlertDialog(
        title: new Text("Location service disable"),
        content: new Text("You must enable your location access"),
        actions: <Widget>[
          // usually buttons at the bottom of the dialog
          new FlatButton(
            child: new Text("Go Setting"),
            onPressed: () {
              Navigator.pop(context)
              openLocationSetting();
              

            },
          ),
        ],
      );
    },
  );
}
在此对话框中,通过调用
Navigator.pop()
来解除平面按钮上的警报 对话将被取消

示例:-

void testAlert(BuildContext context){
  showDialog(
    context: context,
    builder: (BuildContext context) {
      // return object of type Dialog
      return AlertDialog(
        title: new Text("Location service disable"),
        content: new Text("You must enable your location access"),
        actions: <Widget>[
          // usually buttons at the bottom of the dialog
          new FlatButton(
            child: new Text("Go Setting"),
            onPressed: () {
              Navigator.pop(context)
              openLocationSetting();
              

            },
          ),
        ],
      );
    },
  );
}

当用户启用了
location
时,不调用对话框方法,只需删除这一行
testAlert(上下文)

}

更新:-

void testAlert(BuildContext context){
  showDialog(
    context: context,
    builder: (BuildContext context) {
      // return object of type Dialog
      return AlertDialog(
        title: new Text("Location service disable"),
        content: new Text("You must enable your location access"),
        actions: <Widget>[
          // usually buttons at the bottom of the dialog
          new FlatButton(
            child: new Text("Go Setting"),
            onPressed: () {
              Navigator.pop(context)
              openLocationSetting();
              

            },
          ),
        ],
      );
    },
  );
}
在此对话框中,通过调用
Navigator.pop()
来解除平面按钮上的警报 对话将被取消

示例:-

void testAlert(BuildContext context){
  showDialog(
    context: context,
    builder: (BuildContext context) {
      // return object of type Dialog
      return AlertDialog(
        title: new Text("Location service disable"),
        content: new Text("You must enable your location access"),
        actions: <Widget>[
          // usually buttons at the bottom of the dialog
          new FlatButton(
            child: new Text("Go Setting"),
            onPressed: () {
              Navigator.pop(context)
              openLocationSetting();
              

            },
          ),
        ],
      );
    },
  );
}

使用
Navigator.pop(context)
隐藏对话框add?代码bro@JideI编写了一个答案。选中iTunes
Navigator.pop(context)
以隐藏对话框add?代码bro@JideI编写了一个答案。检查itI是否成功,先生。如果我在用户启用位置服务时删除该行,则如何显示检测对话框。您的回答是,当用户单击“设置”按钮时,对话框将关闭,但用户不选择“打开位置”。我想关闭并显示取决于我的回答,当用户返回应用程序时,您需要签入resume lifecycle方法,再次检查位置是否启用,如果不显示对话框,请让我们看。我做到了,先生。如果我在用户启用位置服务时删除该行,则如何显示检测对话框。您的回答是,当用户单击“设置”按钮时,对话框将关闭,但用户不选择位置。我想关闭并显示取决于我的回答,当用户返回应用程序时,您需要签入resume lifecycle方法,再次检查位置是否已启用,如果未启用,请显示Dialogus。