1

I am developing a flutter app, and that app needs to load and store the app data in a public area (to be able to be shared or otherwise copied by other means).

the app needs to run under linux and at least android, web would be nice too, but well....

i came across the FilePickerCross and begun implementing loading and saving, eg. loading with the following code:

IconButton(onPressed: ()
                    async {
                      FilePickerCross?  value = await FilePickerCross.importFromStorage(
                          type: FileTypeCross.any,       // Available: `any`, `audio`, `image`, `video`, `custom`. Note: not available using FDE
                          fileExtension: '.exam'     // Only if FileTypeCross.custom . May be any file extension like `dot`, `ppt,pptx,odp`
                      ).onError((error, _) {
                        String _exceptionData = error.toString() ;
                        print('---------------------- FilePicker error : $error ${error.runtimeType}');
                        print('REASON: ${_exceptionData}');
                        if (_exceptionData == 'read_external_storage_denied') {
                          print('Permission was denied');
                        } else if (_exceptionData == 'selection_canceled') {
                          print('User canceled operation');
                        }
                        print('----------------------');
                        throw Exception("filecros eror");
                      });;//.then(() => ref.read(examenProvider.notifier).fromJson(value.toString())
                      //print("retrieved $value of ${value.runtimeType}");
                      //String fileContent =value.toString();
                      String fileContent = String.fromCharCodes(value.toUint8List());
                      ref.read(examenProvider.notifier).fromJson(fileContent, ref.read(examineeProvider.notifier),fullProg: ref.watch(nodeProvider), settings: ref.read(nodeProvider.notifier).settings.loaded);
                      candidates = ref.watch(examineeProvider);
                    }, icon: Icon(Icons.file_upload))

that code runs nicely under linux, fires up a file section dialog and returns the file, what is not so nice with this library is that it saves the stuff as Uint8List, and if you let it decode it to string automaticly it fails if you really use utf chars.....

now when i run this under android, and in the docu is written that i don't have to do anything to let it run??? well.... that fails miserably:

---------------------- FilePicker error : type '_Exception' is not a subtype of type 'String' _TypeError
I/flutter (22870): REASON: type '_Exception' is not a subtype of type 'String'
I/flutter (22870): ----------------------
E/flutter (22870): [ERROR:flutter/runtime/dart_vm_initializer.cc(39)] Unhandled Exception: Exception: filecros eror
E/flutter (22870): #0      ExamConfigurator.build.<anonymous closure>.<anonymous closure> (package:examen_helper/exam_configurator.dart:132:25)
E/flutter (22870): #1      FutureExtensions.onError.<anonymous closure> (dart:async/future.dart:1012:24)
E/flutter (22870): #2      _RootZone.runBinary (dart:async/zone.dart:1690:54)
E/flutter (22870): #3      _FutureListener.handleError (dart:async/future_impl.dart:162:22)
E/flutter (22870): #4      Future._propagateToListeners.handleError (dart:async/future_impl.dart:778:47)
E/flutter (22870): #5      Future._propagateToListeners (dart:async/future_impl.dart:799:13)
E/flutter (22870): #6      Future._completeError (dart:async/future_impl.dart:574:5)
E/flutter (22870): #7      _completeOnAsyncError (dart:async-patch/async_patch.dart:287:13)
E/flutter (22870): #8      FilePickerCross.importFromStorage (package:file_picker_cross/file_picker_cross.dart)
E/flutter (22870): <asynchronous suspension>

so is this library supposed to take care of access rights? its annoying that the error doesn't tell what is going wrong.... i didn't tamper with the Android Manifest file, should i add there read and write rights to files? since i am using riverpod permission_handler looks complicated to use....

so any hint welcome

bboett
  • 123
  • 9

0 Answers0