flutter_image_picker/lib/src/services/image_picker_service.dart

16 lines
767 B
Dart
Raw Normal View History

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.
void pickImage(ImageSource source, BuildContext context) async {
var image =
await (await _imagePicker.pickImage(source: source))?.readAsBytes();
Navigator.of(context).pop(image);
}
}