mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-18 10:52:34 +01:00
Merge branch 'krille/remove-android-file-picker' into 'main'
remove: Android filepicker See merge request famedly/fluffychat!535
This commit is contained in:
commit
58c6009188
@ -4,54 +4,24 @@ import 'package:matrix/matrix.dart';
|
|||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
|
||||||
import 'package:file_picker_cross/file_picker_cross.dart';
|
import 'package:file_picker_cross/file_picker_cross.dart';
|
||||||
import 'package:filesystem_picker/filesystem_picker.dart';
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
||||||
import 'package:share/share.dart';
|
import 'package:share/share.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
|
||||||
extension MatrixFileExtension on MatrixFile {
|
extension MatrixFileExtension on MatrixFile {
|
||||||
void save(BuildContext context) async {
|
void save(BuildContext context) async {
|
||||||
final fileName = name.split('/').last;
|
final fileName = name.split('/').last;
|
||||||
if (PlatformInfos.isIOS) {
|
if (PlatformInfos.isMobile) {
|
||||||
final tmpDirectory = await getTemporaryDirectory();
|
final tmpDirectory = PlatformInfos.isAndroid
|
||||||
|
? Directory('/storage/emulated/0/Download')
|
||||||
|
: await getTemporaryDirectory();
|
||||||
final path = '${tmpDirectory.path}$fileName';
|
final path = '${tmpDirectory.path}$fileName';
|
||||||
await File(path).writeAsBytes(bytes);
|
await File(path).writeAsBytes(bytes);
|
||||||
await Share.shareFiles([path]);
|
await Share.shareFiles([path]);
|
||||||
return;
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
}
|
SnackBar(content: Text(L10n.of(context).savedFileAs(path))),
|
||||||
if (PlatformInfos.isAndroid) {
|
|
||||||
if (!(await Permission.storage.request()).isGranted) return;
|
|
||||||
final path = await FilesystemPicker.open(
|
|
||||||
title: L10n.of(context).saveFile,
|
|
||||||
context: context,
|
|
||||||
rootDirectory: Directory('/sdcard/'),
|
|
||||||
fsType: FilesystemType.folder,
|
|
||||||
pickText: L10n.of(context).saveFileToFolder,
|
|
||||||
folderIconColor: Theme.of(context).primaryColor,
|
|
||||||
requestPermission: () async =>
|
|
||||||
await Permission.storage.request().isGranted,
|
|
||||||
);
|
);
|
||||||
if (path != null) {
|
return;
|
||||||
// determine a unique filename
|
|
||||||
// somefile-number.extension, e.g. helloworld-1.txt
|
|
||||||
var file = File('$path/$fileName');
|
|
||||||
var i = 0;
|
|
||||||
var extension = '';
|
|
||||||
if (fileName.contains('.')) {
|
|
||||||
extension = fileName.substring(fileName.lastIndexOf('.'));
|
|
||||||
}
|
|
||||||
final fileNameWithoutExtension =
|
|
||||||
fileName.substring(0, fileName.lastIndexOf('.'));
|
|
||||||
while (await file.exists()) {
|
|
||||||
i++;
|
|
||||||
file = File('$path/$fileNameWithoutExtension-$i$extension');
|
|
||||||
}
|
|
||||||
await file.writeAsBytes(bytes);
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
||||||
content:
|
|
||||||
Text(L10n.of(context).savedFileAs(file.path.split('/').last))));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
final file = FilePickerCross(bytes);
|
final file = FilePickerCross(bytes);
|
||||||
await file.exportToStorage(fileName: fileName);
|
await file.exportToStorage(fileName: fileName);
|
||||||
|
@ -309,13 +309,6 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.0.2"
|
version: "0.0.2"
|
||||||
filesystem_picker:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: filesystem_picker
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "2.0.0-nullsafety.0"
|
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -19,7 +19,6 @@ dependencies:
|
|||||||
#fcm_shared_isolate:
|
#fcm_shared_isolate:
|
||||||
# git: https://gitlab.com/famedly/libraries/fcm_shared_isolate.git
|
# git: https://gitlab.com/famedly/libraries/fcm_shared_isolate.git
|
||||||
file_picker_cross: ^4.5.0
|
file_picker_cross: ^4.5.0
|
||||||
filesystem_picker: 2.0.0-nullsafety.0 # Using pre release to be compatible with Flutter 2.5
|
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
# From this fix: https://github.com/g123k/flutter_app_badger/pull/47
|
# From this fix: https://github.com/g123k/flutter_app_badger/pull/47
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh -ve
|
#!/bin/sh -ve
|
||||||
|
git apply ./scripts/enable-android-google-services.patch
|
||||||
flutter format lib/ test/ --set-exit-if-changed
|
flutter format lib/ test/ --set-exit-if-changed
|
||||||
flutter analyze
|
flutter analyze
|
||||||
git apply ./scripts/enable-android-google-services.patch --check
|
|
||||||
|
@ -99,5 +99,5 @@ index 9e7f148c..ea2d90f9 100644
|
|||||||
+ fcm_shared_isolate:
|
+ fcm_shared_isolate:
|
||||||
+ git: https://gitlab.com/famedly/libraries/fcm_shared_isolate.git
|
+ git: https://gitlab.com/famedly/libraries/fcm_shared_isolate.git
|
||||||
file_picker_cross: ^4.5.0
|
file_picker_cross: ^4.5.0
|
||||||
filesystem_picker: 2.0.0-nullsafety.0 # Using pre release to be compatible with Flutter 2.5
|
|
||||||
flutter:
|
flutter:
|
||||||
|
sdk: flutter
|
||||||
|
Loading…
Reference in New Issue
Block a user