Skip to content

Commit

Permalink
saving file path if file found
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibautLEAUX committed Mar 28, 2023
1 parent b9d16de commit fda3328
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
40 changes: 3 additions & 37 deletions lib/ModelFilePath.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,6 @@ import 'package:shared_preferences/shared_preferences.dart';

class ModelFilePath {

// static Future<Directory?> getDownloadPath() async {
// Directory? directory;
// try {
// //ask for permission
// if (Platform.isAndroid) {
// await Permission.storage.request();
// var status = await Permission.storage.request();
// if (!status.isGranted) {
// print("Permission denied : $status");
// return null;
// // We didn't ask for permission yet or the permission has been denied before but not permanently.
// }
// }
// if (Platform.isIOS) {
// directory = await getApplicationDocumentsDirectory();
// var newFolder = Directory('${directory.path}/Download');
// if (newFolder.existsSync() == false) {
// newFolder.createSync();
// }
// directory = newFolder;
// } else {
// directory = Directory('/storage/emulated/0/Download');
// // Put file in global download folder, if for an unknown reason it didn't exist, we fallback
// // ignore: avoid_slow_async_io
// if (!await directory.exists()) {
// directory = await getExternalStorageDirectory();
// }
// }
// } catch (err, stack) {
// print("Cannot get download folder path");
// }
// return directory;
// }



static Future <String?>getFilePath() async {

var prefs = await SharedPreferences.getInstance();
Expand All @@ -52,10 +16,12 @@ class ModelFilePath {
}

FilePickerResult? result = await FilePicker.platform.pickFiles(
withReadStream: true,
type: FileType.custom,
allowedExtensions: ['bin'],
);
if (result != null) {
if (result?.files.single.path != null) {
prefs.setString('path', result!.files.single.path!);
return result.files.single.path;
} else {
return null;
Expand Down
32 changes: 32 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.5"
device_info_plus:
dependency: "direct main"
description:
name: device_info_plus
sha256: "1d6e5a61674ba3a68fb048a7c7b4ff4bebfed8d7379dbe8f2b718231be9a7c95"
url: "https://pub.dev"
source: hosted
version: "8.1.0"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64
url: "https://pub.dev"
source: hosted
version: "7.0.0"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -129,6 +145,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.1.4"
file_picker:
dependency: "direct main"
description:
name: file_picker
sha256: d8e9ca7e5d1983365c277f12c21b4362df6cf659c99af146ad4d04eb33033013
url: "https://pub.dev"
source: hosted
version: "5.2.6"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -150,6 +174,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: c224ac897bed083dabf11f238dd11a239809b446740be0c2044608c50029ffdf
url: "https://pub.dev"
source: hosted
version: "2.0.9"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down

0 comments on commit fda3328

Please sign in to comment.