Damandroid
Damandroid

Reputation: 984

Flutter path_provider plugin not working - (OS Error: No such file or directory, errno = 2)

Here is my simple code I am trying to execute:

    Directory docDirectory = await getApplicationDocumentsDirectory();
    String path = docDirectory.path;
    if (DEBUG) print ('Site_Status: Document path : '+path);
    File file = File('$docDirectory/${widget.site.name}/example.txt');
    file.writeAsString('123');//writeAsBytesSync(doc.save());

The error I am getting is:

    [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: FileSystemException: Cannot open file, path = '/Users/D/Library/Developer/CoreSimulator/Devices/03A681BC-846F-42A5-9489-4C596F6EC8F0/data/Containers/Data/Application/4AA8DB7A-CE63-45EB-8596-D4CEE6BC8926/Documents/Pinpad/example.txt' (OS Error: No such file or directory, errno = 2)
#0      _File.open.<anonymous closure> (dart:io/file_impl.dart:366:9)
#1      _rootRunUnary (dart:async/zone.dart:1192:38)
#2      _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#3      _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#4      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#5      Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#6      Future._completeWithValue (dart:async/future_impl.dart:526:5)
#7      Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:556:7)
#8      _rootRun (dart:async/zone.dart:1184:13)
#9      _CustomZone.run (dart:async/zone.dart:1077<…>

I am using path_provider plugin. I am getting this error on both IOS and Android as well.

Upvotes: 4

Views: 3525

Answers (2)

SinaMN75
SinaMN75

Reputation: 7679

in my case, the problem was about another library. file_picker when i removed this library problem solved, but turned out. there are. some other libraries that may cause this problem. like image_picker or. cached_network_image

hope flutter team figure this out and solve it.

Upvotes: 1

Sachin Bhankhar
Sachin Bhankhar

Reputation: 900

use path not docDirectory

  Directory docDirectory = await getApplicationDocumentsDirectory();
      final dir = Directory(docDirectory.path + "/dir");
      await dir.create().then((value) {
        File file = File('${value.path}/example.txt');
        file.writeAsString('123'); //writeAsBytesSync(doc.save());
      });

Hope this will help you.

Upvotes: 1

Related Questions