mirror of
https://github.com/Iconica-Development/flutter_image_picker.git
synced 2025-05-18 11:43:44 +02:00
code improvements
This commit is contained in:
parent
e9f0aaf4c2
commit
560d8c3e2e
2 changed files with 33 additions and 41 deletions
|
@ -73,15 +73,17 @@ class _ImagePickerExampleHomePageState
|
|||
|
||||
void pickImage() async {
|
||||
Uint8List? imageInBytes = await imagePicker.showPickImageDialog(context);
|
||||
if (imageInBytes != null && !listEquals(image, imageInBytes)) {
|
||||
setState(() {
|
||||
image = imageInBytes;
|
||||
});
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Selected image is already being displayed!')),
|
||||
);
|
||||
if (imageInBytes != null) {
|
||||
if (!listEquals(image, imageInBytes)) {
|
||||
setState(() {
|
||||
image = imageInBytes;
|
||||
});
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Selected image is already being displayed!')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,38 +23,10 @@ class ImagePickerUI {
|
|||
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"),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
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"),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
generateColumn(
|
||||
context, Icons.image, ImageSource.gallery, "Select File"),
|
||||
generateColumn(context, Icons.camera_alt_rounded,
|
||||
ImageSource.camera, "Take a picture"),
|
||||
],
|
||||
),
|
||||
ElevatedButton(
|
||||
|
@ -64,4 +36,22 @@ class ImagePickerUI {
|
|||
},
|
||||
);
|
||||
}
|
||||
|
||||
Column generateColumn(BuildContext context, IconData icon,
|
||||
ImageSource imageSource, String bottomText) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(icon),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => _imagePickerService.pickImage(imageSource, context),
|
||||
),
|
||||
Text(bottomText),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue