Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(neon): unify file dialog capabilities #816

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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