refactor: Remove workaround for download files
This commit is contained in:
parent
549b7bdd4b
commit
8589a17eb3
2 changed files with 11 additions and 38 deletions
|
|
@ -1,46 +1,26 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/utils/size_string.dart';
|
||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||
|
||||
extension MatrixFileExtension on MatrixFile {
|
||||
void save(BuildContext context) async {
|
||||
if (PlatformInfos.isWeb) {
|
||||
_webDownload();
|
||||
return;
|
||||
}
|
||||
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
final l10n = L10n.of(context);
|
||||
final downloadPath = await FilePicker.platform.saveFile(
|
||||
dialogTitle: L10n.of(context).saveFile,
|
||||
dialogTitle: l10n.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(
|
||||
content: Text(
|
||||
L10n.of(context).fileHasBeenSavedAt(downloadPath),
|
||||
),
|
||||
),
|
||||
scaffoldMessenger.showSnackBar(
|
||||
SnackBar(content: Text(l10n.fileHasBeenSavedAt(downloadPath))),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -51,19 +31,6 @@ extension MatrixFileExtension on MatrixFile {
|
|||
return FileType.any;
|
||||
}
|
||||
|
||||
void _webDownload() {
|
||||
html.AnchorElement(
|
||||
href: html.Url.createObjectUrlFromBlob(
|
||||
html.Blob(
|
||||
[bytes],
|
||||
mimeType,
|
||||
),
|
||||
),
|
||||
)
|
||||
..download = name
|
||||
..click();
|
||||
}
|
||||
|
||||
void share(BuildContext context) async {
|
||||
// Workaround for iPad from
|
||||
// https://github.com/fluttercommunity/plus_plugins/tree/main/packages/share_plus/share_plus#ipad
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ PODS:
|
|||
- FlutterMacOS
|
||||
- desktop_drop (0.0.1):
|
||||
- FlutterMacOS
|
||||
- desktop_webview_window (0.0.1):
|
||||
- FlutterMacOS
|
||||
- device_info_plus (0.0.1):
|
||||
- FlutterMacOS
|
||||
- dynamic_color (0.0.2):
|
||||
|
|
@ -79,6 +81,7 @@ DEPENDENCIES:
|
|||
- app_links (from `Flutter/ephemeral/.symlinks/plugins/app_links/macos`)
|
||||
- audio_session (from `Flutter/ephemeral/.symlinks/plugins/audio_session/macos`)
|
||||
- desktop_drop (from `Flutter/ephemeral/.symlinks/plugins/desktop_drop/macos`)
|
||||
- desktop_webview_window (from `Flutter/ephemeral/.symlinks/plugins/desktop_webview_window/macos`)
|
||||
- device_info_plus (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos`)
|
||||
- dynamic_color (from `Flutter/ephemeral/.symlinks/plugins/dynamic_color/macos`)
|
||||
- emoji_picker_flutter (from `Flutter/ephemeral/.symlinks/plugins/emoji_picker_flutter/macos`)
|
||||
|
|
@ -120,6 +123,8 @@ EXTERNAL SOURCES:
|
|||
:path: Flutter/ephemeral/.symlinks/plugins/audio_session/macos
|
||||
desktop_drop:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/desktop_drop/macos
|
||||
desktop_webview_window:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/desktop_webview_window/macos
|
||||
device_info_plus:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos
|
||||
dynamic_color:
|
||||
|
|
@ -181,6 +186,7 @@ SPEC CHECKSUMS:
|
|||
app_links: 05a6ec2341985eb05e9f97dc63f5837c39895c3f
|
||||
audio_session: eaca2512cf2b39212d724f35d11f46180ad3a33e
|
||||
desktop_drop: 10a3e6a7fa9dbe350541f2574092fecfa345a07b
|
||||
desktop_webview_window: 7e37af677d6d19294cb433d9b1d878ef78dffa4d
|
||||
device_info_plus: 4fb280989f669696856f8b129e4a5e3cd6c48f76
|
||||
dynamic_color: cb7c2a300ee67ed3bd96c3e852df3af0300bf610
|
||||
emoji_picker_flutter: 51ca408e289d84d1e460016b2a28721ec754fcf7
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue