From 8ce3cbe0c90fdb645dfad0283efc6fc5c8b95991 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 --- 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 253ec6bdc66..462f7c03986 100644 --- a/packages/neon/neon/lib/src/platform/android.dart +++ b/packages/neon/neon/lib/src/platform/android.dart @@ -28,6 +28,9 @@ class AndroidNeonPlatform implements NeonPlatform { @override bool get canUseWindowManager => false; + @override + bool get canUseFileDialog => 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 594124a4e15..e7aa0b27858 100644 --- a/packages/neon/neon/lib/src/platform/linux.dart +++ b/packages/neon/neon/lib/src/platform/linux.dart @@ -28,6 +28,9 @@ class LinuxNeonPlatform implements NeonPlatform { @override bool get canUsePushNotifications => false; + @override + bool get canUseFileDialog => 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 8c541890226..09b52eff0c7 100644 --- a/packages/neon/neon/lib/src/platform/platform.dart +++ b/packages/neon/neon/lib/src/platform/platform.dart @@ -53,6 +53,11 @@ abstract interface class NeonPlatform { abstract final bool canUsePushNotifications; + /// Whether this platform supports file dialog. + /// + /// The support depends on `https://pub.dev/packages/flutter_file_dialog`. + abstract final bool canUseFileDialog; + 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 d8cab3c8369..e03210a54b8 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.canUseFileDialog) { // TODO: https://github.com/nextcloud/neon/issues/8 return FlutterFileDialog.saveFile( params: SaveFileDialogParams(