2022-08-31 10:09:36 +02:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2022-08-31 10:19:57 +02:00
|
|
|
import 'package:flutter_image_picker/src/services/image_picker_service.dart';
|
2022-08-31 10:09:36 +02:00
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
|
|
|
|
class ImagePickerUI {
|
2022-08-31 10:19:57 +02:00
|
|
|
final ImagePickerService _imagePickerService = ImagePickerService();
|
2022-08-31 10:09:36 +02:00
|
|
|
|
2022-08-31 13:49:25 +02:00
|
|
|
Future<Uint8List?> pickImageDialog(
|
|
|
|
BuildContext context,
|
|
|
|
String title,
|
2022-08-31 14:42:17 +02:00
|
|
|
double titleTextSize,
|
|
|
|
double iconSize,
|
|
|
|
double iconTextSize,
|
|
|
|
double spaceBetweenIcons,
|
2022-08-31 13:49:25 +02:00
|
|
|
IconData makePhotoIcon,
|
2022-08-31 17:03:20 +02:00
|
|
|
String makePhotoText,
|
2022-08-31 13:49:25 +02:00
|
|
|
IconData selectImageIcon,
|
2022-08-31 17:03:20 +02:00
|
|
|
String selectImageText,
|
2022-08-31 13:49:25 +02:00
|
|
|
String closeButtonText) async {
|
2022-08-31 11:45:12 +02:00
|
|
|
return await showModalBottomSheet<Uint8List?>(
|
2022-08-31 10:09:36 +02:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
2022-08-31 14:42:17 +02:00
|
|
|
return Wrap(
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
title,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: titleTextSize,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2022-08-31 16:54:45 +02:00
|
|
|
generateIconButtonWithText(context, selectImageIcon, iconSize,
|
|
|
|
iconTextSize, ImageSource.gallery, selectImageText),
|
2022-08-31 14:42:17 +02:00
|
|
|
SizedBox(
|
|
|
|
width: spaceBetweenIcons,
|
|
|
|
),
|
2022-08-31 16:54:45 +02:00
|
|
|
generateIconButtonWithText(context, makePhotoIcon, iconSize,
|
|
|
|
iconTextSize, ImageSource.camera, makePhotoText),
|
2022-08-31 14:42:17 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
width: 300,
|
|
|
|
height: 40,
|
|
|
|
child: ElevatedButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
child: Text(closeButtonText)),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 60,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2022-08-31 10:09:36 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2022-08-31 12:31:54 +02:00
|
|
|
|
2022-08-31 16:54:45 +02:00
|
|
|
Column generateIconButtonWithText(
|
|
|
|
BuildContext context,
|
|
|
|
IconData icon,
|
|
|
|
double iconSize,
|
|
|
|
double iconTextSize,
|
|
|
|
ImageSource imageSource,
|
|
|
|
String bottomText) {
|
2022-08-31 12:31:54 +02:00
|
|
|
return Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(icon),
|
|
|
|
iconSize: iconSize,
|
|
|
|
onPressed: () => _imagePickerService.pickImage(imageSource, context),
|
|
|
|
),
|
2022-08-31 14:42:17 +02:00
|
|
|
Text(
|
|
|
|
bottomText,
|
|
|
|
style: TextStyle(fontSize: iconTextSize),
|
|
|
|
),
|
2022-08-31 12:31:54 +02:00
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2022-08-31 10:09:36 +02:00
|
|
|
}
|