Browse Source

refactor(neon): unify file dialog capabilities

Signed-off-by: Christian Badelt <cbadelt@cb.dedyn.io>
Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/816/head
Christian Badelt 1 year ago committed by Nikolas Rimikis
parent
commit
41f42a46fe
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 3
      packages/neon/neon/lib/src/platform/android.dart
  2. 3
      packages/neon/neon/lib/src/platform/linux.dart
  3. 5
      packages/neon/neon/lib/src/platform/platform.dart
  4. 3
      packages/neon/neon/lib/src/utils/save_file.dart

3
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<String> get userAccessibleAppDataPath async {
if (!await Permission.storage.request().isGranted) {

3
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');

5
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<String> get userAccessibleAppDataPath;
FutureOr<void> init();

3
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<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(

Loading…
Cancel
Save