From 5bfc0ed7e58c369cac9d102b492d581ce8df9495 Mon Sep 17 00:00:00 2001 From: Jacques Doeleman Date: Mon, 26 Sep 2022 12:00:55 +0200 Subject: [PATCH] Icons can be changed with a Widget Previously only done with IconData --- .flutter-plugins | 10 ++--- .flutter-plugins-dependencies | 2 +- example/ios/Flutter/Debug.xcconfig | 1 + example/ios/Flutter/Release.xcconfig | 1 + example/ios/Podfile | 41 +++++++++++++++++++ example/lib/main.dart | 4 +- example/macos/Flutter/Flutter-Debug.xcconfig | 1 + .../macos/Flutter/Flutter-Release.xcconfig | 1 + example/macos/Podfile | 40 ++++++++++++++++++ example/pubspec.lock | 2 +- lib/src/models/image_picker_theme.dart | 8 ++-- lib/src/ui/image_picker.dart | 20 +++++---- pubspec.yaml | 2 +- test/image_picker_ui_test.dart | 31 +++++++++----- 14 files changed, 134 insertions(+), 30 deletions(-) create mode 100644 example/ios/Podfile create mode 100644 example/macos/Podfile diff --git a/.flutter-plugins b/.flutter-plugins index ba41590..c72bff8 100644 --- a/.flutter-plugins +++ b/.flutter-plugins @@ -1,6 +1,6 @@ # This is a generated file; do not edit or check into version control. -flutter_plugin_android_lifecycle=C:\\src\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\flutter_plugin_android_lifecycle-2.0.7\\ -image_picker=C:\\src\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\image_picker-0.8.5+3\\ -image_picker_android=C:\\src\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\image_picker_android-0.8.5+2\\ -image_picker_for_web=C:\\src\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\image_picker_for_web-2.1.8\\ -image_picker_ios=C:\\src\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\image_picker_ios-0.8.5+6\\ +flutter_plugin_android_lifecycle=/Users/jacquesdoeleman/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-2.0.7/ +image_picker=/Users/jacquesdoeleman/.pub-cache/hosted/pub.dartlang.org/image_picker-0.8.5+3/ +image_picker_android=/Users/jacquesdoeleman/.pub-cache/hosted/pub.dartlang.org/image_picker_android-0.8.5+3/ +image_picker_for_web=/Users/jacquesdoeleman/.pub-cache/hosted/pub.dartlang.org/image_picker_for_web-2.1.8/ +image_picker_ios=/Users/jacquesdoeleman/.pub-cache/hosted/pub.dartlang.org/image_picker_ios-0.8.6/ diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 66fb640..fe05007 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker_ios","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker_ios-0.8.5+6\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_plugin_android_lifecycle-2.0.7\\\\","native_build":true,"dependencies":[]},{"name":"image_picker_android","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker_android-0.8.5+2\\\\","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"image_picker_for_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker_for_web-2.1.8\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["image_picker_android","image_picker_for_web","image_picker_ios"]},{"name":"image_picker_android","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"image_picker_ios","dependencies":[]}],"date_created":"2022-09-05 15:20:35.995199","version":"3.3.0"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker_ios","path":"/Users/jacquesdoeleman/.pub-cache/hosted/pub.dartlang.org/image_picker_ios-0.8.6/","native_build":true,"dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/jacquesdoeleman/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-2.0.7/","native_build":true,"dependencies":[]},{"name":"image_picker_android","path":"/Users/jacquesdoeleman/.pub-cache/hosted/pub.dartlang.org/image_picker_android-0.8.5+3/","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"image_picker_for_web","path":"/Users/jacquesdoeleman/.pub-cache/hosted/pub.dartlang.org/image_picker_for_web-2.1.8/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["image_picker_android","image_picker_for_web","image_picker_ios"]},{"name":"image_picker_android","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"image_picker_ios","dependencies":[]}],"date_created":"2022-09-26 11:53:42.232286","version":"3.3.2"} \ No newline at end of file diff --git a/example/ios/Flutter/Debug.xcconfig b/example/ios/Flutter/Debug.xcconfig index 592ceee..ec97fc6 100644 --- a/example/ios/Flutter/Debug.xcconfig +++ b/example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/example/ios/Flutter/Release.xcconfig b/example/ios/Flutter/Release.xcconfig index 592ceee..c4855bf 100644 --- a/example/ios/Flutter/Release.xcconfig +++ b/example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/example/ios/Podfile b/example/ios/Podfile new file mode 100644 index 0000000..88359b2 --- /dev/null +++ b/example/ios/Podfile @@ -0,0 +1,41 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '11.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/example/lib/main.dart b/example/lib/main.dart index 7f2c28e..a66c2d1 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -127,7 +127,9 @@ class ImagePickerExampleHomePageState Uint8List? imageInBytes = await showModalBottomSheet( context: context, backgroundColor: Colors.white, - builder: (BuildContext context) => const ImagePicker()); + builder: (BuildContext context) => const ImagePicker( + imagePickerTheme: ImagePickerTheme(), + )); if (imageInBytes != null) { if (!listEquals(ref.read(imageProvider), imageInBytes)) { ref.read(imageProvider.notifier).changeImage(imageInBytes); diff --git a/example/macos/Flutter/Flutter-Debug.xcconfig b/example/macos/Flutter/Flutter-Debug.xcconfig index c2efd0b..4b81f9b 100644 --- a/example/macos/Flutter/Flutter-Debug.xcconfig +++ b/example/macos/Flutter/Flutter-Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/example/macos/Flutter/Flutter-Release.xcconfig b/example/macos/Flutter/Flutter-Release.xcconfig index c2efd0b..5caa9d1 100644 --- a/example/macos/Flutter/Flutter-Release.xcconfig +++ b/example/macos/Flutter/Flutter-Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/example/macos/Podfile b/example/macos/Podfile new file mode 100644 index 0000000..dade8df --- /dev/null +++ b/example/macos/Podfile @@ -0,0 +1,40 @@ +platform :osx, '10.11' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_macos_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_macos_build_settings(target) + end +end diff --git a/example/pubspec.lock b/example/pubspec.lock index 935c52b..3c87037 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -68,7 +68,7 @@ packages: path: ".." relative: true source: path - version: "0.0.1" + version: "1.0.0" flutter_lints: dependency: "direct dev" description: diff --git a/lib/src/models/image_picker_theme.dart b/lib/src/models/image_picker_theme.dart index 4bd11ca..e7aac6d 100644 --- a/lib/src/models/image_picker_theme.dart +++ b/lib/src/models/image_picker_theme.dart @@ -15,9 +15,9 @@ class ImagePickerTheme { this.iconSize = 125, this.iconTextSize = 15, this.spaceBetweenIcons = 30, - this.makePhotoIcon = Icons.camera_alt_rounded, + this.makePhotoIcon, this.makePhotoText = "Take a Picture", - this.selectImageIcon = Icons.image, + this.selectImageIcon, this.selectImageText = "Select File", this.closeButtonText = "Close", this.closeButtonTextSize = 15, @@ -61,13 +61,13 @@ class ImagePickerTheme { final double spaceBetweenIcons; /// The icon that is displayed for the 'Make Photo' functionality of the Image Picker Dialog. - final IconData makePhotoIcon; + 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. - final IconData selectImageIcon; + final Widget? selectImageIcon; /// The text that is displayed underneath the 'Select Image From Gallery' icon. final String selectImageText; diff --git a/lib/src/ui/image_picker.dart b/lib/src/ui/image_picker.dart index f6db9aa..39030e7 100644 --- a/lib/src/ui/image_picker.dart +++ b/lib/src/ui/image_picker.dart @@ -50,8 +50,9 @@ class ImagePicker extends StatelessWidget { children: [ _generateIconButtonWithText( context, - imagePickerTheme, imagePickerTheme.selectImageIcon, + imagePickerTheme, + Icons.image, ImageSource.gallery, imagePickerTheme.selectImageText), SizedBox( @@ -59,8 +60,9 @@ class ImagePicker extends StatelessWidget { ), _generateIconButtonWithText( context, - imagePickerTheme, imagePickerTheme.makePhotoIcon, + imagePickerTheme, + Icons.camera_alt_rounded, ImageSource.camera, imagePickerTheme.makePhotoText), ], @@ -105,6 +107,7 @@ class ImagePicker extends StatelessWidget { /// [bottomText] The text that's displayed underneath the icon. Column _generateIconButtonWithText( BuildContext context, + Widget? customIcon, ImagePickerTheme imagePickerTheme, IconData icon, ImageSource imageSource, @@ -112,17 +115,20 @@ class ImagePicker extends StatelessWidget { return Column( mainAxisSize: MainAxisSize.min, children: [ - IconButton( + InkWell( key: Key(bottomText), - icon: Icon(icon), - iconSize: imagePickerTheme.iconSize, - color: imagePickerTheme.iconColor, - onPressed: () async { + onTap: () async { final navigator = Navigator.of(context); var image = await (imagePickerService ?? ImagePickerService()) .pickImage(imageSource); navigator.pop(image); }, + child: customIcon ?? + Icon( + icon, + size: imagePickerTheme.iconSize, + color: imagePickerTheme.iconColor, + ), ), Text( bottomText, diff --git a/pubspec.yaml b/pubspec.yaml index 2cdc686..2871c75 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_image_picker description: A new Flutter package project. -version: 0.0.1 +version: 1.0.0 homepage: https://github.com/Iconica-Development/flutter_image_picker environment: diff --git a/test/image_picker_ui_test.dart b/test/image_picker_ui_test.dart index c39aadd..985d25c 100644 --- a/test/image_picker_ui_test.dart +++ b/test/image_picker_ui_test.dart @@ -14,17 +14,20 @@ void main() { Uint8List galleryImage = Uint8List(44); testWidgets('Image Picker Shows With Normal Theme', (tester) async { - await tester.pumpWidget(const MaterialApp( - home: Material(child: iconica_image_picker.ImagePicker()))); + await tester.pumpWidget( + const MaterialApp( + home: Material( + child: iconica_image_picker.ImagePicker(), + ), + ), + ); final titleFinder = find.text(const iconica_image_picker.ImagePickerTheme().title); - final makePhotoIconFinder = find - .byIcon(const iconica_image_picker.ImagePickerTheme().makePhotoIcon); + final makePhotoIconFinder = find.byIcon(Icons.camera_alt_rounded); final makePhotoTextFinder = find.text(const iconica_image_picker.ImagePickerTheme().makePhotoText); - final selectImageIconFinder = find - .byIcon(const iconica_image_picker.ImagePickerTheme().selectImageIcon); + final selectImageIconFinder = find.byIcon(Icons.image); final selectImageTextFinder = find .text(const iconica_image_picker.ImagePickerTheme().selectImageText); final closebuttonTextFinder = find @@ -84,9 +87,17 @@ void main() { testWidgets('Image Picker Shows With Custom Theme', (tester) async { String title = "title"; - IconData makePhotoIcon = Icons.motorcycle; + Widget makePhotoIcon = Container( + height: 125, + width: 125, + color: Colors.red, + ); String makePhotoText = "taaaake image"; - IconData selectImageIcon = Icons.chevron_left; + Widget selectImageIcon = Container( + height: 125, + width: 125, + color: Colors.blue, + ); String selectImageText = "seleeeeect image"; String closeButtonText = "Close Dialog!"; @@ -102,9 +113,9 @@ void main() { closeButtonText: closeButtonText))))); final titleFinder = find.text(title); - final makePhotoIconFinder = find.byIcon(makePhotoIcon); + final makePhotoIconFinder = find.byWidget(makePhotoIcon); final makePhotoTextFinder = find.text(makePhotoText); - final selectImageIconFinder = find.byIcon(selectImageIcon); + final selectImageIconFinder = find.byWidget(selectImageIcon); final selectImageTextFinder = find.text(selectImageText); final closebuttonTextFinder = find.text(closeButtonText);