pickImage method
Opens file picker to select an image, then processes and stores it.
Implementation
Future<void> pickImage({final String? key}) async {
// Update key if provided
if(key != null) updateKey(key);
// Invoke file picker with custom allowed extensions
await FilePicker.platform.pickFiles(
type : FileType.custom,
allowedExtensions : AcceptedFormats.values.map((e) => e.name).toList(),
allowMultiple : false,
withData : !PlatformPort().requirePath(),
)
.then((pick) async {
// Proceed if user selected a file
if(pick != null){
if(pick.files.isNotEmpty) {
// Start loading indicator
startLoading();
// Create image data from selected platform file
await _useCase
.createDataFromPlatformFile(
key : _key,
file : pick.files.first,
maxSize : _maxSize,
)
.then(_setData) // Update image data on success
.onError(_setError) // Handle errors
.whenComplete(() => stopLoading() ); // Stop loading indicator
}
}
});
}