Skip to content

Commit

Permalink
refactor(neon): unify file dialog capabilities
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Badelt <[email protected]>
  • Loading branch information
fritzlimo committed Sep 19, 2023
1 parent 2614652 commit 8ce3cbe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/neon/neon/lib/src/platform/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class AndroidNeonPlatform implements NeonPlatform {
@override
bool get canUseWindowManager => false;

@override
bool get canUseFileDialog => true;

@override
Future<String> get userAccessibleAppDataPath async {
if (!await Permission.storage.request().isGranted) {
Expand Down
3 changes: 3 additions & 0 deletions packages/neon/neon/lib/src/platform/linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
5 changes: 5 additions & 0 deletions packages/neon/neon/lib/src/platform/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> get userAccessibleAppDataPath;

FutureOr<void> init();
Expand Down
3 changes: 2 additions & 1 deletion packages/neon/neon/lib/src/utils/save_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?> 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(
Expand Down

0 comments on commit 8ce3cbe

Please sign in to comment.