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 11:52:29 +02:00
|
|
|
final double iconSize = 150;
|
2022-08-31 10:09:36 +02:00
|
|
|
|
|
|
|
Future<Uint8List?> pickImageDialog(BuildContext context) 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 11:52:29 +02:00
|
|
|
return Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
2022-08-31 10:09:36 +02:00
|
|
|
),
|
2022-08-31 11:52:29 +02:00
|
|
|
const Text(
|
|
|
|
"Upload Image",
|
|
|
|
textScaleFactor: 2,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2022-08-31 12:31:54 +02:00
|
|
|
generateColumn(
|
|
|
|
context, Icons.image, ImageSource.gallery, "Select File"),
|
|
|
|
generateColumn(context, Icons.camera_alt_rounded,
|
|
|
|
ImageSource.camera, "Take a picture"),
|
2022-08-31 11:45:12 +02:00
|
|
|
],
|
|
|
|
),
|
2022-08-31 11:52:29 +02:00
|
|
|
ElevatedButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
child: const Text("Close")),
|
2022-08-31 11:45:12 +02:00
|
|
|
]);
|
2022-08-31 10:09:36 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2022-08-31 12:31:54 +02:00
|
|
|
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2022-08-31 10:09:36 +02:00
|
|
|
}
|