簡體   English   中英

Flutter:如何隱藏AlertDialog

[英]Flutter : How to hide AlertDialog

我有如下對話框:

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),
            )
          ],
        ),
      );
    },
  );

並嘗試使用 function 關閉它:

Navigator.of(context, rootNavigator: true).pop();

在開發過程中,導航器 function 運行良好並按預期關閉對話框。 但是當我在 google play store 上傳應用程序,並通過 google play store 運行應用程序時,導航器 function 實際上關閉了應用程序而不是關閉對話框。 為什么會這樣? 我的代碼有問題嗎?

這是我的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.of(context, rootNavigator: true).pop(); 僅當您的應用程序中有多個 Navigator 對象時才需要。

否則,無需聲明rootNavigator: True

嘗試更改useRootNavigator: false ,並通過調用Navigator.of(context).pop()關閉對話框

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM