fix: add ci and linter

This commit is contained in:
mike doornenbal 2024-02-06 16:18:57 +01:00
parent 829574e5f6
commit 455fc691a2
13 changed files with 267 additions and 516 deletions

14
.github/workflows/component-ci.yml vendored Normal file
View file

@ -0,0 +1,14 @@
name: Iconica Standard Component CI Workflow
# Workflow Caller version: 2.0.0
on:
pull_request:
workflow_dispatch:
jobs:
call-global-iconica-workflow:
uses: Iconica-Development/.github/.github/workflows/component-ci.yml@master
secrets: inherit
permissions: write-all
with:
subfolder: "." # add optional subfolder to run workflow in

View file

@ -1,32 +0,0 @@
name: CI
on:
push:
branches: [ master ]
pull_request:
branches:
- master
- feature/*
- bugfix/*
- hotfix/*
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.gradle/wrapper
/opt/hostedtoolcache/flutter
key: ${{ runner.OS }}-flutter-install-cache
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
- name: Flutter pub get
run: flutter pub get
- name: Flutter format
run: flutter format -o none --set-exit-if-changed .
- name: Flutter analyze
run: flutter analyze

View file

@ -27,4 +27,8 @@
## 1.0.4 - April 4th 2023
- Make camera option optional
- Make camera option optional
## 1.0.5 - February 7th 2024
- Added CI and linter

View file

@ -1,4 +1,9 @@
include: package:flutter_lints/flutter.yaml
include: package:flutter_iconica_analysis/analysis_options.yaml
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
# Possible to overwrite the rules from the package
analyzer:
exclude:
linter:
rules:

1
example/.gitignore vendored
View file

@ -31,6 +31,7 @@ migrate_working_dir/
.pub-cache/
.pub/
/build/
pubspec.lock
# Web related
lib/generated_plugin_registrant.dart

View file

@ -1,289 +0,0 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
url: "https://pub.dev"
source: hosted
version: "2.10.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
characters:
dependency: transitive
description:
name: characters
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
url: "https://pub.dev"
source: hosted
version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
url: "https://pub.dev"
source: hosted
version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
url: "https://pub.dev"
source: hosted
version: "1.17.0"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: "7632a2bcddc8cef4afde3c6f80e69b29a7060e176f01119c229fe4eb3a2a3d4f"
url: "https://pub.dev"
source: hosted
version: "0.3.3+1"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
url: "https://pub.dev"
source: hosted
version: "1.0.5"
fake_async:
dependency: transitive
description:
name: fake_async
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_image_picker:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.0.4"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
url: "https://pub.dev"
source: hosted
version: "2.0.1"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: "60fc7b78455b94e6de2333d2f95196d32cf5c22f4b0b0520a628804cb463503b"
url: "https://pub.dev"
source: hosted
version: "2.0.7"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: transitive
description:
name: http
sha256: "6aa2946395183537c8b880962d935877325d6a09a2867c3970c05c0fed6ac482"
url: "https://pub.dev"
source: hosted
version: "0.13.5"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: db3060f22889f3d9d55f6a217565486737037eec3609f7f3eca4d0c67ee0d8a0
url: "https://pub.dev"
source: hosted
version: "4.0.1"
image_picker:
dependency: transitive
description:
name: image_picker
sha256: a8f2f0aed50c03230ab37e93ca2905c50b6c4097245345956eb24a88f45328cd
url: "https://pub.dev"
source: hosted
version: "0.8.6"
image_picker_android:
dependency: transitive
description:
name: image_picker_android
sha256: "8243d3324e28806671feb358e3756528bae6f63dacafaecf896e6b45b167def9"
url: "https://pub.dev"
source: hosted
version: "0.8.5+2"
image_picker_for_web:
dependency: transitive
description:
name: image_picker_for_web
sha256: "60f306ffbdcada4bc8b2691acc420258a1b758e102c87c4f94fb568d640f0e0e"
url: "https://pub.dev"
source: hosted
version: "2.1.8"
image_picker_ios:
dependency: transitive
description:
name: image_picker_ios
sha256: "1768087441bd69ca632249d212c26fa8d530552d37b4896a4dd8d6781435c147"
url: "https://pub.dev"
source: hosted
version: "0.8.6+1"
image_picker_platform_interface:
dependency: transitive
description:
name: image_picker_platform_interface
sha256: cedb2650709f066ee83fd65a1d99b6ff33e5adf98cea376426dd33c2b22bf6ad
url: "https://pub.dev"
source: hosted
version: "2.6.1"
js:
dependency: transitive
description:
name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
url: "https://pub.dev"
source: hosted
version: "0.6.5"
lints:
dependency: transitive
description:
name: lints
sha256: "5cfd6509652ff5e7fe149b6df4859e687fca9048437857cb2e65c8d780f396e3"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
matcher:
dependency: transitive
description:
name: matcher
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
url: "https://pub.dev"
source: hosted
version: "0.12.13"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
url: "https://pub.dev"
source: hosted
version: "0.2.0"
meta:
dependency: transitive
description:
name: meta
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
path:
dependency: transitive
description:
name: path
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
url: "https://pub.dev"
source: hosted
version: "1.8.2"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "075f927ebbab4262ace8d0b283929ac5410c0ac4e7fc123c76429564facfb757"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
url: "https://pub.dev"
source: hosted
version: "1.9.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev"
source: hosted
version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
url: "https://pub.dev"
source: hosted
version: "0.4.16"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
vector_math:
dependency: transitive
description:
name: vector_math
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
sdks:
dart: ">=2.18.0 <3.0.0"
flutter: ">=2.10.0"

View file

@ -1,10 +1,10 @@
// SPDX-FileCopyrightText: 2022 Iconica
//
// SPDX-License-Identifier: BSD-3-Clause
///
library flutter_image_picker;
export 'src/services/image_picker_service.dart';
export 'src/models/image_picker_theme.dart';
export 'src/models/image_picker_config.dart';
export 'src/models/image_picker_theme.dart';
export 'src/services/image_picker_service.dart';
export 'src/ui/image_picker.dart';

View file

@ -10,11 +10,12 @@ class ImagePickerConfig {
/// If specified, the image will be at most `maxWidth` wide and
/// `maxHeight` tall. Otherwise the image will be returned at it's
/// original width and height.
/// The `imageQuality` argument modifies the quality of the image, ranging from 0-100
/// where 100 is the original/max quality. If `imageQuality` is null, the image with
/// the original quality will be returned. Compression is only supported for certain
/// image types such as JPEG and on Android PNG and WebP, too. If compression is not supported for the image that is picked,
/// a warning message will be logged.
/// The `imageQuality` argument modifies the quality of the image, ranging
/// from 0-100 where 100 is the original/max quality. If `imageQuality` is null, the image with
/// the original quality will be returned. Compression is only supported
/// for certain image types such as JPEG and on Android PNG and WebP, too.
/// If compression is not supported for the image that is picked, a warning
/// message will be logged.
final double? maxWidth;
final double? maxHeight;
final int? imageQuality;

View file

@ -8,8 +8,8 @@ class ImagePickerTheme {
/// The [ImagePickerTheme] is used to style the [ImagePicker].
const ImagePickerTheme({
this.font = "Roboto",
this.title = "Upload Image",
this.font = 'Roboto',
this.title = 'Upload Image',
this.titleTextSize = 20,
this.titleColor = Colors.black,
this.titleBackgroundColor = Colors.white,
@ -20,10 +20,10 @@ class ImagePickerTheme {
this.iconTextSize = 15,
this.spaceBetweenIcons = 30,
this.makePhotoIcon,
this.makePhotoText = "Take a Picture",
this.makePhotoText = 'Take a Picture',
this.selectImageIcon,
this.selectImageText = "Select File",
this.closeButtonText = "Close",
this.selectImageText = 'Select File',
this.closeButtonText = 'Close',
this.closeButtonTextSize = 15,
this.closeButtonTextColor = Colors.white,
this.closeButtonWidth = 300,
@ -64,19 +64,23 @@ class ImagePickerTheme {
/// The size of the space between the two icons in the Image Picker Dialog.
final double spaceBetweenIcons;
/// The icon that is displayed for the 'Make Photo' functionality of the Image Picker Dialog.
/// The icon that is displayed for the 'Make Photo' functionality of the
/// Image Picker Dialog.
final Widget? makePhotoIcon;
/// The text that is displayed underneath the 'Make Photo' icon.
final String makePhotoText;
/// The icon that is displayed for the 'Select Image From Gallery' functionality of the Image Picker Dialog.
/// The icon that is displayed for the 'Select Image From Gallery'
/// functionality of the Image Picker Dialog.
final Widget? selectImageIcon;
/// The text that is displayed underneath the 'Select Image From Gallery' icon.
/// The text that is displayed underneath the 'Select Image From Gallery'
/// icon.
final String selectImageText;
/// The text that is shown on the 'Close Dialog' button at the bottom of the Image Picker Dialog.
/// The text that is shown on the 'Close Dialog' button at the bottom of the
/// Image Picker Dialog.
final String closeButtonText;
/// The fontsize of the text of the close button of the Image Picker Dialog.
@ -85,10 +89,12 @@ class ImagePickerTheme {
/// The color of the text of the close button of the Image Picker Dialog.
final Color closeButtonTextColor;
/// The width of the 'Close Dialog' button at the bottom of the Image Picker Dialog.
/// The width of the 'Close Dialog' button at the bottom of the Image Picker
/// Dialog.
final double closeButtonWidth;
/// The height of the 'Close Dialog' button at the bottom of the Image Picker Dialog.
/// The height of the 'Close Dialog' button at the bottom of the Image Picker
/// Dialog.
final double closeButtonHeight;
/// The color of the close button of the Image Picker Dialog.

View file

@ -6,10 +6,13 @@ import 'dart:typed_data';
import 'package:flutter_image_picker/src/models/image_picker_config.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.
/// If you have your own implementation of the Image Picker you can add it to the constructor when creating the class.
abstract class ImagePickerService {
/// [pickImage] is the function that picks the image and returns it as a [Uint8List].
/// 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.
mixin ImagePickerService {
/// [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, {
@ -17,16 +20,21 @@ abstract class ImagePickerService {
});
}
/// 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].
/// 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;
/// [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.
/// [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.
@override
Future<Uint8List?> pickImage(
ImageSource source, {

View file

@ -6,10 +6,15 @@ import 'package:flutter/material.dart';
import 'package:flutter_image_picker/flutter_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 first one is the [ImagePickerTheme] which can be used to change the UI of the widget.
/// The second one is the [ImagePickerConfig] which can be used to configure the behaviour of the image picker.
/// The third one is your own implementation of the ImagePickerService. Which can be used in testing for example.
/// 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 first one is the [ImagePickerTheme] which can be used to change the UI
/// of the widget.
/// The second one is the [ImagePickerConfig] which can be used to configure the
/// behaviour of the image picker.
/// The third one is your own implementation of the ImagePickerService. Which
/// can be used in testing for example.
/// The fourth one is a custom Button widget.
class ImagePicker extends StatelessWidget {
const ImagePicker({
@ -23,134 +28,141 @@ class ImagePicker extends StatelessWidget {
/// ImagePickerTheme can be used to change the UI of the Image Picker Widget to change the text/icons to your liking.
final ImagePickerTheme imagePickerTheme;
/// ImagePickerConfig can be used to define the size and quality for the uploaded image.
/// ImagePickerConfig can be used to define the size and quality for the
/// uploaded image.
final ImagePickerConfig imagePickerConfig;
/// The Image Picker Dialog can have a custom button if you want to.
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;
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
ListTile(
tileColor: imagePickerTheme.titleBackgroundColor,
title: Text(
textAlign: imagePickerTheme.titleAlignment,
imagePickerTheme.title,
style: TextStyle(
fontFamily: imagePickerTheme.font,
fontSize: imagePickerTheme.titleTextSize,
color: imagePickerTheme.titleColor,
Widget build(BuildContext context) => SingleChildScrollView(
child: Column(
children: <Widget>[
ListTile(
tileColor: imagePickerTheme.titleBackgroundColor,
title: Text(
textAlign: imagePickerTheme.titleAlignment,
imagePickerTheme.title,
style: TextStyle(
fontFamily: imagePickerTheme.font,
fontSize: imagePickerTheme.titleTextSize,
color: imagePickerTheme.titleColor,
),
),
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_generateIconButtonWithText(
context,
imagePickerTheme.selectImageIcon,
imagePickerTheme,
Icons.image,
ImageSource.gallery,
imagePickerTheme.selectImageText,
),
if (imagePickerConfig.cameraOption ?? true) ...[
SizedBox(
width: imagePickerTheme.spaceBetweenIcons,
),
_generateIconButtonWithText(
context,
imagePickerTheme.makePhotoIcon,
imagePickerTheme,
Icons.camera_alt_rounded,
ImageSource.camera,
imagePickerTheme.makePhotoText,
),
],
],
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: imagePickerTheme.closeButtonWidth,
height: imagePickerTheme.closeButtonHeight,
child: customButton ??
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
imagePickerTheme.closeButtonBackgroundColor,
),
onPressed: () => Navigator.of(context).pop(),
child: Text(
imagePickerTheme.closeButtonText,
style: TextStyle(
fontFamily: imagePickerTheme.font,
fontSize: imagePickerTheme.closeButtonTextSize,
color: imagePickerTheme.closeButtonTextColor,
),
),
),
),
],
),
const SizedBox(height: 30),
],
),
);
/// 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:
/// [context] The build context that is required to make the [pickImage]
/// function in [_imagePickerService] work.
/// [imagePickerTheme] The ImagePickerTheme that includes all default values
/// for the Image Picker Dialog.
/// [icon] The icon that needs to be displayed, requires an [IconData] as
///value to be used.
/// [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.
Column _generateIconButtonWithText(
BuildContext context,
Widget? customIcon,
ImagePickerTheme imagePickerTheme,
IconData icon,
ImageSource imageSource,
String bottomText,
) =>
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
InkWell(
key: Key(bottomText),
onTap: () async {
var navigator = Navigator.of(context);
var image =
await (imagePickerService ?? ImagePickerServiceDefault())
.pickImage(imageSource, config: imagePickerConfig);
navigator.pop(image);
},
child: customIcon ??
Icon(
icon,
size: imagePickerTheme.iconSize,
color: imagePickerTheme.iconColor,
),
),
Text(
bottomText,
style: TextStyle(
fontFamily: imagePickerTheme.font,
fontSize: imagePickerTheme.iconTextSize,
color: imagePickerTheme.textColor,
),
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_generateIconButtonWithText(
context,
imagePickerTheme.selectImageIcon,
imagePickerTheme,
Icons.image,
ImageSource.gallery,
imagePickerTheme.selectImageText,
),
if (imagePickerConfig.cameraOption ?? true) ...[
SizedBox(
width: imagePickerTheme.spaceBetweenIcons,
),
_generateIconButtonWithText(
context,
imagePickerTheme.makePhotoIcon,
imagePickerTheme,
Icons.camera_alt_rounded,
ImageSource.camera,
imagePickerTheme.makePhotoText,
),
]
],
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: imagePickerTheme.closeButtonWidth,
height: imagePickerTheme.closeButtonHeight,
child: customButton ??
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
imagePickerTheme.closeButtonBackgroundColor,
),
onPressed: () => Navigator.of(context).pop(),
child: Text(
imagePickerTheme.closeButtonText,
style: TextStyle(
fontFamily: imagePickerTheme.font,
fontSize: imagePickerTheme.closeButtonTextSize,
color: imagePickerTheme.closeButtonTextColor,
),
),
),
)
],
),
const SizedBox(height: 30),
],
),
);
}
/// 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:
/// [context] The build context that is required to make the [pickImage] function in [_imagePickerService] work.
/// [imagePickerTheme] The ImagePickerTheme that includes all default values for the Image Picker Dialog.
/// [icon] The icon that needs to be displayed, requires an [IconData] as value to be used.
/// [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.
Column _generateIconButtonWithText(
BuildContext context,
Widget? customIcon,
ImagePickerTheme imagePickerTheme,
IconData icon,
ImageSource imageSource,
String bottomText) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
InkWell(
key: Key(bottomText),
onTap: () async {
final navigator = Navigator.of(context);
var image =
await (imagePickerService ?? ImagePickerServiceDefault())
.pickImage(imageSource, config: imagePickerConfig);
navigator.pop(image);
},
child: customIcon ??
Icon(
icon,
size: imagePickerTheme.iconSize,
color: imagePickerTheme.iconColor,
),
),
Text(
bottomText,
style: TextStyle(
fontFamily: imagePickerTheme.font,
fontSize: imagePickerTheme.iconTextSize,
color: imagePickerTheme.textColor,
),
),
const SizedBox(height: 20),
],
);
}
);
}

View file

@ -1,6 +1,6 @@
name: flutter_image_picker
description: A Flutter Image Picking package.
version: 1.0.4
version: 1.0.5
repository: https://github.com/Iconica-Development/flutter_image_picker
environment:
@ -15,7 +15,10 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
mocktail: ^0.3.0
flutter_iconica_analysis:
git:
url: https://github.com/Iconica-Development/flutter_iconica_analysis
ref: 6.0.0
flutter:

View file

@ -7,15 +7,15 @@ import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_image_picker/flutter_image_picker.dart'
as iconica_image_picker;
import 'package:image_picker/image_picker.dart' as image_picker;
import 'package:flutter_test/flutter_test.dart';
import 'package:image_picker/image_picker.dart' as image_picker;
import 'package:mocktail/mocktail.dart';
import 'mocks/image_picker_service_mock.dart';
void main() {
Uint8List cameraImage = Uint8List(10);
Uint8List galleryImage = Uint8List(44);
var cameraImage = Uint8List(10);
var galleryImage = Uint8List(44);
testWidgets('Image Picker Shows With Normal Theme', (tester) async {
await tester.pumpWidget(
@ -26,15 +26,15 @@ void main() {
),
);
final titleFinder =
var titleFinder =
find.text(const iconica_image_picker.ImagePickerTheme().title);
final makePhotoIconFinder = find.byIcon(Icons.camera_alt_rounded);
final makePhotoTextFinder =
var makePhotoIconFinder = find.byIcon(Icons.camera_alt_rounded);
var makePhotoTextFinder =
find.text(const iconica_image_picker.ImagePickerTheme().makePhotoText);
final selectImageIconFinder = find.byIcon(Icons.image);
final selectImageTextFinder = find
var selectImageIconFinder = find.byIcon(Icons.image);
var selectImageTextFinder = find
.text(const iconica_image_picker.ImagePickerTheme().selectImageText);
final closebuttonTextFinder = find
var closebuttonTextFinder = find
.text(const iconica_image_picker.ImagePickerTheme().closeButtonText);
expect(titleFinder, findsOneWidget);
@ -48,18 +48,24 @@ void main() {
testWidgets(
'Image Picker Calls Function Correctly When ImageSource Is Gallery',
(tester) async {
ImagePickerServiceMock serviceMock = ImagePickerServiceMock();
var serviceMock = ImagePickerServiceMock();
when(() => serviceMock.pickImage(image_picker.ImageSource.gallery))
.thenAnswer((_) => Future.value(galleryImage));
await tester.pumpWidget(MaterialApp(
await tester.pumpWidget(
MaterialApp(
home: Material(
child: iconica_image_picker.ImagePicker(
imagePickerService: serviceMock))));
child: iconica_image_picker.ImagePicker(
imagePickerService: serviceMock,
),
),
),
);
Finder finder = find.byKey(
Key(const iconica_image_picker.ImagePickerTheme().selectImageText));
var finder = find.byKey(
Key(const iconica_image_picker.ImagePickerTheme().selectImageText),
);
await tester.tap(finder);
@ -70,18 +76,24 @@ void main() {
testWidgets(
'Image Picker Calls Function Correctly When ImageSource Is Camera',
(tester) async {
ImagePickerServiceMock serviceMock = ImagePickerServiceMock();
var serviceMock = ImagePickerServiceMock();
when(() => serviceMock.pickImage(image_picker.ImageSource.camera))
.thenAnswer((_) => Future.value(cameraImage));
await tester.pumpWidget(MaterialApp(
await tester.pumpWidget(
MaterialApp(
home: Material(
child: iconica_image_picker.ImagePicker(
imagePickerService: serviceMock))));
child: iconica_image_picker.ImagePicker(
imagePickerService: serviceMock,
),
),
),
);
Finder finder = find.byKey(
Key(const iconica_image_picker.ImagePickerTheme().makePhotoText));
var finder = find.byKey(
Key(const iconica_image_picker.ImagePickerTheme().makePhotoText),
);
await tester.tap(finder);
@ -90,38 +102,44 @@ void main() {
});
testWidgets('Image Picker Shows With Custom Theme', (tester) async {
String title = "title";
var title = 'title';
Widget makePhotoIcon = Container(
height: 125,
width: 125,
color: Colors.red,
);
String makePhotoText = "taaaake image";
var makePhotoText = 'taaaake image';
Widget selectImageIcon = Container(
height: 125,
width: 125,
color: Colors.blue,
);
String selectImageText = "seleeeeect image";
String closeButtonText = "Close Dialog!";
var selectImageText = 'seleeeeect image';
var closeButtonText = 'Close Dialog!';
await tester.pumpWidget(MaterialApp(
await tester.pumpWidget(
MaterialApp(
home: Material(
child: iconica_image_picker.ImagePicker(
imagePickerTheme: iconica_image_picker.ImagePickerTheme(
title: title,
makePhotoIcon: makePhotoIcon,
makePhotoText: makePhotoText,
selectImageIcon: selectImageIcon,
selectImageText: selectImageText,
closeButtonText: closeButtonText)))));
child: iconica_image_picker.ImagePicker(
imagePickerTheme: iconica_image_picker.ImagePickerTheme(
title: title,
makePhotoIcon: makePhotoIcon,
makePhotoText: makePhotoText,
selectImageIcon: selectImageIcon,
selectImageText: selectImageText,
closeButtonText: closeButtonText,
),
),
),
),
);
final titleFinder = find.text(title);
final makePhotoIconFinder = find.byWidget(makePhotoIcon);
final makePhotoTextFinder = find.text(makePhotoText);
final selectImageIconFinder = find.byWidget(selectImageIcon);
final selectImageTextFinder = find.text(selectImageText);
final closebuttonTextFinder = find.text(closeButtonText);
var titleFinder = find.text(title);
var makePhotoIconFinder = find.byWidget(makePhotoIcon);
var makePhotoTextFinder = find.text(makePhotoText);
var selectImageIconFinder = find.byWidget(selectImageIcon);
var selectImageTextFinder = find.text(selectImageText);
var closebuttonTextFinder = find.text(closeButtonText);
expect(titleFinder, findsOneWidget);
expect(makePhotoIconFinder, findsOneWidget);