fix: Android Download

This commit is contained in:
Christian Pauly 2020-10-28 08:05:10 +01:00
commit 08a3b199e7
5 changed files with 37 additions and 7 deletions

View file

@ -1,11 +1,14 @@
import 'dart:io';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/foundation.dart';
import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart';
import 'package:universal_html/prefer_universal/html.dart' as html;
import 'package:mime_type/mime_type.dart';
import 'package:downloads_path_provider_28/downloads_path_provider_28.dart';
import 'package:permission_handler/permission_handler.dart';
extension MatrixFileExtension on MatrixFile {
void open() async {
@ -24,9 +27,12 @@ extension MatrixFileExtension on MatrixFile {
element.click();
element.remove();
} else {
final downloadsDir = Platform.isAndroid
? (await getExternalStorageDirectory())
: (await getApplicationDocumentsDirectory());
if (!(await Permission.storage.request()).isGranted) return;
final downloadsDir = PlatformInfos.isDesktop
? (await getDownloadsDirectory())
: Platform.isAndroid
? (await DownloadsPathProvider.downloadsDirectory)
: (await getApplicationDocumentsDirectory());
final file = File(downloadsDir.path + '/' + name.split('/').last);
file.writeAsBytesSync(bytes);

View file

@ -11,5 +11,8 @@ abstract class PlatformInfos {
static bool get isBetaDesktop =>
!kIsWeb && (Platform.isWindows || Platform.isLinux);
static bool get isDesktop =>
!kIsWeb && (Platform.isLinux || Platform.isWindows || Platform.isMacOS);
static bool get usesTouchscreen => !isMobile;
}