2022-08-31 10:19:57 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
|
|
|
|
class ImagePickerService {
|
|
|
|
final ImagePicker _imagePicker = ImagePicker();
|
|
|
|
|
2022-09-01 10:22:32 +02:00
|
|
|
/// [pickImage] is the function that picks the image and returns it when the Image Picker Dialog gets closed.
|
|
|
|
/// The function requires [source], an [ImageSource] that's the method of how the image needs to be picked, for example gallery or camera.
|
|
|
|
/// It also requires [context], the [BuildContext] which is needed to be able to return the image when the Image Picker Dialog gets closed.
|
2022-08-31 10:19:57 +02:00
|
|
|
void pickImage(ImageSource source, BuildContext context) async {
|
|
|
|
var image =
|
|
|
|
await (await _imagePicker.pickImage(source: source))?.readAsBytes();
|
|
|
|
Navigator.of(context).pop(image);
|
|
|
|
}
|
|
|
|
}
|