flutter_image_picker/lib/src/screens/image_picker_ui.dart

89 lines
2.5 KiB
Dart
Raw Normal View History

2022-08-31 10:09:36 +02:00
import 'dart:typed_data';
import 'package:flutter/material.dart';
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 {
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,
double titleTextSize,
double iconSize,
double iconTextSize,
double spaceBetweenIcons,
2022-08-31 13:49:25 +02:00
String makePhotoText,
IconData makePhotoIcon,
String selectImageText,
IconData selectImageIcon,
String closeButtonText) async {
return await showModalBottomSheet<Uint8List?>(
2022-08-31 10:09:36 +02:00
context: context,
builder: (BuildContext context) {
return Wrap(
children: <Widget>[
ListTile(
title: Text(
title,
style: TextStyle(
fontSize: titleTextSize,
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
generateColumn(context, selectImageIcon, iconSize, iconTextSize,
ImageSource.gallery, selectImageText),
SizedBox(
width: spaceBetweenIcons,
),
generateColumn(context, makePhotoIcon, iconSize, iconTextSize,
ImageSource.camera, makePhotoText),
],
),
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
Column generateColumn(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),
),
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
}