I am creating a Flutter Desktop application for windows and I am trying to retrieve the application directory where the exe is located. I tried to use path_provider but can only get the Documents directory. Any help I would appreciate lots.
I am creating a Flutter Desktop application for windows and I am trying to retrieve the application directory where the exe is located. I tried to use path_provider but can only get the Documents directory. Any help I would appreciate lots.
Use Platform.resolvedExecutable
(of dart:io).
I have tested it in Flutter/Windows and it works.
Strangely, Platform.executable returns null instead. I tell strangely because its type is String not nullable. This unexpected null value can cause crash or errors that are difficult to detect (but in the end Flutter desktop is not in the stable channel).
String dir = Directory.current.path;
print(dir);
Directory.current.path (in the dart:io package) returns the current working directory of the project folder (when developing) or the executable directory when running from a release build.
Try is package: path_provider
- set this code in pubspec.yaml
dependencies:
path_provider: ^1.6.27 # get last Version From https://pub.dev/packages/path_provider/install
- Code
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path; //C:\Users\USER_NAME\AppData\Local\Temp
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path; //C:\Users\USER_NAME\Documents
//Warning: on debug mode this code get location project but in release mode will get your location app correctly
String dir = Directory.current.path; // PATH_APP