我有一个如下对话框:
showDialog(
context: context,
barrierDismissible : true,
useRootNavigator: true,
builder: (BuildContext context) {
return new AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5.0))),
title: new Flex(
direction: Axis.horizontal,
children: <Widget>[
new CircularProgressIndicator(),
new Padding(
padding: EdgeInsets.only(left: 20.0),
child: new Text("Loading...", style: new TextStyle(
fontSize: 14.0,
color: Colors.black54,
fontFamily: "GoogleSans",
fontWeight: FontWeight.w400
), textAlign: TextAlign.left),
)
],
),
);
},
);
并尝试使用函数关闭它:
Navigator.of(context, rootNavigator: true).pop();
在开发过程中,导航器功能运行良好并按预期关闭对话框。但是当我在 Google Play 商店中上传应用程序并通过 Google Play 商店运行应用程序时,导航器功能实际上会关闭应用程序而不是关闭对话框。为什么会发生这样的事?我的代码有问题吗?
这是我的flutter doctor -v
Flutter (Channel stable, v1.12.13+hotfix.7, on Mac OS X 10.15.3 19D76, locale en-ID)
• Flutter version 1.12.13+hotfix.7 at /Users/macpro/Documents/Development/flutter
• Framework revision 9f5ff2306b (2 weeks ago), 2020-01-26 22:38:26 -0800
• Engine revision a67792536c
• Dart version 2.7.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/macpro/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[!] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install:
sudo gem install cocoapods
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 43.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.42.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.8.0
[✓] Connected device (1 available)
• SM J330G • 4200db84cc425415 • android-arm • Android 9 (API 28)
最佳答案
不要使用 Navigator.of(context, rootNavigator: true).pop();
,而是使用 Navigator.of(context).pop();
这应该可以解决问题。仅当您的应用程序中有多个 Navigator 对象时,才需要使用 Navigator.of(context, rootNavigator: true).pop();
。
否则,不需要声明rootNavigator: True
。
关于 flutter : How to hide AlertDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60181566/