3

I am having issues running my flutter application. I am using objectbox-dart for storing data in my app. So far so good, but when I create a store using path_provider, the getApplicationSupportDirectory() throws _CastError: Null check operator on a null value. Below is the output of 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!

Below is the exact line of code of path_provider file where exception is being caught

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

  return Directory(path);
}

I am unable to run my app. Any help would be appreciated. Thanks

Shoaib A
  • 63
  • 7
  • Was this ever solved? – Filled Stacks Oct 19 '21 at 10:15
  • @FilledStacks yes. Actually, I was unit testing my code block and calling getApplicationSupportDirectory() from main.dart was causing that error. Calling this code after WidgetsFlutterBinding.ensureInitialized() solved the issue. – Shoaib A Nov 01 '21 at 05:38

0 Answers0