Replaced the alert dialog with modal bottom sheet

also replaced the buttons with icons
This commit is contained in:
commitimpush 2022-08-31 11:45:12 +02:00
parent 87706a49ba
commit 80f959b5df
3 changed files with 45 additions and 34 deletions

View file

@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker_ios-0.8.5+6\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_plugin_android_lifecycle-2.0.7\\\\","native_build":true,"dependencies":[]},{"name":"image_picker_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker_android-0.8.5+2\\\\","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"image_picker_for_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker_for_web-2.1.8\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["image_picker_android","image_picker_for_web","image_picker_ios"]},{"name":"image_picker_android","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"image_picker_ios","dependencies":[]}],"date_created":"2022-08-30 16:05:56.456110","version":"3.0.5"} {"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker_ios-0.8.5+6\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_plugin_android_lifecycle-2.0.7\\\\","native_build":true,"dependencies":[]},{"name":"image_picker_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker_android-0.8.5+2\\\\","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"image_picker_for_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker_for_web-2.1.8\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["image_picker_android","image_picker_for_web","image_picker_ios"]},{"name":"image_picker_android","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"image_picker_ios","dependencies":[]}],"date_created":"2022-08-31 11:35:04.576524","version":"3.0.5"}

View file

@ -37,6 +37,7 @@ class ImagePickerExampleHomePage extends StatefulWidget {
class _ImagePickerExampleHomePageState class _ImagePickerExampleHomePageState
extends State<ImagePickerExampleHomePage> { extends State<ImagePickerExampleHomePage> {
Uint8List? image; Uint8List? image;
ImagePicker imagePicker = ImagePicker();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -61,7 +62,7 @@ class _ImagePickerExampleHomePageState
'Pick or make an Image/Photo!', 'Pick or make an Image/Photo!',
), ),
ElevatedButton( ElevatedButton(
onPressed: onPressed, child: const Text('Pick Image')) onPressed: pickImage, child: const Text('Pick Image'))
], ],
), ),
), ),
@ -69,8 +70,7 @@ class _ImagePickerExampleHomePageState
); );
} }
void onPressed() async { void pickImage() async {
ImagePicker imagePicker = ImagePicker();
Uint8List? imageInBytes = await imagePicker.showPickImageDialog(context); Uint8List? imageInBytes = await imagePicker.showPickImageDialog(context);
if (imageInBytes != null) { if (imageInBytes != null) {
setState(() { setState(() {

View file

@ -6,41 +6,52 @@ import 'package:image_picker/image_picker.dart';
class ImagePickerUI { class ImagePickerUI {
final ImagePickerService _imagePickerService = ImagePickerService(); final ImagePickerService _imagePickerService = ImagePickerService();
final double iconSize = 125;
Future<Uint8List?> pickImageDialog(BuildContext context) async { Future<Uint8List?> pickImageDialog(BuildContext context) async {
return await showDialog<Uint8List?>( return await showModalBottomSheet<Uint8List?>(
context: context, context: context,
barrierDismissible: true,
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( return Row(mainAxisAlignment: MainAxisAlignment.center, children: [
title: const Text('Image Picker'), Column(
content: SingleChildScrollView( mainAxisSize: MainAxisSize.min,
child: ListBody( children: <Widget>[
children: const <Widget>[ IconButton(
Text( icon: const Icon(Icons.image),
'Do you want to choose an existing image or make a new picture with the camera?'), tooltip: 'Choose Image From Gallery',
], iconSize: iconSize,
), onPressed: () =>
_imagePickerService.pickImage(ImageSource.gallery, context),
),
const Text("Select file"),
],
), ),
actions: <Widget>[
ElevatedButton( Column(
onPressed: () => mainAxisSize: MainAxisSize.min,
_imagePickerService.pickImage(ImageSource.gallery, context), children: <Widget>[
child: const Text('Pick image from Gallery'), IconButton(
), icon: const Icon(Icons.camera_alt_rounded),
ElevatedButton( tooltip: 'Make Image With Camera',
onPressed: () => iconSize: iconSize,
_imagePickerService.pickImage(ImageSource.camera, context), onPressed: () =>
child: const Text('Make picture with Camera'), _imagePickerService.pickImage(ImageSource.camera, context),
), ),
TextButton( const Text("Take a picture"),
child: const Text('Close Dialog'), ],
onPressed: () async { ),
Navigator.of(context).pop(); // ElevatedButton(
}, // onPressed: () =>
), // _imagePickerService.pickImage(ImageSource.gallery, context),
], // child: const Text('Gallery'),
); // ),
// const SizedBox(width: 10),
// ElevatedButton(
// onPressed: () =>
// _imagePickerService.pickImage(ImageSource.camera, context),
// child: const Text('Camera'),
// ),
]);
}, },
); );
} }