Flutter path_provider getApplicationSupportDirectory() 在空值上抛出 _CastError Null 检查运算符

时间:2021-06-08 05:10:12

标签: flutter dart dart-null-safety

我在运行 Flutter 应用程序时遇到问题。我正在使用 objectbox-dart 在我的应用程序中存储数据。到目前为止一切顺利,但是当我使用 path_provider 创建商店时,getApplicationSupportDirectory() 会抛出 _CastError: Null check operator on a null value。下面是 flutter doctor -v

的输出
    [✓] Flutter (Channel stable, 2.2.1, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-PK)
    • Flutter version 2.2.1 at /Users/muhammadumar/sdks/flutter
    • Framework revision 02c026b03c (11 days ago), 2021-05-27 12:24:44 -0700
    • Engine revision 0fdb562ac8
    • Dart version 2.13.1

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/muhammadumar/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      ? https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      ? https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] VS Code (version 1.56.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.23.0

[✓] Connected device (2 available)
    • MI 8 Lite (mobile) • bb4e8ab • android-arm64  • Android 10 (API 29)
    • Chrome (web)       • chrome  • web-javascript • Google Chrome 91.0.4472.77

• No issues found!

以下是 path_provider 文件中捕获异常的确切代码行

    Future<Directory> getApplicationSupportDirectory() async {
  final String? path = await _platform.getApplicationSupportPath();
  if (path == null) {
    throw MissingPlatformDirectoryException(
        'Unable to get application support directory');
  }

  return Directory(path);
}

我无法运行我的应用程序。任何帮助,将不胜感激。 谢谢

0 个答案:

没有答案