2022-08-31 10:09:36 +02:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2022-08-31 10:19:57 +02:00
|
|
|
import 'package:flutter_image_picker/src/services/image_picker_service.dart';
|
2022-08-31 10:09:36 +02:00
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
|
|
|
|
class ImagePickerUI {
|
2022-08-31 10:19:57 +02:00
|
|
|
final ImagePickerService _imagePickerService = ImagePickerService();
|
2022-08-31 10:09:36 +02:00
|
|
|
|
|
|
|
Future<Uint8List?> pickImageDialog(BuildContext context) async {
|
|
|
|
return await showDialog<Uint8List?>(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: true,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: const Text('Image Picker'),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: ListBody(
|
|
|
|
children: const <Widget>[
|
|
|
|
Text(
|
|
|
|
'Do you want to choose an existing image or make a new picture with the camera?'),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
ElevatedButton(
|
2022-08-31 10:19:57 +02:00
|
|
|
onPressed: () =>
|
|
|
|
_imagePickerService.pickImage(ImageSource.gallery, context),
|
2022-08-31 10:09:36 +02:00
|
|
|
child: const Text('Pick image from Gallery'),
|
|
|
|
),
|
|
|
|
ElevatedButton(
|
2022-08-31 10:19:57 +02:00
|
|
|
onPressed: () =>
|
|
|
|
_imagePickerService.pickImage(ImageSource.camera, context),
|
2022-08-31 10:09:36 +02:00
|
|
|
child: const Text('Make picture with Camera'),
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
child: const Text('Close Dialog'),
|
|
|
|
onPressed: () async {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|