Icons can be changed with a Widget

Previously only done with IconData
This commit is contained in:
Jacques Doeleman 2022-09-26 12:00:55 +02:00
parent ad9595dbd8
commit 5bfc0ed7e5
14 changed files with 134 additions and 30 deletions

View file

@ -1,6 +1,6 @@
# This is a generated file; do not edit or check into version control. # 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\\ flutter_plugin_android_lifecycle=/Users/jacquesdoeleman/.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=/Users/jacquesdoeleman/.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_android=/Users/jacquesdoeleman/.pub-cache/hosted/pub.dartlang.org/image_picker_android-0.8.5+3/
image_picker_for_web=C:\\src\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\image_picker_for_web-2.1.8\\ image_picker_for_web=/Users/jacquesdoeleman/.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\\ image_picker_ios=/Users/jacquesdoeleman/.pub-cache/hosted/pub.dartlang.org/image_picker_ios-0.8.6/

View file

@ -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"} {"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"}

View file

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig" #include "Generated.xcconfig"

View file

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig" #include "Generated.xcconfig"

41
example/ios/Podfile Normal file
View file

@ -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

View file

@ -127,7 +127,9 @@ 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) => const ImagePicker()); builder: (BuildContext context) => const ImagePicker(
imagePickerTheme: ImagePickerTheme(),
));
if (imageInBytes != null) { if (imageInBytes != null) {
if (!listEquals(ref.read(imageProvider), imageInBytes)) { if (!listEquals(ref.read(imageProvider), imageInBytes)) {
ref.read(imageProvider.notifier).changeImage(imageInBytes); ref.read(imageProvider.notifier).changeImage(imageInBytes);

View file

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig"

View file

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig"

40
example/macos/Podfile Normal file
View file

@ -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

View file

@ -68,7 +68,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "0.0.1" version: "1.0.0"
flutter_lints: flutter_lints:
dependency: "direct dev" dependency: "direct dev"
description: description:

View file

@ -15,9 +15,9 @@ class ImagePickerTheme {
this.iconSize = 125, this.iconSize = 125,
this.iconTextSize = 15, this.iconTextSize = 15,
this.spaceBetweenIcons = 30, this.spaceBetweenIcons = 30,
this.makePhotoIcon = Icons.camera_alt_rounded, this.makePhotoIcon,
this.makePhotoText = "Take a Picture", this.makePhotoText = "Take a Picture",
this.selectImageIcon = Icons.image, this.selectImageIcon,
this.selectImageText = "Select File", this.selectImageText = "Select File",
this.closeButtonText = "Close", this.closeButtonText = "Close",
this.closeButtonTextSize = 15, this.closeButtonTextSize = 15,
@ -61,13 +61,13 @@ class ImagePickerTheme {
final double spaceBetweenIcons; 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 IconData makePhotoIcon; final Widget? makePhotoIcon;
/// The text that is displayed underneath the 'Make Photo' icon. /// The text that is displayed underneath the 'Make Photo' icon.
final String makePhotoText; 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 IconData selectImageIcon; 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; final String selectImageText;

View file

@ -50,8 +50,9 @@ class ImagePicker extends StatelessWidget {
children: [ children: [
_generateIconButtonWithText( _generateIconButtonWithText(
context, context,
imagePickerTheme,
imagePickerTheme.selectImageIcon, imagePickerTheme.selectImageIcon,
imagePickerTheme,
Icons.image,
ImageSource.gallery, ImageSource.gallery,
imagePickerTheme.selectImageText), imagePickerTheme.selectImageText),
SizedBox( SizedBox(
@ -59,8 +60,9 @@ class ImagePicker extends StatelessWidget {
), ),
_generateIconButtonWithText( _generateIconButtonWithText(
context, context,
imagePickerTheme,
imagePickerTheme.makePhotoIcon, imagePickerTheme.makePhotoIcon,
imagePickerTheme,
Icons.camera_alt_rounded,
ImageSource.camera, ImageSource.camera,
imagePickerTheme.makePhotoText), imagePickerTheme.makePhotoText),
], ],
@ -105,6 +107,7 @@ class ImagePicker extends StatelessWidget {
/// [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,
ImagePickerTheme imagePickerTheme, ImagePickerTheme imagePickerTheme,
IconData icon, IconData icon,
ImageSource imageSource, ImageSource imageSource,
@ -112,17 +115,20 @@ class ImagePicker extends StatelessWidget {
return Column( return Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
IconButton( InkWell(
key: Key(bottomText), key: Key(bottomText),
icon: Icon(icon), onTap: () async {
iconSize: imagePickerTheme.iconSize,
color: imagePickerTheme.iconColor,
onPressed: () async {
final navigator = Navigator.of(context); final navigator = Navigator.of(context);
var image = await (imagePickerService ?? ImagePickerService()) var image = await (imagePickerService ?? ImagePickerService())
.pickImage(imageSource); .pickImage(imageSource);
navigator.pop(image); navigator.pop(image);
}, },
child: customIcon ??
Icon(
icon,
size: imagePickerTheme.iconSize,
color: imagePickerTheme.iconColor,
),
), ),
Text( Text(
bottomText, bottomText,

View file

@ -1,6 +1,6 @@
name: flutter_image_picker name: flutter_image_picker
description: A new Flutter package project. description: A new Flutter package project.
version: 0.0.1 version: 1.0.0
homepage: https://github.com/Iconica-Development/flutter_image_picker homepage: https://github.com/Iconica-Development/flutter_image_picker
environment: environment:

View file

@ -14,17 +14,20 @@ void main() {
Uint8List galleryImage = Uint8List(44); Uint8List 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( await tester.pumpWidget(
home: Material(child: iconica_image_picker.ImagePicker()))); const MaterialApp(
home: Material(
child: iconica_image_picker.ImagePicker(),
),
),
);
final titleFinder = final titleFinder =
find.text(const iconica_image_picker.ImagePickerTheme().title); find.text(const iconica_image_picker.ImagePickerTheme().title);
final makePhotoIconFinder = find final makePhotoIconFinder = find.byIcon(Icons.camera_alt_rounded);
.byIcon(const iconica_image_picker.ImagePickerTheme().makePhotoIcon);
final makePhotoTextFinder = final makePhotoTextFinder =
find.text(const iconica_image_picker.ImagePickerTheme().makePhotoText); find.text(const iconica_image_picker.ImagePickerTheme().makePhotoText);
final selectImageIconFinder = find final selectImageIconFinder = find.byIcon(Icons.image);
.byIcon(const iconica_image_picker.ImagePickerTheme().selectImageIcon);
final selectImageTextFinder = find final selectImageTextFinder = find
.text(const iconica_image_picker.ImagePickerTheme().selectImageText); .text(const iconica_image_picker.ImagePickerTheme().selectImageText);
final closebuttonTextFinder = find final closebuttonTextFinder = find
@ -84,9 +87,17 @@ void main() {
testWidgets('Image Picker Shows With Custom Theme', (tester) async { testWidgets('Image Picker Shows With Custom Theme', (tester) async {
String title = "title"; String title = "title";
IconData makePhotoIcon = Icons.motorcycle; Widget makePhotoIcon = Container(
height: 125,
width: 125,
color: Colors.red,
);
String makePhotoText = "taaaake image"; String makePhotoText = "taaaake image";
IconData selectImageIcon = Icons.chevron_left; Widget selectImageIcon = Container(
height: 125,
width: 125,
color: Colors.blue,
);
String selectImageText = "seleeeeect image"; String selectImageText = "seleeeeect image";
String closeButtonText = "Close Dialog!"; String closeButtonText = "Close Dialog!";
@ -102,9 +113,9 @@ void main() {
closeButtonText: closeButtonText))))); closeButtonText: closeButtonText)))));
final titleFinder = find.text(title); final titleFinder = find.text(title);
final makePhotoIconFinder = find.byIcon(makePhotoIcon); final makePhotoIconFinder = find.byWidget(makePhotoIcon);
final makePhotoTextFinder = find.text(makePhotoText); final makePhotoTextFinder = find.text(makePhotoText);
final selectImageIconFinder = find.byIcon(selectImageIcon); final selectImageIconFinder = find.byWidget(selectImageIcon);
final selectImageTextFinder = find.text(selectImageText); final selectImageTextFinder = find.text(selectImageText);
final closebuttonTextFinder = find.text(closeButtonText); final closebuttonTextFinder = find.text(closeButtonText);