Browse Source

Merge pull request #816 from fritzlimo/main

refactor(neon): unify file dialog capabilities
pull/928/head
Kate 1 year ago committed by GitHub
parent
commit
cd59a9b549
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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 @override
bool get canUseSharing => true; bool get canUseSharing => true;
@override
bool get shouldUseFileDialog => true;
@override @override
Future<String> get userAccessibleAppDataPath async { Future<String> get userAccessibleAppDataPath async {
if (!await Permission.storage.request().isGranted) { if (!await Permission.storage.request().isGranted) {

3
packages/neon/neon/lib/src/platform/linux.dart

@ -31,6 +31,9 @@ class LinuxNeonPlatform implements NeonPlatform {
@override @override
bool get canUseSharing => false; bool get canUseSharing => false;
@override
bool get shouldUseFileDialog => false;
@override @override
String get userAccessibleAppDataPath => p.join(Platform.environment['HOME']!, 'Neon'); 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; 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<String> get userAccessibleAppDataPath;
FutureOr<void> init(); 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:file_picker/file_picker.dart';
import 'package:flutter_file_dialog/flutter_file_dialog.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 { 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 // TODO: https://github.com/nextcloud/neon/issues/8
return FlutterFileDialog.saveFile( return FlutterFileDialog.saveFile(
params: SaveFileDialogParams( params: SaveFileDialogParams(

Loading…
Cancel
Save