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/ coverage/
/.flutter-plugins /.flutter-plugins
/.flutter-plugins-dependencies /.flutter-plugins-dependencies
# FVM Version Cache
.fvm/
.fvmrc

View file

@ -32,19 +32,3 @@
## 1.0.5 - February 7th 2024 ## 1.0.5 - February 7th 2024
- Added CI and linter - 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 { class ImagePickerExample extends StatelessWidget {
const ImagePickerExample({ const ImagePickerExample({Key? key}) : super(key: key);
super.key,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -29,10 +27,8 @@ class ImagePickerExample extends StatelessWidget {
} }
class ImagePickerExampleHomePage extends StatefulWidget { class ImagePickerExampleHomePage extends StatefulWidget {
const ImagePickerExampleHomePage({ const ImagePickerExampleHomePage({Key? key, required this.title})
required this.title, : super(key: key);
super.key,
});
final String title; final String title;
@ -116,13 +112,7 @@ class ImagePickerExampleHomePageState
Uint8List? imageInBytes = await showModalBottomSheet<Uint8List?>( Uint8List? imageInBytes = await showModalBottomSheet<Uint8List?>(
context: context, context: context,
backgroundColor: Colors.white, backgroundColor: Colors.white,
builder: (BuildContext context) => ImagePicker( builder: (BuildContext context) => const ImagePicker());
onError: (error) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(error.message ?? "An error occurred")),
);
},
));
if (imageInBytes != null) { if (imageInBytes != null) {
if (!listEquals(uploadedImage, imageInBytes)) { if (!listEquals(uploadedImage, imageInBytes)) {
setState(() { setState(() {

View file

@ -6,10 +6,6 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <file_selector_linux/file_selector_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { 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 list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST

View file

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

View file

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

View file

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

View file

@ -4,7 +4,7 @@
/// ///
library flutter_image_picker; library flutter_image_picker;
export "src/models/image_picker_config.dart"; export 'src/models/image_picker_config.dart';
export "src/models/image_picker_theme.dart"; export 'src/models/image_picker_theme.dart';
export "src/services/image_picker_service.dart"; export 'src/services/image_picker_service.dart';
export "src/ui/image_picker.dart"; export 'src/ui/image_picker.dart';

View file

@ -2,32 +2,65 @@
// //
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
import "package:flutter/material.dart"; import 'package:flutter/material.dart';
class ImagePickerTheme { class ImagePickerTheme {
/// The [ImagePickerTheme] is used to style the [ImagePicker]. /// The [ImagePickerTheme] is used to style the [ImagePicker].
const ImagePickerTheme({ 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.iconColor = Colors.black,
this.iconSize = 125, this.iconSize = 125,
this.iconTextSize = 15,
this.spaceBetweenIcons = 30, this.spaceBetweenIcons = 30,
this.makePhotoIcon, this.makePhotoIcon,
this.makePhotoText = "TAKE PICTURE", this.makePhotoText = 'Take a Picture',
this.selectImageIcon, this.selectImageIcon,
this.selectImageText = "UPLOAD FILE", this.selectImageText = 'Select File',
this.iconTextStyle, this.closeButtonText = 'Close',
this.closeButtonBuilder, this.closeButtonTextSize = 15,
this.title = "Do you want to upload a file or take a picture?", this.closeButtonTextColor = Colors.white,
this.titleStyle, this.closeButtonWidth = 300,
this.titleAlignment = TextAlign.center, 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 /// The color of the icons
final Color iconColor; 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. /// The size of the icons that are visible in the Image Picker Dialog.
final double iconSize; 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. /// The size of the space between the two icons in the Image Picker Dialog.
final double spaceBetweenIcons; final double spaceBetweenIcons;
@ -46,13 +79,24 @@ class ImagePickerTheme {
/// icon. /// icon.
final String selectImageText; 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 // SPDX-License-Identifier: BSD-3-Clause
import "dart:typed_data"; 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 /// The Image Picker Service class is the functionality of the Image Picker
/// package which uses the Image Picker package to choose an image. /// package which uses the Image Picker package to choose an image.

View file

@ -2,10 +2,9 @@
// //
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
import "package:flutter/material.dart"; import 'package:flutter/material.dart';
import "package:flutter/services.dart"; import 'package:flutter_image_picker/flutter_image_picker.dart';
import "package:flutter_image_picker/flutter_image_picker.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 /// 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 /// displayed in your application. If you call the class you can give it 4
@ -19,94 +18,98 @@ 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({
this.theme = const ImagePickerTheme(), this.imagePickerTheme = const ImagePickerTheme(),
this.config = const ImagePickerConfig(), this.imagePickerConfig = const ImagePickerConfig(),
this.service, this.imagePickerService,
this.onError, this.customButton,
super.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 theme; final ImagePickerTheme imagePickerTheme;
/// ImagePickerConfig can be used to define the size and quality for the /// ImagePickerConfig can be used to define the size and quality for the
/// uploaded image. /// 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 /// 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 /// 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. /// add more features. If null the current implementation will be used.
final ImagePickerService? service; final ImagePickerService? imagePickerService;
final Function(PlatformException error)? onError;
@override @override
Widget build(BuildContext context) => SingleChildScrollView( Widget build(BuildContext context) => SingleChildScrollView(
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
ListTile( ListTile(
tileColor: imagePickerTheme.titleBackgroundColor,
title: Text( title: Text(
theme.title, textAlign: imagePickerTheme.titleAlignment,
style: imagePickerTheme.title,
theme.titleStyle ?? Theme.of(context).textTheme.titleMedium, style: TextStyle(
textAlign: theme.titleAlignment, fontFamily: imagePickerTheme.font,
fontSize: imagePickerTheme.titleTextSize,
color: imagePickerTheme.titleColor,
),
), ),
), ),
const SizedBox(height: 20),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
_generateIconButtonWithText( _generateIconButtonWithText(
context, context,
theme.selectImageIcon, imagePickerTheme.selectImageIcon,
theme, imagePickerTheme,
Icons.image, Icons.image,
ImageSource.gallery, ImageSource.gallery,
theme.selectImageText, imagePickerTheme.selectImageText,
onError,
), ),
if (config.cameraOption ?? true) ...[ if (imagePickerConfig.cameraOption ?? true) ...[
SizedBox( SizedBox(
width: theme.spaceBetweenIcons, width: imagePickerTheme.spaceBetweenIcons,
), ),
_generateIconButtonWithText( _generateIconButtonWithText(
context, context,
theme.makePhotoIcon, imagePickerTheme.makePhotoIcon,
theme, imagePickerTheme,
Icons.camera_alt_rounded, Icons.camera_alt_rounded,
ImageSource.camera, ImageSource.camera,
theme.makePhotoText, imagePickerTheme.makePhotoText,
onError,
), ),
], ],
], ],
), ),
if (theme.closeButtonBuilder != null) ...[ const SizedBox(height: 10),
theme.closeButtonBuilder!.call( Row(
() => Navigator.of(context).pop(), mainAxisAlignment: MainAxisAlignment.center,
), children: [
] else ...[ SizedBox(
const SizedBox(height: 30), width: imagePickerTheme.closeButtonWidth,
Center( height: imagePickerTheme.closeButtonHeight,
child: SizedBox( child: customButton ??
width: 300, ElevatedButton(
height: 40, style: ElevatedButton.styleFrom(
child: ElevatedButton( backgroundColor:
style: ElevatedButton.styleFrom( imagePickerTheme.closeButtonBackgroundColor,
backgroundColor: Colors.black, ),
), onPressed: () => Navigator.of(context).pop(),
onPressed: () => Navigator.of(context).pop(), child: Text(
child: const Text( imagePickerTheme.closeButtonText,
"Close", style: TextStyle(
style: TextStyle( fontFamily: imagePickerTheme.font,
fontSize: 15, fontSize: imagePickerTheme.closeButtonTextSize,
color: Colors.white, color: imagePickerTheme.closeButtonTextColor,
),
),
), ),
),
),
), ),
), ],
const SizedBox(height: 30), ),
], const SizedBox(height: 30),
], ],
), ),
); );
@ -131,7 +134,6 @@ class ImagePicker extends StatelessWidget {
IconData icon, IconData icon,
ImageSource imageSource, ImageSource imageSource,
String bottomText, String bottomText,
Function(PlatformException error)? onError,
) => ) =>
Column( Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@ -140,14 +142,9 @@ class ImagePicker extends StatelessWidget {
key: Key(bottomText), key: Key(bottomText),
onTap: () async { onTap: () async {
var navigator = Navigator.of(context); var navigator = Navigator.of(context);
Uint8List? image; var image =
try { await (imagePickerService ?? ImagePickerServiceDefault())
image = await (service ?? ImagePickerServiceDefault()) .pickImage(imageSource, config: imagePickerConfig);
.pickImage(imageSource, config: config);
} on PlatformException catch (e) {
debugPrint("image_picker_error: $e");
onError?.call(e);
}
navigator.pop(image); navigator.pop(image);
}, },
child: customIcon ?? child: customIcon ??
@ -159,8 +156,13 @@ class ImagePicker extends StatelessWidget {
), ),
Text( Text(
bottomText, 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 name: flutter_image_picker
description: A Flutter Image Picking package. description: A Flutter Image Picking package.
version: 4.1.0 version: 1.0.5
repository: https://github.com/Iconica-Development/flutter_image_picker repository: https://github.com/Iconica-Development/flutter_image_picker
publish_to: https://forgejo.internal.iconica.nl/api/packages/internal/pub
environment: environment:
sdk: ">=3.0.0 <4.0.0" sdk: ">=2.17.6 <3.0.0"
flutter: ">=1.17.0" flutter: ">=1.17.0"
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
image_picker: ^1.1.2 image_picker: ^1.0.7
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
@ -21,4 +19,6 @@ dev_dependencies:
flutter_iconica_analysis: flutter_iconica_analysis:
git: git:
url: https://github.com/Iconica-Development/flutter_iconica_analysis 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 // SPDX-License-Identifier: BSD-3-Clause
import "dart:typed_data"; import 'dart:typed_data';
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'
as iconica_image_picker; as iconica_image_picker;
import "package:flutter_test/flutter_test.dart"; import 'package:flutter_test/flutter_test.dart';
import "package:image_picker/image_picker.dart" as image_picker; import 'package:image_picker/image_picker.dart' as image_picker;
import "package:mocktail/mocktail.dart"; import 'package:mocktail/mocktail.dart';
import "mocks/image_picker_service_mock.dart"; import 'mocks/image_picker_service_mock.dart';
void main() { void main() {
var cameraImage = Uint8List(10); var cameraImage = Uint8List(10);
var galleryImage = Uint8List(44); 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( await tester.pumpWidget(
const MaterialApp( const MaterialApp(
home: Material( 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 makePhotoIconFinder = find.byIcon(Icons.camera_alt_rounded);
var makePhotoTextFinder = var makePhotoTextFinder =
find.text(const iconica_image_picker.ImagePickerTheme().makePhotoText); find.text(const iconica_image_picker.ImagePickerTheme().makePhotoText);
var selectImageIconFinder = find.byIcon(Icons.image); var selectImageIconFinder = find.byIcon(Icons.image);
var selectImageTextFinder = find var selectImageTextFinder = find
.text(const iconica_image_picker.ImagePickerTheme().selectImageText); .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(makePhotoIconFinder, findsOneWidget);
expect(makePhotoTextFinder, findsOneWidget); expect(makePhotoTextFinder, findsOneWidget);
expect(selectImageIconFinder, findsOneWidget); expect(selectImageIconFinder, findsOneWidget);
@ -42,7 +46,7 @@ void main() {
}); });
testWidgets( testWidgets(
"Image Picker Calls Function Correctly When ImageSource Is Gallery", 'Image Picker Calls Function Correctly When ImageSource Is Gallery',
(tester) async { (tester) async {
var serviceMock = ImagePickerServiceMock(); var serviceMock = ImagePickerServiceMock();
@ -53,7 +57,7 @@ void main() {
MaterialApp( MaterialApp(
home: Material( home: Material(
child: iconica_image_picker.ImagePicker( child: iconica_image_picker.ImagePicker(
service: serviceMock, imagePickerService: serviceMock,
), ),
), ),
), ),
@ -70,7 +74,7 @@ void main() {
}); });
testWidgets( testWidgets(
"Image Picker Calls Function Correctly When ImageSource Is Camera", 'Image Picker Calls Function Correctly When ImageSource Is Camera',
(tester) async { (tester) async {
var serviceMock = ImagePickerServiceMock(); var serviceMock = ImagePickerServiceMock();
@ -81,7 +85,7 @@ void main() {
MaterialApp( MaterialApp(
home: Material( home: Material(
child: iconica_image_picker.ImagePicker( child: iconica_image_picker.ImagePicker(
service: serviceMock, imagePickerService: serviceMock,
), ),
), ),
), ),
@ -97,42 +101,47 @@ void main() {
.called(1); .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( Widget makePhotoIcon = Container(
height: 125, height: 125,
width: 125, width: 125,
color: Colors.red, color: Colors.red,
); );
var makePhotoText = "taaaake image"; var makePhotoText = 'taaaake image';
Widget selectImageIcon = Container( Widget selectImageIcon = Container(
height: 125, height: 125,
width: 125, width: 125,
color: Colors.blue, color: Colors.blue,
); );
var selectImageText = "seleeeeect image"; var selectImageText = 'seleeeeect image';
var closeButtonText = "Close"; var closeButtonText = 'Close Dialog!';
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Material( home: Material(
child: iconica_image_picker.ImagePicker( child: iconica_image_picker.ImagePicker(
theme: iconica_image_picker.ImagePickerTheme( imagePickerTheme: iconica_image_picker.ImagePickerTheme(
title: title,
makePhotoIcon: makePhotoIcon, makePhotoIcon: makePhotoIcon,
makePhotoText: makePhotoText, makePhotoText: makePhotoText,
selectImageIcon: selectImageIcon, selectImageIcon: selectImageIcon,
selectImageText: selectImageText, selectImageText: selectImageText,
closeButtonText: closeButtonText,
), ),
), ),
), ),
), ),
); );
var titleFinder = find.text(title);
var makePhotoIconFinder = find.byWidget(makePhotoIcon); var makePhotoIconFinder = find.byWidget(makePhotoIcon);
var makePhotoTextFinder = find.text(makePhotoText); var makePhotoTextFinder = find.text(makePhotoText);
var selectImageIconFinder = find.byWidget(selectImageIcon); var selectImageIconFinder = find.byWidget(selectImageIcon);
var selectImageTextFinder = find.text(selectImageText); var selectImageTextFinder = find.text(selectImageText);
var closebuttonTextFinder = find.text(closeButtonText); var closebuttonTextFinder = find.text(closeButtonText);
expect(titleFinder, findsOneWidget);
expect(makePhotoIconFinder, findsOneWidget); expect(makePhotoIconFinder, findsOneWidget);
expect(makePhotoTextFinder, findsOneWidget); expect(makePhotoTextFinder, findsOneWidget);
expect(selectImageIconFinder, findsOneWidget); expect(selectImageIconFinder, findsOneWidget);

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: BSD-3-Clause // 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';
class ImagePickerServiceMock extends Mock implements ImagePickerService {} class ImagePickerServiceMock extends Mock implements ImagePickerService {}