mirror of
https://github.com/Iconica-Development/flutter_image_picker.git
synced 2025-05-18 19:53:45 +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 {
|
void pickImage() async {
|
||||||
Uint8List? imageInBytes = await imagePicker.showPickImageDialog(context);
|
Uint8List? imageInBytes = await imagePicker.showPickImageDialog(context);
|
||||||
if (imageInBytes != null && !listEquals(image, imageInBytes)) {
|
if (imageInBytes != null) {
|
||||||
setState(() {
|
if (!listEquals(image, imageInBytes)) {
|
||||||
image = imageInBytes;
|
setState(() {
|
||||||
});
|
image = imageInBytes;
|
||||||
} else {
|
});
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
} else {
|
||||||
const SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
content: Text('Selected image is already being displayed!')),
|
const SnackBar(
|
||||||
);
|
content: Text('Selected image is already being displayed!')),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,38 +23,10 @@ class ImagePickerUI {
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Column(
|
generateColumn(
|
||||||
mainAxisSize: MainAxisSize.min,
|
context, Icons.image, ImageSource.gallery, "Select File"),
|
||||||
children: <Widget>[
|
generateColumn(context, Icons.camera_alt_rounded,
|
||||||
IconButton(
|
ImageSource.camera, "Take a picture"),
|
||||||
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,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
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