|
|
@ -3,7 +3,6 @@ import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:file_picker/file_picker.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:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
@ -15,10 +14,6 @@ import 'package:fluffychat/utils/size_string.dart';
|
|
|
|
|
|
|
|
|
|
|
|
extension MatrixFileExtension on MatrixFile {
|
|
|
|
extension MatrixFileExtension on MatrixFile {
|
|
|
|
void save(BuildContext context) async {
|
|
|
|
void save(BuildContext context) async {
|
|
|
|
if (PlatformInfos.isIOS || PlatformInfos.isAndroid) {
|
|
|
|
|
|
|
|
_mobileDownload(context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (PlatformInfos.isWeb) {
|
|
|
|
if (PlatformInfos.isWeb) {
|
|
|
|
_webDownload();
|
|
|
|
_webDownload();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -28,14 +23,17 @@ extension MatrixFileExtension on MatrixFile {
|
|
|
|
dialogTitle: L10n.of(context)!.saveFile,
|
|
|
|
dialogTitle: L10n.of(context)!.saveFile,
|
|
|
|
fileName: name,
|
|
|
|
fileName: name,
|
|
|
|
type: filePickerFileType,
|
|
|
|
type: filePickerFileType,
|
|
|
|
|
|
|
|
bytes: bytes,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (downloadPath == null) return;
|
|
|
|
if (downloadPath == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (PlatformInfos.isDesktop) {
|
|
|
|
final result = await showFutureLoadingDialog(
|
|
|
|
final result = await showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
context: context,
|
|
|
|
future: () => File(downloadPath).writeAsBytes(bytes),
|
|
|
|
future: () => File(downloadPath).writeAsBytes(bytes),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (result.error != null) return;
|
|
|
|
if (result.error != null) return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
SnackBar(
|
|
|
@ -53,25 +51,6 @@ extension MatrixFileExtension on MatrixFile {
|
|
|
|
return FileType.any;
|
|
|
|
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() {
|
|
|
|
void _webDownload() {
|
|
|
|
html.AnchorElement(
|
|
|
|
html.AnchorElement(
|
|
|
|
href: html.Url.createObjectUrlFromBlob(
|
|
|
|
href: html.Url.createObjectUrlFromBlob(
|
|
|
|