mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-23 18:44:10 +01:00
fix: Download files on iOS
This commit is contained in:
parent
4c2e690125
commit
a8201c4358
@ -3,17 +3,25 @@ import 'dart:io';
|
|||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:file_picker_cross/file_picker_cross.dart';
|
import 'package:file_picker_cross/file_picker_cross.dart';
|
||||||
import 'package:filesystem_picker/filesystem_picker.dart';
|
import 'package:filesystem_picker/filesystem_picker.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:share/share.dart';
|
||||||
|
|
||||||
extension MatrixFileExtension on MatrixFile {
|
extension MatrixFileExtension on MatrixFile {
|
||||||
void save(BuildContext context) async {
|
void save(BuildContext context) async {
|
||||||
if (PlatformInfos.isMobile &&
|
|
||||||
!(await Permission.storage.request()).isGranted) return;
|
|
||||||
final fileName = name.split('/').last;
|
final fileName = name.split('/').last;
|
||||||
|
if (PlatformInfos.isIOS) {
|
||||||
|
final tmpDirectory = await getTemporaryDirectory();
|
||||||
|
final path = '${tmpDirectory.path}$fileName';
|
||||||
|
await File(path).writeAsBytes(bytes);
|
||||||
|
await Share.shareFiles([path]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (PlatformInfos.isAndroid) {
|
if (PlatformInfos.isAndroid) {
|
||||||
|
if (!(await Permission.storage.request()).isGranted) return;
|
||||||
final path = await FilesystemPicker.open(
|
final path = await FilesystemPicker.open(
|
||||||
title: L10n.of(context).saveFile,
|
title: L10n.of(context).saveFile,
|
||||||
context: context,
|
context: context,
|
||||||
|
Loading…
Reference in New Issue
Block a user