flutter - 如何关闭 Navigator.of(context).overlay

标签 flutter

用我的代码:

final CustomOverlay customOverlay = new CustomOverlay(); 
Navigator.of(context).overlay.insert(OverlayEntry(builder: (BuildContext context) { return customOverlay; }));

但是当我想关闭那个 customOverlay 但我不知道如何......

我尝试了Navigator.of(context).overlay.dispose();

但这不起作用......

[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.13.6 17G4015, locale en-NL)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
✗ Verify that all connected devices have been paired with this computer in Xcode.
If all devices have been paired, libimobiledevice and ideviceinstaller may require updating.
To update with Brew, run:
brew update
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
[✓] Android Studio (version 3.3)
[✓] Connected device (1 available)

! Doctor found issues in 1 category.
Macbooks-MacBook-Pro:TweensTalent-Front-end daniquedejong$ flutter doctor -v
[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.13.6 17G4015, locale en-NL)
• Flutter version 1.0.0 at /Users/daniquedejong/tools/flutter
• Framework revision [5391447](https://github.com/flutter/flutter/commit/5391447fae6209bb21a89e6a5a6583cac1af9b4b) (3 months ago), 2018-11-29 19:41:26 -0800
• Engine revision [7375a0f](https://github.com/flutter/flutter/commit/7375a0f414bde4bc941e623482221db2fc8c4ab5)
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Android SDK at /Users/daniquedejong/Library/Android/sdk
• Android NDK at /Users/daniquedejong/Library/Android/sdk/ndk-bundle
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.

[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.1, Build version 10B61
✗ Verify that all connected devices have been paired with this computer in Xcode.
If all devices have been paired, libimobiledevice and ideviceinstaller may require updating.
To update with Brew, run:
brew update
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
• ios-deploy 2.0.0
• CocoaPods version 1.5.3

[✓] Android Studio (version 3.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 32.0.1
• Dart plugin version 182.5215
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[✓] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

最佳答案

使用 remove 从您的 OverlayEntry

final customOverlay = new CustomOverlay(); 
final overlayEntry = OverlayEntry(builder: (BuildContext context) { return customOverlay; })); 
overlayEntry.remove();

关于flutter - 如何关闭 Navigator.of(context).overlay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54903690/

相关文章:

flutter - flutter 如何从相机单击正方形图像并显示正方形图像

Flutter 应用程序错误 - 类型 'Timestamp' 不是类型 'DateTime' 的子类型

visual-studio - URI 的目标不存在 : 'package:english_words/english_words.dart' . dart

flutter - 检测 flutter 中的模拟位置

google-maps - 获取数据快照到位置纬度经度

Flutter Web 集成测试 CORS XMLHttpRequest 错误

flutter - Flutter:无法移动或更改SDK位置

screenshot - 在 Flutter 中截取特定 Widget 的屏幕截图?

flutter - 如何根据日历中的选择在 18 岁以下时隐藏小部件

flutter - 如何控制基于父项或子项的调整大小行为?