From f9f185ece97ca3e43d6ff2c2e7f513c7b84c5e50 Mon Sep 17 00:00:00 2001 From: Tanish2002 Date: Sun, 24 Mar 2024 20:11:44 +0530 Subject: [PATCH] fix: file picker on linux --- .../request_pane/request_form_data.dart | 5 +- lib/utils/file_utils.dart | 6 +- pubspec.lock | 80 ++++++++++++++++--- pubspec.yaml | 2 +- 4 files changed, 74 insertions(+), 19 deletions(-) diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart index a6bafd6e..582b19ed 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_form_data.dart @@ -132,10 +132,9 @@ class _FormDataBodyState extends ConsumerState { onPressed: () async { var pickedResult = await pickFile(); if (pickedResult != null && - pickedResult.files.isNotEmpty && - pickedResult.files.first.path != null) { + pickedResult.path.isNotEmpty) { formRows[idx] = formRows[idx].copyWith( - value: pickedResult.files.first.path!, + value: pickedResult.path, ); setState(() {}); _onFieldChange(selectedId!); diff --git a/lib/utils/file_utils.dart b/lib/utils/file_utils.dart index 58d69513..8f7c6a72 100644 --- a/lib/utils/file_utils.dart +++ b/lib/utils/file_utils.dart @@ -1,10 +1,10 @@ import 'dart:io'; import 'dart:typed_data'; +import 'package:file_selector/file_selector.dart'; import 'package:path/path.dart' as p; import 'package:mime_dart/mime_dart.dart'; import 'package:uuid/uuid.dart'; import 'package:path_provider/path_provider.dart'; -import 'package:file_picker/file_picker.dart'; const uuid = Uuid(); @@ -57,7 +57,7 @@ String getTempFileName() { return getNewUuid(); } -Future pickFile() async { - FilePickerResult? pickedResult = await FilePicker.platform.pickFiles(); +Future pickFile() async { + XFile? pickedResult = await openFile(); return pickedResult; } diff --git a/pubspec.lock b/pubspec.lock index a4e54dfb..3d7a7189 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -209,6 +209,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.7.2" + cross_file: + dependency: transitive + description: + name: cross_file + sha256: "55d7b444feb71301ef6b8838dbc1ae02e63dd48c8773f3810ff53bb1e2945b32" + url: "https://pub.dev" + source: hosted + version: "0.3.4+1" crypto: dependency: transitive description: @@ -289,14 +297,70 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.0" - file_picker: + file_selector: dependency: "direct main" description: - name: file_picker - sha256: caa6bc229eab3e32eb2f37b53a5f9d22a6981474afd210c512a7546c1e1a04f6 + name: file_selector + sha256: "5019692b593455127794d5718304ff1ae15447dea286cdda9f0db2a796a1b828" url: "https://pub.dev" source: hosted - version: "6.2.0" + version: "1.0.3" + file_selector_android: + dependency: transitive + description: + name: file_selector_android + sha256: "1cd66575f063b689e041aec836905ba7be18d76c9f0634d0d75daec825f67095" + url: "https://pub.dev" + source: hosted + version: "0.5.0+7" + file_selector_ios: + dependency: transitive + description: + name: file_selector_ios + sha256: b015154e6d9fddbc4d08916794df170b44531798c8dd709a026df162d07ad81d + url: "https://pub.dev" + source: hosted + version: "0.5.1+8" + file_selector_linux: + dependency: transitive + description: + name: file_selector_linux + sha256: "045d372bf19b02aeb69cacf8b4009555fb5f6f0b7ad8016e5f46dd1387ddd492" + url: "https://pub.dev" + source: hosted + version: "0.9.2+1" + file_selector_macos: + dependency: transitive + description: + name: file_selector_macos + sha256: b15c3da8bd4908b9918111fa486903f5808e388b8d1c559949f584725a6594d6 + url: "https://pub.dev" + source: hosted + version: "0.9.3+3" + file_selector_platform_interface: + dependency: transitive + description: + name: file_selector_platform_interface + sha256: a3994c26f10378a039faa11de174d7b78eb8f79e4dd0af2a451410c1a5c3f66b + url: "https://pub.dev" + source: hosted + version: "2.6.2" + file_selector_web: + dependency: transitive + description: + name: file_selector_web + sha256: "619e431b224711a3869e30dbd7d516f5f5a4f04b265013a50912f39e1abc88c8" + url: "https://pub.dev" + source: hosted + version: "0.9.4+1" + file_selector_windows: + dependency: transitive + description: + name: file_selector_windows + sha256: d3547240c20cabf205c7c7f01a50ecdbc413755814d6677f3cb366f04abcead0 + url: "https://pub.dev" + source: hosted + version: "0.9.3+1" fixnum: dependency: transitive description: @@ -382,14 +446,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.21" - flutter_plugin_android_lifecycle: - dependency: transitive - description: - name: flutter_plugin_android_lifecycle - sha256: b068ffc46f82a55844acfa4fdbb61fad72fa2aef0905548419d97f0f95c456da - url: "https://pub.dev" - source: hosted - version: "2.0.17" flutter_riverpod: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index b7c79bde..cfa20cb3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -49,13 +49,13 @@ dependencies: url: https://github.com/foss42/json_data_explorer.git ref: b7dde2f85dff4f482eed7eda4ef2a71344ef8b3a scrollable_positioned_list: ^0.3.8 - file_picker: ^6.2.0 flutter_svg: ^2.0.10+1 vector_graphics_compiler: ^1.1.9+1 code_builder: ^4.10.0 dart_style: ^2.3.6 json_text_field: ^1.1.0 csv: ^6.0.0 + file_selector: ^1.0.3 dependency_overrides: web: ^0.5.0