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]>
Signed-off-by: Nikolas Rimikis <[email protected]>
  • Loading branch information
fritzlimo authored and Leptopoda committed Oct 4, 2023
1 parent 367bb8c commit 41f42a4
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 @@ -31,6 +31,9 @@ class AndroidNeonPlatform implements NeonPlatform {
@override
bool get canUseSharing => true;

@override
bool get shouldUseFileDialog => 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 @@ -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');

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 @@ -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<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.shouldUseFileDialog) {
// TODO: https://github.com/nextcloud/neon/issues/8
return FlutterFileDialog.saveFile(
params: SaveFileDialogParams(
Expand Down

0 comments on commit 41f42a4

Please sign in to comment.