pickImage method

Future<void> pickImage({
  1. String? key,
})

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.pickFile(
    type              : FileType.custom,
    allowedExtensions : AcceptedFormats.values.map((e) => e.name).toList(),
  )
  .then((file) async {
    // Proceed if user selected a file
    if(file != null){
        // Start loading indicator
        startLoading();
        // Create image data from selected platform file
        await _useCase
        .createDataFromPlatformFile(
          key     : _key,
          file    : file,
          maxSize : _maxSize,
        )
        .then(_setData)          // Update image data on success
        .onError(_setError)      // Handle errors
        .whenComplete(() => stopLoading() ); // Stop loading indicator
      }
  });
}