Skip to content

PathProvider.getApplicationDocumentsDirectory sometimes returns null #6359

Closed

Description

@drewwarren

Steps to Reproduce

Run the following app and click the "print app dir" button lots of times. observe that sometimes the result is null and other times we get the app dir.

import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(
    new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new FlutterDemo(),
    ),
  );
}

class FlutterDemo extends StatefulWidget {
  FlutterDemo({Key key}) : super(key: key);

  @override
  _FlutterDemoState createState() => new _FlutterDemoState();
}

class _FlutterDemoState extends State<FlutterDemo> {
  Future printAppDir() async {
    Directory appDir = await PathProvider.getApplicationDocumentsDirectory();
    print(appDir?.path ?? "null appDir");
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          title: new Text('Flutter Demo'),
        ),
        body: new Column(children: [
          new RaisedButton(
              child: new Text("print app dir"), onPressed: printAppDir),
        ]));
  }
}

Logs

Users/drewwarren/Library/Developer/CoreSimulator/Devices/16BCCC3C-2F9C-401F-B2BF-97F1E3D2929A/data/Containers/Data/Application/A3252D13-A6D7-4B9F-8563-A339446A1E43/Documents
/Users/drewwarren/Library/Developer/CoreSimulator/Devices/16BCCC3C-2F9C-401F-B2BF-97F1E3D2929A/data/Containers/Data/Application/A3252D13-A6D7-4B9F-8563-A339446A1E43/Documents
null appDir
/Users/drewwarren/Library/Developer/CoreSimulator/Devices/16BCCC3C-2F9C-401F-B2BF-97F1E3D2929A/data/Containers/Data/Application/A3252D13-A6D7-4B9F-8563-A339446A1E43/Documents
null appDir
null appDir
null appDir
null appDir
null appDir
/Users/drewwarren/Library/Developer/CoreSimulator/Devices/16BCCC3C-2F9C-401F-B2BF-97F1E3D2929A/data/Containers/Data/Application/A3252D13-A6D7-4B9F-8563-A339446A1E43/Documents
/Users/drewwarren/Library/Developer/CoreSimulator/Devices/16BCCC3C-2F9C-401F-B2BF-97F1E3D2929A/data/Containers/Data/Application/A3252D13-A6D7-4B9F-8563-A339446A1E43/Documents
null appDir

Flutter Doctor

[✓] Flutter (on Mac OS, channel master)
    • Flutter at /Users/drewwarren/flutter
    • Framework revision 3203757958 (52 minutes ago), 2016-10-17 10:30:13
    • Engine revision d999f6c123
    • Tools Dart version 1.20.1

[x] Android toolchain - develop for Android devices
    x Android Studio / Android SDK not found. Download from https://developer.android.com/sdk/
      (or visit https://flutter.io/setup/#android-setup for detailed instructions).

[✓] iOS toolchain - develop for iOS devices (Xcode 7.3.1)
    • XCode at /Applications/Xcode.app/Contents/Developer
    • Xcode 7.3.1, Build version 7D1014

[✓] Atom - a lightweight development environment for Flutter
    • flutter plugin version 0.2.5
    • dartlang plugin version 0.6.39

[-] IntelliJ IDEA Community Edition (version 2016.2)
    • Dart plugin not installed; this adds Dart specific functionality.
    • Flutter plugin not installed; this adds Flutter specific functionality.
    • For information about managing plugins, see
      https://www.jetbrains.com/help/idea/2016.2/managing-plugins.html

[✓] Connected devices
    • iPhone 5s • 16BCCC3C-2F9C-401F-B2BF-97F1E3D2929A • ios (simulator)

Activity

  1. eseidelGoogle commented on Oct 17, 2016

    @eseidelGoogle
    Contributor

    @abarth is your man here.

  2. self-assigned this
    on Oct 17, 2016
  3. abarth commented on Oct 17, 2016

    @abarth
    Contributor

    I can repro.

  4. added a commit that references this issue on Sep 27, 2018
  5. github-actions commented on Sep 5, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  6. locked as resolved and limited conversation to collaborators on Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions