Compare commits

..

No commits in common. "master" and "1.0.5" have entirely different histories.

16 changed files with 167 additions and 167 deletions

View file

@ -1,14 +0,0 @@
name: Iconica Standard Component Documentation Workflow
# Workflow Caller version: 1.0.0
on:
release:
types: [published]
workflow_dispatch:
jobs:
call-iconica-component-documentation-workflow:
uses: Iconica-Development/.github/.github/workflows/component-documentation.yml@master
secrets: inherit
permissions: write-all

4
.gitignore vendored
View file

@ -31,7 +31,3 @@ build/
coverage/
/.flutter-plugins
/.flutter-plugins-dependencies
# FVM Version Cache
.fvm/
.fvmrc

View file

@ -32,19 +32,3 @@
## 1.0.5 - February 7th 2024
- Added CI and linter
## 2.0.0 - February 22nd 2024
- Simplified the ImagePickerTheme
# 3.0.0 - February 22nd 2024
- Removed customButton from ImagePicker.
# 4.0.0
* Added title options to theme.
* updated iconica_analysis dependency.
* Updated default theme.
# 4.1.0
* Added support for handling errors when calling `pickImage`.

View file

@ -11,9 +11,7 @@ void main() {
}
class ImagePickerExample extends StatelessWidget {
const ImagePickerExample({
super.key,
});
const ImagePickerExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
@ -29,10 +27,8 @@ class ImagePickerExample extends StatelessWidget {
}
class ImagePickerExampleHomePage extends StatefulWidget {
const ImagePickerExampleHomePage({
required this.title,
super.key,
});
const ImagePickerExampleHomePage({Key? key, required this.title})
: super(key: key);
final String title;
@ -116,13 +112,7 @@ class ImagePickerExampleHomePageState
Uint8List? imageInBytes = await showModalBottomSheet<Uint8List?>(
context: context,
backgroundColor: Colors.white,
builder: (BuildContext context) => ImagePicker(
onError: (error) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(error.message ?? "An error occurred")),
);
},
));
builder: (BuildContext context) => const ImagePicker());
if (imageInBytes != null) {
if (!listEquals(uploadedImage, imageInBytes)) {
setState(() {

View file

@ -6,10 +6,6 @@
#include "generated_plugin_registrant.h"
#include <file_selector_linux/file_selector_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
}

View file

@ -3,7 +3,6 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST

View file

@ -5,8 +5,6 @@
import FlutterMacOS
import Foundation
import file_selector_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
}

View file

@ -6,9 +6,6 @@
#include "generated_plugin_registrant.h"
#include <file_selector_windows/file_selector_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
}

View file

@ -3,7 +3,6 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
file_selector_windows
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST

View file

@ -4,7 +4,7 @@
///
library flutter_image_picker;
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";
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

@ -2,32 +2,65 @@
//
// SPDX-License-Identifier: BSD-3-Clause
import "package:flutter/material.dart";
import 'package:flutter/material.dart';
class ImagePickerTheme {
/// The [ImagePickerTheme] is used to style the [ImagePicker].
const ImagePickerTheme({
this.font = 'Roboto',
this.title = 'Upload Image',
this.titleTextSize = 20,
this.titleColor = Colors.black,
this.titleBackgroundColor = Colors.white,
this.titleAlignment = TextAlign.left,
this.textColor = Colors.black,
this.iconColor = Colors.black,
this.iconSize = 125,
this.iconTextSize = 15,
this.spaceBetweenIcons = 30,
this.makePhotoIcon,
this.makePhotoText = "TAKE PICTURE",
this.makePhotoText = 'Take a Picture',
this.selectImageIcon,
this.selectImageText = "UPLOAD FILE",
this.iconTextStyle,
this.closeButtonBuilder,
this.title = "Do you want to upload a file or take a picture?",
this.titleStyle,
this.titleAlignment = TextAlign.center,
this.selectImageText = 'Select File',
this.closeButtonText = 'Close',
this.closeButtonTextSize = 15,
this.closeButtonTextColor = Colors.white,
this.closeButtonWidth = 300,
this.closeButtonHeight = 40,
this.closeButtonBackgroundColor = Colors.black,
});
/// The font that's used in the Image Picker
final String font;
/// The title displayed at the top of the Image Picker Dialog.
final String title;
/// The font size of the title mentioned above.
final double titleTextSize;
/// The color of the title text.
final Color titleColor;
/// The color of the title background.
final Color titleBackgroundColor;
/// The alignment of the title text.
final TextAlign titleAlignment;
/// The color of the icons
final Color iconColor;
/// The color of the text in the Image Picker Dialog
final Color textColor;
/// The size of the icons that are visible in the Image Picker Dialog.
final double iconSize;
/// The font size of the text underneath the icon buttons.
final double iconTextSize;
/// The size of the space between the two icons in the Image Picker Dialog.
final double spaceBetweenIcons;
@ -46,13 +79,24 @@ class ImagePickerTheme {
/// icon.
final String selectImageText;
final TextStyle? iconTextStyle;
/// The text that is shown on the 'Close Dialog' button at the bottom of the
/// Image Picker Dialog.
final String closeButtonText;
final Widget Function(Function() onTap)? closeButtonBuilder;
/// The fontsize of the text of the close button of the Image Picker Dialog.
final double closeButtonTextSize;
final String title;
/// The color of the text of the close button of the Image Picker Dialog.
final Color closeButtonTextColor;
final TextStyle? titleStyle;
/// The width of the 'Close Dialog' button at the bottom of the Image Picker
/// Dialog.
final double closeButtonWidth;
final TextAlign titleAlignment;
/// 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.
final Color closeButtonBackgroundColor;
}

View file

@ -2,9 +2,9 @@
//
// SPDX-License-Identifier: BSD-3-Clause
import "dart:typed_data";
import "package:flutter_image_picker/src/models/image_picker_config.dart";
import "package:image_picker/image_picker.dart";
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.

View file

@ -2,10 +2,9 @@
//
// SPDX-License-Identifier: BSD-3-Clause
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:flutter_image_picker/flutter_image_picker.dart";
import "package:image_picker/image_picker.dart";
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
@ -19,95 +18,99 @@ import "package:image_picker/image_picker.dart";
/// The fourth one is a custom Button widget.
class ImagePicker extends StatelessWidget {
const ImagePicker({
this.theme = const ImagePickerTheme(),
this.config = const ImagePickerConfig(),
this.service,
this.onError,
this.imagePickerTheme = const ImagePickerTheme(),
this.imagePickerConfig = const ImagePickerConfig(),
this.imagePickerService,
this.customButton,
super.key,
});
/// ImagePickerTheme can be used to change the UI of the Image Picker Widget to change the text/icons to your liking.
final ImagePickerTheme theme;
final ImagePickerTheme imagePickerTheme;
/// ImagePickerConfig can be used to define the size and quality for the
/// uploaded image.
final ImagePickerConfig config;
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.
final ImagePickerService? service;
final Function(PlatformException error)? onError;
final ImagePickerService? imagePickerService;
@override
Widget build(BuildContext context) => SingleChildScrollView(
child: Column(
children: <Widget>[
ListTile(
tileColor: imagePickerTheme.titleBackgroundColor,
title: Text(
theme.title,
style:
theme.titleStyle ?? Theme.of(context).textTheme.titleMedium,
textAlign: theme.titleAlignment,
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,
theme.selectImageIcon,
theme,
imagePickerTheme.selectImageIcon,
imagePickerTheme,
Icons.image,
ImageSource.gallery,
theme.selectImageText,
onError,
imagePickerTheme.selectImageText,
),
if (config.cameraOption ?? true) ...[
if (imagePickerConfig.cameraOption ?? true) ...[
SizedBox(
width: theme.spaceBetweenIcons,
width: imagePickerTheme.spaceBetweenIcons,
),
_generateIconButtonWithText(
context,
theme.makePhotoIcon,
theme,
imagePickerTheme.makePhotoIcon,
imagePickerTheme,
Icons.camera_alt_rounded,
ImageSource.camera,
theme.makePhotoText,
onError,
imagePickerTheme.makePhotoText,
),
],
],
),
if (theme.closeButtonBuilder != null) ...[
theme.closeButtonBuilder!.call(
() => Navigator.of(context).pop(),
),
] else ...[
const SizedBox(height: 30),
Center(
child: SizedBox(
width: 300,
height: 40,
child: ElevatedButton(
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: imagePickerTheme.closeButtonWidth,
height: imagePickerTheme.closeButtonHeight,
child: customButton ??
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black,
backgroundColor:
imagePickerTheme.closeButtonBackgroundColor,
),
onPressed: () => Navigator.of(context).pop(),
child: const Text(
"Close",
child: Text(
imagePickerTheme.closeButtonText,
style: TextStyle(
fontSize: 15,
color: Colors.white,
fontFamily: imagePickerTheme.font,
fontSize: imagePickerTheme.closeButtonTextSize,
color: imagePickerTheme.closeButtonTextColor,
),
),
),
),
],
),
const SizedBox(height: 30),
],
],
),
);
@ -131,7 +134,6 @@ class ImagePicker extends StatelessWidget {
IconData icon,
ImageSource imageSource,
String bottomText,
Function(PlatformException error)? onError,
) =>
Column(
mainAxisSize: MainAxisSize.min,
@ -140,14 +142,9 @@ class ImagePicker extends StatelessWidget {
key: Key(bottomText),
onTap: () async {
var navigator = Navigator.of(context);
Uint8List? image;
try {
image = await (service ?? ImagePickerServiceDefault())
.pickImage(imageSource, config: config);
} on PlatformException catch (e) {
debugPrint("image_picker_error: $e");
onError?.call(e);
}
var image =
await (imagePickerService ?? ImagePickerServiceDefault())
.pickImage(imageSource, config: imagePickerConfig);
navigator.pop(image);
},
child: customIcon ??
@ -159,8 +156,13 @@ class ImagePicker extends StatelessWidget {
),
Text(
bottomText,
style: theme.iconTextStyle,
style: TextStyle(
fontFamily: imagePickerTheme.font,
fontSize: imagePickerTheme.iconTextSize,
color: imagePickerTheme.textColor,
),
),
const SizedBox(height: 20),
],
);
}

View file

@ -1,18 +1,16 @@
name: flutter_image_picker
description: A Flutter Image Picking package.
version: 4.1.0
version: 1.0.5
repository: https://github.com/Iconica-Development/flutter_image_picker
publish_to: https://forgejo.internal.iconica.nl/api/packages/internal/pub
environment:
sdk: ">=3.0.0 <4.0.0"
sdk: ">=2.17.6 <3.0.0"
flutter: ">=1.17.0"
dependencies:
flutter:
sdk: flutter
image_picker: ^1.1.2
image_picker: ^1.0.7
dev_dependencies:
flutter_test:
@ -21,4 +19,6 @@ dev_dependencies:
flutter_iconica_analysis:
git:
url: https://github.com/Iconica-Development/flutter_iconica_analysis
ref: 7.0.0
ref: 6.0.0
flutter:

View file

@ -2,22 +2,22 @@
//
// SPDX-License-Identifier: BSD-3-Clause
import "dart:typed_data";
import 'dart:typed_data';
import "package:flutter/material.dart";
import "package:flutter_image_picker/flutter_image_picker.dart"
import 'package:flutter/material.dart';
import 'package:flutter_image_picker/flutter_image_picker.dart'
as iconica_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 '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";
import 'mocks/image_picker_service_mock.dart';
void main() {
var cameraImage = Uint8List(10);
var galleryImage = Uint8List(44);
testWidgets("Image Picker Shows With Normal Theme", (tester) async {
testWidgets('Image Picker Shows With Normal Theme', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Material(
@ -26,14 +26,18 @@ void main() {
),
);
var titleFinder =
find.text(const iconica_image_picker.ImagePickerTheme().title);
var makePhotoIconFinder = find.byIcon(Icons.camera_alt_rounded);
var makePhotoTextFinder =
find.text(const iconica_image_picker.ImagePickerTheme().makePhotoText);
var selectImageIconFinder = find.byIcon(Icons.image);
var selectImageTextFinder = find
.text(const iconica_image_picker.ImagePickerTheme().selectImageText);
var closebuttonTextFinder = find.text("Close");
var closebuttonTextFinder = find
.text(const iconica_image_picker.ImagePickerTheme().closeButtonText);
expect(titleFinder, findsOneWidget);
expect(makePhotoIconFinder, findsOneWidget);
expect(makePhotoTextFinder, findsOneWidget);
expect(selectImageIconFinder, findsOneWidget);
@ -42,7 +46,7 @@ void main() {
});
testWidgets(
"Image Picker Calls Function Correctly When ImageSource Is Gallery",
'Image Picker Calls Function Correctly When ImageSource Is Gallery',
(tester) async {
var serviceMock = ImagePickerServiceMock();
@ -53,7 +57,7 @@ void main() {
MaterialApp(
home: Material(
child: iconica_image_picker.ImagePicker(
service: serviceMock,
imagePickerService: serviceMock,
),
),
),
@ -70,7 +74,7 @@ void main() {
});
testWidgets(
"Image Picker Calls Function Correctly When ImageSource Is Camera",
'Image Picker Calls Function Correctly When ImageSource Is Camera',
(tester) async {
var serviceMock = ImagePickerServiceMock();
@ -81,7 +85,7 @@ void main() {
MaterialApp(
home: Material(
child: iconica_image_picker.ImagePicker(
service: serviceMock,
imagePickerService: serviceMock,
),
),
),
@ -97,42 +101,47 @@ void main() {
.called(1);
});
testWidgets("Image Picker Shows With Custom Theme", (tester) async {
testWidgets('Image Picker Shows With Custom Theme', (tester) async {
var title = 'title';
Widget makePhotoIcon = Container(
height: 125,
width: 125,
color: Colors.red,
);
var makePhotoText = "taaaake image";
var makePhotoText = 'taaaake image';
Widget selectImageIcon = Container(
height: 125,
width: 125,
color: Colors.blue,
);
var selectImageText = "seleeeeect image";
var closeButtonText = "Close";
var selectImageText = 'seleeeeect image';
var closeButtonText = 'Close Dialog!';
await tester.pumpWidget(
MaterialApp(
home: Material(
child: iconica_image_picker.ImagePicker(
theme: iconica_image_picker.ImagePickerTheme(
imagePickerTheme: iconica_image_picker.ImagePickerTheme(
title: title,
makePhotoIcon: makePhotoIcon,
makePhotoText: makePhotoText,
selectImageIcon: selectImageIcon,
selectImageText: selectImageText,
closeButtonText: 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);
expect(makePhotoTextFinder, findsOneWidget);
expect(selectImageIconFinder, findsOneWidget);

View file

@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: BSD-3-Clause
import "package:flutter_image_picker/src/services/image_picker_service.dart";
import "package:mocktail/mocktail.dart";
import 'package:flutter_image_picker/src/services/image_picker_service.dart';
import 'package:mocktail/mocktail.dart';
class ImagePickerServiceMock extends Mock implements ImagePickerService {}