mirror of
https://github.com/Iconica-Development/flutter_image_picker.git
synced 2025-05-18 11:43:44 +02:00
feat: added ImagePickerService interface
This commit is contained in:
parent
c8a837b249
commit
ae2cc33479
6 changed files with 29 additions and 48 deletions
|
@ -20,3 +20,7 @@
|
||||||
## 1.0.0 - September 26th 2022
|
## 1.0.0 - September 26th 2022
|
||||||
|
|
||||||
- Icons can be changed by Widgets instead of IconData.
|
- Icons can be changed by Widgets instead of IconData.
|
||||||
|
|
||||||
|
## 1.0.2 - Oktober 21st 2022
|
||||||
|
|
||||||
|
- ImagePickerService can be correctly injected into the widget.
|
|
@ -68,7 +68,7 @@ packages:
|
||||||
path: ".."
|
path: ".."
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "1.0.0"
|
version: "1.0.3"
|
||||||
flutter_lints:
|
flutter_lints:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
library flutter_image_picker;
|
library flutter_image_picker;
|
||||||
|
|
||||||
|
export 'src/services/image_picker_service.dart';
|
||||||
export 'src/models/image_picker_theme.dart';
|
export 'src/models/image_picker_theme.dart';
|
||||||
export 'src/ui/image_picker.dart';
|
export 'src/ui/image_picker.dart';
|
||||||
|
|
|
@ -4,14 +4,23 @@ import 'package:image_picker/image_picker.dart';
|
||||||
|
|
||||||
/// The Image Picker Service class is the functionality of the Image Picker package which uses the Image Picker package to choose an image.
|
/// The Image Picker Service class is the functionality of the Image Picker package which uses the Image Picker package to choose an image.
|
||||||
/// If you have your own implementation of the Image Picker you can add it to the constructor when creating the class.
|
/// If you have your own implementation of the Image Picker you can add it to the constructor when creating the class.
|
||||||
class ImagePickerService {
|
abstract class ImagePickerService {
|
||||||
ImagePickerService({this.imagePicker});
|
/// [pickImage] is the function that picks the image and returns it as a [Uint8List].
|
||||||
|
/// The function requires [source], an [ImageSource]
|
||||||
|
Future<Uint8List?> pickImage(ImageSource source);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The ImagePickerServiceDefault is the default implementation of the ImagePickerService.
|
||||||
|
/// It uses the Image Picker package to pick an image and returns it as a [Uint8List].
|
||||||
|
class ImagePickerServiceDefault implements ImagePickerService {
|
||||||
|
ImagePickerServiceDefault({this.imagePicker});
|
||||||
|
|
||||||
/// It's possible to have your own implementation for the Image Picker if you don't want to use the Image Picker Package.
|
/// It's possible to have your own implementation for the Image Picker if you don't want to use the Image Picker Package.
|
||||||
ImagePicker? imagePicker;
|
ImagePicker? imagePicker;
|
||||||
|
|
||||||
/// [pickImage] is the function that picks the image and returns it as a [Uint8List].
|
/// [pickImage] is the function that picks the image and returns it as a [Uint8List].
|
||||||
/// The function requires [source], an [ImageSource] that's the method of how the image needs to be picked, for example gallery or camera.
|
/// The function requires [source], an [ImageSource] that's the method of how the image needs to be picked, for example gallery or camera.
|
||||||
|
@override
|
||||||
Future<Uint8List?> pickImage(ImageSource source) async {
|
Future<Uint8List?> pickImage(ImageSource source) async {
|
||||||
var image =
|
var image =
|
||||||
await (await (imagePicker ?? ImagePicker()).pickImage(source: source))
|
await (await (imagePicker ?? ImagePicker()).pickImage(source: source))
|
||||||
|
|
|
@ -9,12 +9,12 @@ import '../models/image_picker_theme.dart';
|
||||||
/// The second one is your own implementation of the ImagePickerService. Which can be used in testing for example.
|
/// The second one is your own implementation of the ImagePickerService. Which can be used in testing for example.
|
||||||
/// The third one is a custom Button widget.
|
/// The third one is a custom Button widget.
|
||||||
class ImagePicker extends StatelessWidget {
|
class ImagePicker extends StatelessWidget {
|
||||||
const ImagePicker(
|
const ImagePicker({
|
||||||
{Key? key,
|
this.imagePickerTheme = const ImagePickerTheme(),
|
||||||
this.imagePickerTheme = const ImagePickerTheme(),
|
this.imagePickerService,
|
||||||
this.imagePickerService,
|
this.customButton,
|
||||||
this.customButton})
|
super.key,
|
||||||
: super(key: key);
|
});
|
||||||
|
|
||||||
/// ImagePickerTheme can be used to change the UI of the Image Picker Widget to change the text/icons to your liking.
|
/// ImagePickerTheme can be used to change the UI of the Image Picker Widget to change the text/icons to your liking.
|
||||||
final ImagePickerTheme imagePickerTheme;
|
final ImagePickerTheme imagePickerTheme;
|
||||||
|
@ -119,8 +119,9 @@ class ImagePicker extends StatelessWidget {
|
||||||
key: Key(bottomText),
|
key: Key(bottomText),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final navigator = Navigator.of(context);
|
final navigator = Navigator.of(context);
|
||||||
var image = await (imagePickerService ?? ImagePickerService())
|
var image =
|
||||||
.pickImage(imageSource);
|
await (imagePickerService ?? ImagePickerServiceDefault())
|
||||||
|
.pickImage(imageSource);
|
||||||
navigator.pop(image);
|
navigator.pop(image);
|
||||||
},
|
},
|
||||||
child: customIcon ??
|
child: customIcon ??
|
||||||
|
|
40
pubspec.yaml
40
pubspec.yaml
|
@ -1,7 +1,7 @@
|
||||||
name: flutter_image_picker
|
name: flutter_image_picker
|
||||||
description: A new Flutter package project.
|
description: A Flutter Image Picking package.
|
||||||
version: 1.0.0
|
version: 1.0.3
|
||||||
homepage: https://github.com/Iconica-Development/flutter_image_picker
|
repository: https://github.com/Iconica-Development/flutter_image_picker
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.17.6 <3.0.0"
|
sdk: ">=2.17.6 <3.0.0"
|
||||||
|
@ -18,38 +18,4 @@ dev_dependencies:
|
||||||
flutter_lints: ^2.0.0
|
flutter_lints: ^2.0.0
|
||||||
mocktail: ^0.3.0
|
mocktail: ^0.3.0
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
|
||||||
|
|
||||||
# The following section is specific to Flutter packages.
|
|
||||||
flutter:
|
flutter:
|
||||||
# To add assets to your package, add an assets section, like this:
|
|
||||||
# assets:
|
|
||||||
# - images/a_dot_burr.jpeg
|
|
||||||
# - images/a_dot_ham.jpeg
|
|
||||||
#
|
|
||||||
# For details regarding assets in packages, see
|
|
||||||
# https://flutter.dev/assets-and-images/#from-packages
|
|
||||||
#
|
|
||||||
# An image asset can refer to one or more resolution-specific "variants", see
|
|
||||||
# https://flutter.dev/assets-and-images/#resolution-aware
|
|
||||||
|
|
||||||
# To add custom fonts to your package, add a fonts section here,
|
|
||||||
# in this "flutter" section. Each entry in this list should have a
|
|
||||||
# "family" key with the font family name, and a "fonts" key with a
|
|
||||||
# list giving the asset and other descriptors for the font. For
|
|
||||||
# example:
|
|
||||||
# fonts:
|
|
||||||
# - family: Schyler
|
|
||||||
# fonts:
|
|
||||||
# - asset: fonts/Schyler-Regular.ttf
|
|
||||||
# - asset: fonts/Schyler-Italic.ttf
|
|
||||||
# style: italic
|
|
||||||
# - family: Trajan Pro
|
|
||||||
# fonts:
|
|
||||||
# - asset: fonts/TrajanPro.ttf
|
|
||||||
# - asset: fonts/TrajanPro_Bold.ttf
|
|
||||||
# weight: 700
|
|
||||||
#
|
|
||||||
# For details regarding fonts in packages, see
|
|
||||||
# https://flutter.dev/custom-fonts/#from-packages
|
|
||||||
|
|
Loading…
Reference in a new issue