pickImage method

Future<void> pickImage(
  1. ImageSource source,
  2. AppLocalizations localizations
)

Picks an image from the specified source for classification.

Parameters:

  • source: The image source (camera or gallery)
  • localizations: Used for localized error messages

Updates the UI state and notifies listeners when complete. Picks an image from the specified source for classification.

Parameters:

  • source: The image source (camera or gallery)
  • localizations: Used for localized error messages

Updates the UI state and notifies listeners when complete.

Implementation

Future<void> pickImage(
  ImageSource source,
  AppLocalizations localizations,
) async {
  final picker = ImagePicker();
  try {
    _state = ClassificationState.initial;
    _result = null;
    _errorMessage = null;
    notifyListeners();
    final pickedFile = await picker.pickImage(source: source);
    if (pickedFile != null) {
      _imageFile = File(pickedFile.path);
      notifyListeners();
    }
  } catch (e) {
    _errorMessage = localizations.errorFailedToPickImage(e.toString());
    notifyListeners();
  }
}