mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-17 06:20:44 +01:00
refactor: Use FilePickerCross for all downloading
This commit is contained in:
parent
10798ac7ff
commit
bebc3c7a22
@ -1,36 +1,11 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:file_picker_cross/file_picker_cross.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:share/share.dart';
|
||||
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
|
||||
extension MatrixFileExtension on MatrixFile {
|
||||
void save(BuildContext context) async {
|
||||
final fileName = name.split('/').last;
|
||||
if (PlatformInfos.isMobile) {
|
||||
final tmpDirectory = PlatformInfos.isAndroid
|
||||
? (await getExternalStorageDirectories(
|
||||
type: StorageDirectory.downloads))!
|
||||
.first
|
||||
: await getTemporaryDirectory();
|
||||
final path = '${tmpDirectory.path}$fileName';
|
||||
await File(path).writeAsBytes(bytes);
|
||||
await Share.shareFiles([path]);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context)!.savedFileAs(path))),
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
final file = FilePickerCross(bytes);
|
||||
await file.exportToStorage(fileName: fileName);
|
||||
}
|
||||
}
|
||||
void save(BuildContext context) =>
|
||||
FilePickerCross(bytes).exportToStorage(fileName: name.split('/').last);
|
||||
|
||||
MatrixFile get detectFileType {
|
||||
if (msgType == MessageTypes.Image) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user