mirror of
https://github.com/krille-chan/fluffychat
synced 2024-10-05 13:12:44 +00:00
refactor: Download on android and iOS with file_picker
This commit is contained in:
parent
86df13d6d8
commit
a705a5b399
3 changed files with 16 additions and 46 deletions
|
@ -3,7 +3,6 @@ import 'dart:io';
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter_file_dialog/flutter_file_dialog.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
@ -15,10 +14,6 @@ import 'package:fluffychat/utils/size_string.dart';
|
|||
|
||||
extension MatrixFileExtension on MatrixFile {
|
||||
void save(BuildContext context) async {
|
||||
if (PlatformInfos.isIOS || PlatformInfos.isAndroid) {
|
||||
_mobileDownload(context);
|
||||
}
|
||||
|
||||
if (PlatformInfos.isWeb) {
|
||||
_webDownload();
|
||||
return;
|
||||
|
@ -28,14 +23,17 @@ extension MatrixFileExtension on MatrixFile {
|
|||
dialogTitle: L10n.of(context)!.saveFile,
|
||||
fileName: name,
|
||||
type: filePickerFileType,
|
||||
bytes: bytes,
|
||||
);
|
||||
if (downloadPath == null) return;
|
||||
|
||||
if (PlatformInfos.isDesktop) {
|
||||
final result = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => File(downloadPath).writeAsBytes(bytes),
|
||||
);
|
||||
if (result.error != null) return;
|
||||
}
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
|
@ -53,25 +51,6 @@ extension MatrixFileExtension on MatrixFile {
|
|||
return FileType.any;
|
||||
}
|
||||
|
||||
void _mobileDownload(BuildContext context) async {
|
||||
final downloadPath = await FlutterFileDialog.saveFile(
|
||||
params: SaveFileDialogParams(
|
||||
fileName: name,
|
||||
data: bytes,
|
||||
),
|
||||
);
|
||||
if (downloadPath != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
L10n.of(context)!.fileHasBeenSavedAt(downloadPath),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void _webDownload() {
|
||||
html.AnchorElement(
|
||||
href: html.Url.createObjectUrlFromBlob(
|
||||
|
|
20
pubspec.lock
20
pubspec.lock
|
@ -397,10 +397,10 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: file_picker
|
||||
sha256: "4e42aacde3b993c5947467ab640882c56947d9d27342a5b6f2895b23956954a6"
|
||||
sha256: b6283d7387310ad83bc4f3bc245b75d223a032ae6eba275afcd585de2b9a1476
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.1"
|
||||
version: "8.0.1"
|
||||
file_selector_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -459,14 +459,6 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_file_dialog:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_file_dialog
|
||||
sha256: "9344b8f07be6a1b6f9854b723fb0cf84a8094ba94761af1d213589d3cb087488"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
flutter_foreground_task:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -932,10 +924,10 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: image_picker
|
||||
sha256: "26222b01a0c9a2c8fe02fc90b8208bd3325da5ed1f4a2acabf75939031ac0bdd"
|
||||
sha256: fe9ee64ccb8d599a5dfb0e21cc6652232c610bcf667af4e79b9eb175cc30a7a5
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.7"
|
||||
version: "1.1.0"
|
||||
image_picker_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -980,10 +972,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: image_picker_platform_interface
|
||||
sha256: ed9b00e63977c93b0d2d2b343685bed9c324534ba5abafbb3dfbd6a780b1b514
|
||||
sha256: "9ec26d410ff46f483c5519c29c02ef0e02e13a543f882b152d4bfd2f06802f80"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.9.1"
|
||||
version: "2.10.0"
|
||||
image_picker_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -26,12 +26,11 @@ dependencies:
|
|||
emoji_proposal: ^0.0.1
|
||||
emojis: ^0.9.9
|
||||
#fcm_shared_isolate: ^0.1.0
|
||||
file_picker: ^6.1.1
|
||||
file_picker: ^8.0.1
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_app_badger: ^1.5.0
|
||||
flutter_cache_manager: ^3.3.1
|
||||
flutter_file_dialog: ^3.0.2
|
||||
flutter_foreground_task: ^6.1.3
|
||||
flutter_highlighter: ^0.1.1
|
||||
flutter_html: ^3.0.0-beta.2
|
||||
|
@ -59,7 +58,7 @@ dependencies:
|
|||
html: ^0.15.4
|
||||
http: ^1.2.0
|
||||
image: ^4.1.7
|
||||
image_picker: ^1.0.7
|
||||
image_picker: ^1.1.0
|
||||
intl: any
|
||||
just_audio: ^0.9.37
|
||||
keyboard_shortcuts: ^0.1.4
|
||||
|
|
Loading…
Reference in a new issue