From 41f42a46fecb6ac000291dcfce65fd13557ad0d2 Mon Sep 17 00:00:00 2001 From: Christian Badelt Date: Tue, 19 Sep 2023 23:32:56 +0200 Subject: [PATCH] refactor(neon): unify file dialog capabilities Signed-off-by: Christian Badelt Signed-off-by: Nikolas Rimikis --- packages/neon/neon/lib/src/platform/android.dart | 3 +++ packages/neon/neon/lib/src/platform/linux.dart | 3 +++ packages/neon/neon/lib/src/platform/platform.dart | 5 +++++ packages/neon/neon/lib/src/utils/save_file.dart | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/neon/neon/lib/src/platform/android.dart b/packages/neon/neon/lib/src/platform/android.dart index d4d905c5..9dceed83 100644 --- a/packages/neon/neon/lib/src/platform/android.dart +++ b/packages/neon/neon/lib/src/platform/android.dart @@ -31,6 +31,9 @@ class AndroidNeonPlatform implements NeonPlatform { @override bool get canUseSharing => true; + @override + bool get shouldUseFileDialog => true; + @override Future get userAccessibleAppDataPath async { if (!await Permission.storage.request().isGranted) { diff --git a/packages/neon/neon/lib/src/platform/linux.dart b/packages/neon/neon/lib/src/platform/linux.dart index 144f0072..4c3f5b2c 100644 --- a/packages/neon/neon/lib/src/platform/linux.dart +++ b/packages/neon/neon/lib/src/platform/linux.dart @@ -31,6 +31,9 @@ class LinuxNeonPlatform implements NeonPlatform { @override bool get canUseSharing => false; + @override + bool get shouldUseFileDialog => false; + @override String get userAccessibleAppDataPath => p.join(Platform.environment['HOME']!, 'Neon'); diff --git a/packages/neon/neon/lib/src/platform/platform.dart b/packages/neon/neon/lib/src/platform/platform.dart index 283be64f..6393ea2a 100644 --- a/packages/neon/neon/lib/src/platform/platform.dart +++ b/packages/neon/neon/lib/src/platform/platform.dart @@ -59,6 +59,11 @@ abstract interface class NeonPlatform { abstract final bool canUseSharing; + /// Whether this platform should use file dialog. + /// + /// This is needed to compensate lacking support of `https://pub.dev/packages/file_picker`. + abstract final bool shouldUseFileDialog; + FutureOr get userAccessibleAppDataPath; FutureOr init(); diff --git a/packages/neon/neon/lib/src/utils/save_file.dart b/packages/neon/neon/lib/src/utils/save_file.dart index d8cab3c8..36b27c83 100644 --- a/packages/neon/neon/lib/src/utils/save_file.dart +++ b/packages/neon/neon/lib/src/utils/save_file.dart @@ -3,9 +3,10 @@ import 'dart:typed_data'; import 'package:file_picker/file_picker.dart'; import 'package:flutter_file_dialog/flutter_file_dialog.dart'; +import 'package:neon/src/platform/platform.dart'; Future saveFileWithPickDialog(final String fileName, final Uint8List data) async { - if (Platform.isAndroid || Platform.isIOS) { + if (NeonPlatform.instance.shouldUseFileDialog) { // TODO: https://github.com/nextcloud/neon/issues/8 return FlutterFileDialog.saveFile( params: SaveFileDialogParams(