fix: android invalid download location Download not starting or not explaining error #720

This commit is contained in:
Kingkor Roy Tirtho 2023-10-29 19:02:39 +06:00
parent 433ae3d0c7
commit d056dbf9ee
3 changed files with 22 additions and 8 deletions

View File

@ -1,5 +1,6 @@
import 'package:auto_size_text/auto_size_text.dart'; import 'package:auto_size_text/auto_size_text.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:file_picker/file_picker.dart';
import 'package:file_selector/file_selector.dart'; import 'package:file_selector/file_selector.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -47,15 +48,19 @@ class SettingsPage extends HookConsumerWidget {
}, []); }, []);
final pickDownloadLocation = useCallback(() async { final pickDownloadLocation = useCallback(() async {
if (DesktopTools.platform.isMobile) {
final dirStr = await FilePicker.platform.getDirectoryPath(
initialDirectory: preferences.downloadLocation,
);
if (dirStr == null) return;
preferences.setDownloadLocation(dirStr);
} else {
String? dirStr = await getDirectoryPath( String? dirStr = await getDirectoryPath(
initialDirectory: preferences.downloadLocation, initialDirectory: preferences.downloadLocation,
); );
if (dirStr == null) return; if (dirStr == null) return;
if (DesktopTools.platform.isAndroid && dirStr.startsWith("content://")) {
dirStr =
"/storage/emulated/0/${Uri.decodeFull(dirStr).split("primary:").last}";
}
preferences.setDownloadLocation(dirStr); preferences.setDownloadLocation(dirStr);
}
}, [preferences.downloadLocation]); }, [preferences.downloadLocation]);
return SafeArea( return SafeArea(

View File

@ -513,6 +513,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "6.1.4" version: "6.1.4"
file_picker:
dependency: "direct main"
description:
name: file_picker
sha256: "903dd4ba13eae7cef64acc480e91bf54c3ddd23b5b90b639c170f3911e489620"
url: "https://pub.dev"
source: hosted
version: "6.0.0"
file_selector: file_selector:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -114,6 +114,7 @@ dependencies:
youtube_explode_dart: ^2.0.1 youtube_explode_dart: ^2.0.1
simple_icons: ^7.10.0 simple_icons: ^7.10.0
audio_service_mpris: ^0.1.0 audio_service_mpris: ^0.1.0
file_picker: ^6.0.0
dev_dependencies: dev_dependencies:
build_runner: ^2.3.2 build_runner: ^2.3.2