-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAINTROID-455 Add Color Picker (#40)
* Add Color Picker * Implement color picker * Fix issues * Merge with develop * Fix issues * Resolve pubspec errors * address requested changes * fix minor issues * refactoring and minor fixes * use checkerboardimg from component_library * fix minor issues * revert app_localizations file * add dynamic color change, separate colorpicker package * use riverpod generator * fix lint errors * add tests * fix riverpod issues, remove redundancies * remove comments, capitalize text * convert stateful to stateless, rename widgets * address changes, remove slider position state provider * fix minor issues * debug test error * Revert "debug test error" This reverts commit e8a6e03. * debug test error * fix test error * resolve conflicts * sort imports, remove duplicates * fix lint errors * use paintroid theme colors * fix minor issues * fix lint errors * fix background color * fix test error, minor refactoring * minor fixes * fix pubspec.lock * update makefile to run pub get in packages * minor changes * fix dependency
- Loading branch information
1 parent
17577d1
commit ae20a51
Showing
29 changed files
with
939 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: "9e1c857886f07d342cf106f2cd588bcd5e031bb2" | ||
channel: "stable" | ||
|
||
project_type: package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
include: package:flutter_lints/flutter.yaml | ||
linter: | ||
rules: | ||
always_use_package_imports: true | ||
avoid_relative_lib_imports: true | ||
prefer_relative_imports: false | ||
prefer_single_quotes: true | ||
avoid_void_async: true | ||
constant_identifier_names: false | ||
|
||
analyzer: | ||
errors: | ||
missing_enum_constant_in_switch: error | ||
exhaustive_cases: error | ||
unused_element: error | ||
type_annotate_public_apis: error | ||
missing_required_param: error | ||
invalid_use_of_protected_member: error | ||
unused_import: error | ||
|
||
exclude: | ||
- lib/src/**.pb*.dart | ||
- lib/src/data/*.g.dart |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
library colorpicker; | ||
|
||
export 'src/colorpicker.dart'; | ||
export 'src/constants/colors.dart'; | ||
export 'src/components/color_comparison.dart'; | ||
export 'src/components/opacity_slider.dart'; | ||
export 'src/components/slider_indicator_shape.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import 'package:colorpicker/src/components/checkerboard_square.dart'; | ||
import 'package:colorpicker/src/components/color_square.dart'; | ||
import 'package:colorpicker/src/constants/colors.dart'; | ||
import 'package:colorpicker/src/components/color_comparison.dart'; | ||
import 'package:colorpicker/src/components/opacity_slider.dart'; | ||
import 'package:colorpicker/src/state/color_picker_state_provider.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class ColorPicker extends ConsumerWidget { | ||
const ColorPicker({ | ||
super.key, | ||
required this.currentColor, | ||
required this.onColorChanged, | ||
}); | ||
|
||
final Color currentColor; | ||
final void Function(Color) onColorChanged; | ||
|
||
final colors = DisplayColors.colors; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final colorPickerStateData = ref.watch(colorPickerStateProvider); | ||
return Container( | ||
margin: const EdgeInsets.all(26.0), | ||
alignment: Alignment.center, | ||
decoration: BoxDecoration( | ||
borderRadius: BorderRadius.circular(16.0), | ||
), | ||
child: SingleChildScrollView( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
children: [ | ||
ColorComparison( | ||
currentColor: currentColor, | ||
newColor: colorPickerStateData.currentColor != null | ||
? colorPickerStateData.currentColor!.withOpacity( | ||
colorPickerStateData.currentOpacity, | ||
) | ||
: currentColor, | ||
), | ||
const SizedBox(height: 10.0), | ||
GridView.count( | ||
childAspectRatio: 1.4, | ||
crossAxisCount: 4, | ||
crossAxisSpacing: 2.0, | ||
mainAxisSpacing: 2.0, | ||
shrinkWrap: true, | ||
children: List.generate( | ||
colors.length + 1, | ||
(index) { | ||
if (index == colors.length) { | ||
return const CheckerboardSquare(); | ||
} else { | ||
return ColorSquare(color: colors[index]); | ||
} | ||
}, | ||
), | ||
), | ||
const SizedBox(height: 20.0), | ||
OpacitySlider( | ||
gradientColor: colorPickerStateData.currentColor != null | ||
? colorPickerStateData.currentColor! | ||
: currentColor, | ||
), | ||
const SizedBox(height: 20.0), | ||
Row( | ||
children: [ | ||
const Spacer(), | ||
TextButton( | ||
onPressed: () { | ||
Navigator.pop(context); | ||
}, | ||
child: const Text('CANCEL'), | ||
), | ||
const SizedBox(width: 10.0), | ||
TextButton( | ||
onPressed: () { | ||
if (colorPickerStateData.currentColor != null) { | ||
onColorChanged(colorPickerStateData.currentColor! | ||
.withOpacity(colorPickerStateData.currentOpacity)); | ||
} | ||
Navigator.pop(context); | ||
}, | ||
child: const Text('APPLY'), | ||
), | ||
], | ||
) | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/colorpicker/lib/src/components/checkerboard_square.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:colorpicker/utils/assets.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class CheckerboardSquare extends StatelessWidget { | ||
const CheckerboardSquare({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
decoration: BoxDecoration( | ||
image: DecorationImage( | ||
image: PackageAssets.getCheckerboardImgAsset(), | ||
fit: BoxFit.contain, | ||
repeat: ImageRepeat.repeat, | ||
), | ||
), | ||
); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
packages/colorpicker/lib/src/components/color_comparison.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import 'package:colorpicker/utils/assets.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class ColorComparison extends StatelessWidget { | ||
const ColorComparison({ | ||
super.key, | ||
required this.currentColor, | ||
required this.newColor, | ||
}); | ||
|
||
final Color currentColor; | ||
final Color newColor; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SizedBox( | ||
width: 130.0, | ||
height: 70.0, | ||
child: Row( | ||
children: [ | ||
Expanded( | ||
child: ColorDescription( | ||
color: currentColor, | ||
description: 'current', | ||
), | ||
), | ||
Expanded( | ||
child: ColorDescription( | ||
color: newColor, | ||
description: 'new', | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} | ||
|
||
class ColorDescription extends StatelessWidget { | ||
const ColorDescription({ | ||
super.key, | ||
required this.color, | ||
required this.description, | ||
}); | ||
|
||
final Color color; | ||
final String description; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
Expanded( | ||
child: Container( | ||
decoration: BoxDecoration( | ||
image: DecorationImage( | ||
image: PackageAssets.getCheckerboardImgAsset(), | ||
repeat: ImageRepeat.repeat, | ||
), | ||
), | ||
child: Container( | ||
decoration: BoxDecoration( | ||
color: color, | ||
), | ||
), | ||
), | ||
), | ||
const SizedBox(width: 8.0), | ||
Text( | ||
description, | ||
style: const TextStyle(color: Color.fromARGB(255, 149, 149, 149)), | ||
), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.