mirror of
https://github.com/Iconica-Development/flutter_image_picker.git
synced 2025-05-18 11:43:44 +02:00
Replaced the alert dialog with modal bottom sheet
also replaced the buttons with icons
This commit is contained in:
parent
87706a49ba
commit
80f959b5df
3 changed files with 45 additions and 34 deletions
|
@ -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"}
|
|
@ -37,6 +37,7 @@ class ImagePickerExampleHomePage extends StatefulWidget {
|
|||
class _ImagePickerExampleHomePageState
|
||||
extends State<ImagePickerExampleHomePage> {
|
||||
Uint8List? image;
|
||||
ImagePicker imagePicker = ImagePicker();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -61,7 +62,7 @@ class _ImagePickerExampleHomePageState
|
|||
'Pick or make an Image/Photo!',
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: onPressed, child: const Text('Pick Image'))
|
||||
onPressed: pickImage, child: const Text('Pick Image'))
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -69,8 +70,7 @@ class _ImagePickerExampleHomePageState
|
|||
);
|
||||
}
|
||||
|
||||
void onPressed() async {
|
||||
ImagePicker imagePicker = ImagePicker();
|
||||
void pickImage() async {
|
||||
Uint8List? imageInBytes = await imagePicker.showPickImageDialog(context);
|
||||
if (imageInBytes != null) {
|
||||
setState(() {
|
||||
|
|
|
@ -6,41 +6,52 @@ import 'package:image_picker/image_picker.dart';
|
|||
|
||||
class ImagePickerUI {
|
||||
final ImagePickerService _imagePickerService = ImagePickerService();
|
||||
final double iconSize = 125;
|
||||
|
||||
Future<Uint8List?> pickImageDialog(BuildContext context) async {
|
||||
return await showDialog<Uint8List?>(
|
||||
return await showModalBottomSheet<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?'),
|
||||
],
|
||||
),
|
||||
return Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
IconButton(
|
||||
icon: const Icon(Icons.image),
|
||||
tooltip: 'Choose Image From Gallery',
|
||||
iconSize: iconSize,
|
||||
onPressed: () =>
|
||||
_imagePickerService.pickImage(ImageSource.gallery, context),
|
||||
),
|
||||
const Text("Select file"),
|
||||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
ElevatedButton(
|
||||
onPressed: () =>
|
||||
_imagePickerService.pickImage(ImageSource.gallery, context),
|
||||
child: const Text('Pick image from Gallery'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () =>
|
||||
_imagePickerService.pickImage(ImageSource.camera, context),
|
||||
child: const Text('Make picture with Camera'),
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Close Dialog'),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
IconButton(
|
||||
icon: const Icon(Icons.camera_alt_rounded),
|
||||
tooltip: 'Make Image With Camera',
|
||||
iconSize: iconSize,
|
||||
onPressed: () =>
|
||||
_imagePickerService.pickImage(ImageSource.camera, context),
|
||||
),
|
||||
const Text("Take a picture"),
|
||||
],
|
||||
),
|
||||
// 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'),
|
||||
// ),
|
||||
]);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue