code improvements

This commit is contained in:
commitimpush 2022-08-31 12:31:54 +02:00
parent e9f0aaf4c2
commit 560d8c3e2e
2 changed files with 33 additions and 41 deletions

View file

@ -73,7 +73,8 @@ class _ImagePickerExampleHomePageState
void pickImage() async {
Uint8List? imageInBytes = await imagePicker.showPickImageDialog(context);
if (imageInBytes != null && !listEquals(image, imageInBytes)) {
if (imageInBytes != null) {
if (!listEquals(image, imageInBytes)) {
setState(() {
image = imageInBytes;
});
@ -85,3 +86,4 @@ class _ImagePickerExampleHomePageState
}
}
}
}

View file

@ -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,
),
],
);
}
}