mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-20 02:59:26 +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:flutter/material.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:filesystem_picker/filesystem_picker.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:share/share.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
extension MatrixFileExtension on MatrixFile {
|
||||
void save(BuildContext context) async {
|
||||
final fileName = name.split('/').last;
|
||||
if (PlatformInfos.isIOS) {
|
||||
final tmpDirectory = await getTemporaryDirectory();
|
||||
if (PlatformInfos.isMobile) {
|
||||
final tmpDirectory = PlatformInfos.isAndroid
|
||||
? Directory('/storage/emulated/0/Download')
|
||||
: await getTemporaryDirectory();
|
||||
final path = '${tmpDirectory.path}$fileName';
|
||||
await File(path).writeAsBytes(bytes);
|
||||
await Share.shareFiles([path]);
|
||||
return;
|
||||
}
|
||||
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,
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context).savedFileAs(path))),
|
||||
);
|
||||
if (path != null) {
|
||||
// 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))));
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
final file = FilePickerCross(bytes);
|
||||
await file.exportToStorage(fileName: fileName);
|
||||
|
@ -309,13 +309,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
@ -19,7 +19,6 @@ dependencies:
|
||||
#fcm_shared_isolate:
|
||||
# git: https://gitlab.com/famedly/libraries/fcm_shared_isolate.git
|
||||
file_picker_cross: ^4.5.0
|
||||
filesystem_picker: 2.0.0-nullsafety.0 # Using pre release to be compatible with Flutter 2.5
|
||||
flutter:
|
||||
sdk: flutter
|
||||
# From this fix: https://github.com/g123k/flutter_app_badger/pull/47
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/bin/sh -ve
|
||||
git apply ./scripts/enable-android-google-services.patch
|
||||
flutter format lib/ test/ --set-exit-if-changed
|
||||
flutter analyze
|
||||
git apply ./scripts/enable-android-google-services.patch --check
|
||||
|
@ -99,5 +99,5 @@ index 9e7f148c..ea2d90f9 100644
|
||||
+ fcm_shared_isolate:
|
||||
+ git: https://gitlab.com/famedly/libraries/fcm_shared_isolate.git
|
||||
file_picker_cross: ^4.5.0
|
||||
filesystem_picker: 2.0.0-nullsafety.0 # Using pre release to be compatible with Flutter 2.5
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
Loading…
Reference in New Issue
Block a user