pickFiles method
Future<void>
pickFiles(
- BuildContext context,
- FilePickerAction action,
- ScopeManager? scopeManager
override
Opens the platform file picker and stores selected files in the action scope.
Implementation
@override
Future<void> pickFiles(BuildContext context, FilePickerAction action,
ScopeManager? scopeManager) async {
final type = pickType(action);
FilePicker.platform
.pickFiles(
type: type,
allowedExtensions:
type == FileType.custom ? action.allowedExtensions : null,
allowMultiple: action.allowMultiple ?? false,
)
.then((result) {
if (result == null || result.files.isEmpty) {
if (action.onError != null) {
ScreenController().executeAction(context, action.onError!);
}
return;
}
final selectedFiles = result.files
.map((file) => FileExtension.fromPlatformFile(file))
.toList();
final fileData = FileData(files: selectedFiles);
if (scopeManager == null) return;
scopeManager.dataContext.addDataContextById(action.id, fileData);
scopeManager
.dispatch(ModelChangeEvent(SimpleBindingSource(action.id), fileData));
if (action.onComplete != null) {
ScreenController().executeAction(context, action.onComplete!);
}
});
}