mirror of
https://github.com/Iconica-Development/flutter_image_picker.git
synced 2025-05-18 19:53:45 +02:00
Merge remote-tracking branch 'origin/master' into feature/config-for-setting-size-and-quality
This commit is contained in:
commit
cc1c54027a
12 changed files with 168 additions and 146 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.
|
9
LICENSE
Normal file
9
LICENSE
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
Copyright (c) 2022 Iconica, All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -50,7 +50,7 @@ Please file any issues, bugs or feature request as an issue on our [GitHub](http
|
||||||
|
|
||||||
## Want to contribute
|
## Want to contribute
|
||||||
|
|
||||||
If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](../CONTRIBUTING.md) and send us your [pull request](URL TO PULL REQUEST TAB IN REPO).
|
If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](../CONTRIBUTING.md) and send us your [pull request](https://github.com/Iconica-Development/flutter_image_picker/pulls).
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// SPDX-FileCopyrightText: 2022 Iconica
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_image_picker/flutter_image_picker.dart';
|
import 'package:flutter_image_picker/flutter_image_picker.dart';
|
||||||
|
|
|
@ -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,5 +1,10 @@
|
||||||
|
// SPDX-FileCopyrightText: 2022 Iconica
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
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/models/image_picker_config.dart';
|
export 'src/models/image_picker_config.dart';
|
||||||
export 'src/ui/image_picker.dart';
|
export 'src/ui/image_picker.dart';
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// SPDX-FileCopyrightText: 2022 Iconica
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class ImagePickerTheme {
|
class ImagePickerTheme {
|
||||||
|
|
|
@ -1,18 +1,33 @@
|
||||||
import 'dart:typed_data';
|
// SPDX-FileCopyrightText: 2022 Iconica
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
import 'dart:typed_data';
|
||||||
import 'package:flutter_image_picker/src/models/image_picker_config.dart';
|
import 'package:flutter_image_picker/src/models/image_picker_config.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
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, {
|
||||||
|
ImagePickerConfig? config,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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(
|
Future<Uint8List?> pickImage(
|
||||||
ImageSource source, {
|
ImageSource source, {
|
||||||
ImagePickerConfig? config,
|
ImagePickerConfig? config,
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
// SPDX-FileCopyrightText: 2022 Iconica
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_image_picker/flutter_image_picker.dart';
|
import 'package:flutter_image_picker/flutter_image_picker.dart';
|
||||||
import 'package:flutter_image_picker/src/services/image_picker_service.dart';
|
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
|
|
||||||
/// The Image Picker class generates the Image Picker Widget which can be displayed in your application. If you call the class you can give it 4 optional variables:
|
/// The Image Picker class generates the Image Picker Widget which can be displayed in your application. If you call the class you can give it 4 optional variables:
|
||||||
|
@ -10,12 +13,12 @@ import 'package:image_picker/image_picker.dart';
|
||||||
/// The fourth one is a custom Button widget.
|
/// The fourth 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.imagePickerConfig = const ImagePickerConfig(),
|
this.imagePickerConfig = const ImagePickerConfig(),
|
||||||
this.imagePickerService,
|
this.imagePickerService,
|
||||||
this.customButton,
|
this.customButton,
|
||||||
}) : super(key: key);
|
super.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;
|
||||||
|
@ -24,82 +27,84 @@ class ImagePicker extends StatelessWidget {
|
||||||
final ImagePickerConfig imagePickerConfig;
|
final ImagePickerConfig imagePickerConfig;
|
||||||
|
|
||||||
/// The Image Picker Dialog can have a custom button if you want to.
|
/// The Image Picker Dialog can have a custom button if you want to.
|
||||||
final StatelessWidget? customButton;
|
final Widget? customButton;
|
||||||
|
|
||||||
/// The ImagePickerService can be used if you want to use your own implementation of the Image Service if you want to use it for testing or add more features. If null the current implementation will be used.
|
/// The ImagePickerService can be used if you want to use your own implementation of the Image Service if you want to use it for testing or add more features. If null the current implementation will be used.
|
||||||
final ImagePickerService? imagePickerService;
|
final ImagePickerService? imagePickerService;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => SingleChildScrollView(
|
Widget build(BuildContext context) {
|
||||||
child: Column(
|
return SingleChildScrollView(
|
||||||
children: <Widget>[
|
child: Column(
|
||||||
ListTile(
|
children: <Widget>[
|
||||||
tileColor: imagePickerTheme.titleBackgroundColor,
|
ListTile(
|
||||||
title: Text(
|
tileColor: imagePickerTheme.titleBackgroundColor,
|
||||||
textAlign: imagePickerTheme.titleAlignment,
|
title: Text(
|
||||||
imagePickerTheme.title,
|
textAlign: imagePickerTheme.titleAlignment,
|
||||||
style: TextStyle(
|
imagePickerTheme.title,
|
||||||
fontFamily: imagePickerTheme.font,
|
style: TextStyle(
|
||||||
fontSize: imagePickerTheme.titleTextSize,
|
fontFamily: imagePickerTheme.font,
|
||||||
color: imagePickerTheme.titleColor,
|
fontSize: imagePickerTheme.titleTextSize,
|
||||||
),
|
color: imagePickerTheme.titleColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
),
|
||||||
Row(
|
const SizedBox(height: 20),
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
Row(
|
||||||
children: [
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
_generateIconButtonWithText(
|
children: [
|
||||||
context,
|
_generateIconButtonWithText(
|
||||||
imagePickerTheme.selectImageIcon,
|
context,
|
||||||
imagePickerTheme,
|
imagePickerTheme.selectImageIcon,
|
||||||
Icons.image,
|
imagePickerTheme,
|
||||||
ImageSource.gallery,
|
Icons.image,
|
||||||
imagePickerTheme.selectImageText,
|
ImageSource.gallery,
|
||||||
),
|
imagePickerTheme.selectImageText,
|
||||||
SizedBox(
|
),
|
||||||
width: imagePickerTheme.spaceBetweenIcons,
|
SizedBox(
|
||||||
),
|
width: imagePickerTheme.spaceBetweenIcons,
|
||||||
_generateIconButtonWithText(
|
),
|
||||||
context,
|
_generateIconButtonWithText(
|
||||||
imagePickerTheme.makePhotoIcon,
|
context,
|
||||||
imagePickerTheme,
|
imagePickerTheme.makePhotoIcon,
|
||||||
Icons.camera_alt_rounded,
|
imagePickerTheme,
|
||||||
ImageSource.camera,
|
Icons.camera_alt_rounded,
|
||||||
imagePickerTheme.makePhotoText,
|
ImageSource.camera,
|
||||||
),
|
imagePickerTheme.makePhotoText,
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
const SizedBox(height: 10),
|
),
|
||||||
Row(
|
const SizedBox(height: 10),
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
Row(
|
||||||
children: [
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
SizedBox(
|
children: [
|
||||||
width: imagePickerTheme.closeButtonWidth,
|
SizedBox(
|
||||||
height: imagePickerTheme.closeButtonHeight,
|
width: imagePickerTheme.closeButtonWidth,
|
||||||
child: customButton ??
|
height: imagePickerTheme.closeButtonHeight,
|
||||||
ElevatedButton(
|
child: customButton ??
|
||||||
style: ElevatedButton.styleFrom(
|
ElevatedButton(
|
||||||
backgroundColor:
|
style: ElevatedButton.styleFrom(
|
||||||
imagePickerTheme.closeButtonBackgroundColor,
|
backgroundColor:
|
||||||
),
|
imagePickerTheme.closeButtonBackgroundColor,
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
),
|
||||||
child: Text(
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
imagePickerTheme.closeButtonText,
|
child: Text(
|
||||||
style: TextStyle(
|
imagePickerTheme.closeButtonText,
|
||||||
fontFamily: imagePickerTheme.font,
|
style: TextStyle(
|
||||||
fontSize: imagePickerTheme.closeButtonTextSize,
|
fontFamily: imagePickerTheme.font,
|
||||||
color: imagePickerTheme.closeButtonTextColor,
|
fontSize: imagePickerTheme.closeButtonTextSize,
|
||||||
),
|
color: imagePickerTheme.closeButtonTextColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
],
|
)
|
||||||
),
|
],
|
||||||
const SizedBox(height: 30),
|
),
|
||||||
],
|
const SizedBox(height: 30),
|
||||||
),
|
],
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// The [_generateIconButtonWithText] function returns a column that includes an [IconButton] and [Text].
|
/// The [_generateIconButtonWithText] function returns a column that includes an [IconButton] and [Text].
|
||||||
/// The function requires the following parameters to be able to generate an icon with text:
|
/// The function requires the following parameters to be able to generate an icon with text:
|
||||||
|
@ -109,39 +114,41 @@ class ImagePicker extends StatelessWidget {
|
||||||
/// [imageSource] The type of [ImageSource] to be used to pick an image when pressed on the icon.
|
/// [imageSource] The type of [ImageSource] to be used to pick an image when pressed on the icon.
|
||||||
/// [bottomText] The text that's displayed underneath the icon.
|
/// [bottomText] The text that's displayed underneath the icon.
|
||||||
Column _generateIconButtonWithText(
|
Column _generateIconButtonWithText(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
Widget? customIcon,
|
Widget? customIcon,
|
||||||
ImagePickerTheme imagePickerTheme,
|
ImagePickerTheme imagePickerTheme,
|
||||||
IconData icon,
|
IconData icon,
|
||||||
ImageSource imageSource,
|
ImageSource imageSource,
|
||||||
String bottomText) =>
|
String bottomText) {
|
||||||
Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
InkWell(
|
InkWell(
|
||||||
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, config: imagePickerConfig);
|
await (imagePickerService ?? ImagePickerServiceDefault())
|
||||||
navigator.pop(image);
|
.pickImage(imageSource, config: imagePickerConfig);
|
||||||
},
|
navigator.pop(image);
|
||||||
child: customIcon ??
|
},
|
||||||
Icon(
|
child: customIcon ??
|
||||||
icon,
|
Icon(
|
||||||
size: imagePickerTheme.iconSize,
|
icon,
|
||||||
color: imagePickerTheme.iconColor,
|
size: imagePickerTheme.iconSize,
|
||||||
),
|
color: imagePickerTheme.iconColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
bottomText,
|
||||||
|
style: TextStyle(
|
||||||
|
fontFamily: imagePickerTheme.font,
|
||||||
|
fontSize: imagePickerTheme.iconTextSize,
|
||||||
|
color: imagePickerTheme.textColor,
|
||||||
),
|
),
|
||||||
Text(
|
),
|
||||||
bottomText,
|
const SizedBox(height: 20),
|
||||||
style: TextStyle(
|
],
|
||||||
fontFamily: imagePickerTheme.font,
|
);
|
||||||
fontSize: imagePickerTheme.iconTextSize,
|
}
|
||||||
color: imagePickerTheme.textColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
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
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// SPDX-FileCopyrightText: 2022 Iconica
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// SPDX-FileCopyrightText: 2022 Iconica
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
import 'package:flutter_image_picker/src/services/image_picker_service.dart';
|
import 'package:flutter_image_picker/src/services/image_picker_service.dart';
|
||||||
import 'package:mocktail/mocktail.dart';
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue