@ -76,10 +76,14 @@ class HSVWithHueColorPainter extends CustomPainter {
) ;
) ;
canvas . drawCircle (
canvas . drawCircle (
Offset ( size . width * hsvColor . saturation , size . height * ( 1 - hsvColor . value ) ) ,
Offset (
size . width * hsvColor . saturation , size . height * ( 1 - hsvColor . value ) ) ,
size . height * 0.04 ,
size . height * 0.04 ,
Paint ( )
Paint ( )
. . color = pointerColor ? ? ( useWhiteForeground ( hsvColor . toColor ( ) ) ? Colors . white : Colors . black )
. . color = pointerColor ? ?
( useWhiteForeground ( hsvColor . toColor ( ) )
? Colors . white
: Colors . black )
. . strokeWidth = 1.5
. . strokeWidth = 1.5
. . blendMode = BlendMode . luminosity
. . blendMode = BlendMode . luminosity
. . style = PaintingStyle . stroke ,
. . style = PaintingStyle . stroke ,
@ -125,7 +129,10 @@ class HSVWithSaturationColorPainter extends CustomPainter {
) ,
) ,
size . height * 0.04 ,
size . height * 0.04 ,
Paint ( )
Paint ( )
. . color = pointerColor ? ? ( useWhiteForeground ( hsvColor . toColor ( ) ) ? Colors . white : Colors . black )
. . color = pointerColor ? ?
( useWhiteForeground ( hsvColor . toColor ( ) )
? Colors . white
: Colors . black )
. . strokeWidth = 1.5
. . strokeWidth = 1.5
. . style = PaintingStyle . stroke ,
. . style = PaintingStyle . stroke ,
) ;
) ;
@ -174,7 +181,10 @@ class HSVWithValueColorPainter extends CustomPainter {
) ,
) ,
size . height * 0.04 ,
size . height * 0.04 ,
Paint ( )
Paint ( )
. . color = pointerColor ? ? ( useWhiteForeground ( hsvColor . toColor ( ) ) ? Colors . white : Colors . black )
. . color = pointerColor ? ?
( useWhiteForeground ( hsvColor . toColor ( ) )
? Colors . white
: Colors . black )
. . strokeWidth = 1.5
. . strokeWidth = 1.5
. . style = PaintingStyle . stroke ,
. . style = PaintingStyle . stroke ,
) ;
) ;
@ -215,10 +225,14 @@ class HSLWithHueColorPainter extends CustomPainter {
canvas . drawRect ( rect , Paint ( ) . . shader = gradientV . createShader ( rect ) ) ;
canvas . drawRect ( rect , Paint ( ) . . shader = gradientV . createShader ( rect ) ) ;
canvas . drawCircle (
canvas . drawCircle (
Offset ( size . width * hslColor . saturation , size . height * ( 1 - hslColor . lightness ) ) ,
Offset ( size . width * hslColor . saturation ,
size . height * ( 1 - hslColor . lightness ) ) ,
size . height * 0.04 ,
size . height * 0.04 ,
Paint ( )
Paint ( )
. . color = pointerColor ? ? ( useWhiteForeground ( hslColor . toColor ( ) ) ? Colors . white : Colors . black )
. . color = pointerColor ? ?
( useWhiteForeground ( hslColor . toColor ( ) )
? Colors . white
: Colors . black )
. . strokeWidth = 1.5
. . strokeWidth = 1.5
. . style = PaintingStyle . stroke ,
. . style = PaintingStyle . stroke ,
) ;
) ;
@ -263,10 +277,14 @@ class HSLWithSaturationColorPainter extends CustomPainter {
canvas . drawRect ( rect , Paint ( ) . . shader = gradientV . createShader ( rect ) ) ;
canvas . drawRect ( rect , Paint ( ) . . shader = gradientV . createShader ( rect ) ) ;
canvas . drawCircle (
canvas . drawCircle (
Offset ( size . width * hslColor . hue / 360 , size . height * ( 1 - hslColor . lightness ) ) ,
Offset ( size . width * hslColor . hue / 360 ,
size . height * ( 1 - hslColor . lightness ) ) ,
size . height * 0.04 ,
size . height * 0.04 ,
Paint ( )
Paint ( )
. . color = pointerColor ? ? ( useWhiteForeground ( hslColor . toColor ( ) ) ? Colors . white : Colors . black )
. . color = pointerColor ? ?
( useWhiteForeground ( hslColor . toColor ( ) )
? Colors . white
: Colors . black )
. . strokeWidth = 1.5
. . strokeWidth = 1.5
. . style = PaintingStyle . stroke ,
. . style = PaintingStyle . stroke ,
) ;
) ;
@ -308,18 +326,26 @@ class HSLWithLightnessColorPainter extends CustomPainter {
canvas . drawRect ( rect , Paint ( ) . . shader = gradientV . createShader ( rect ) ) ;
canvas . drawRect ( rect , Paint ( ) . . shader = gradientV . createShader ( rect ) ) ;
canvas . drawRect (
canvas . drawRect (
rect ,
rect ,
Paint ( ) . . color = Colors . black . withOpacity ( ( 1 - hslColor . lightness * 2 ) . clamp ( 0 , 1 ) ) ,
Paint ( )
. . color =
Colors . black . withOpacity ( ( 1 - hslColor . lightness * 2 ) . clamp ( 0 , 1 ) ) ,
) ;
) ;
canvas . drawRect (
canvas . drawRect (
rect ,
rect ,
Paint ( ) . . color = Colors . white . withOpacity ( ( ( hslColor . lightness - 0.5 ) * 2 ) . clamp ( 0 , 1 ) ) ,
Paint ( )
. . color = Colors . white
. withOpacity ( ( ( hslColor . lightness - 0.5 ) * 2 ) . clamp ( 0 , 1 ) ) ,
) ;
) ;
canvas . drawCircle (
canvas . drawCircle (
Offset ( size . width * hslColor . hue / 360 , size . height * ( 1 - hslColor . saturation ) ) ,
Offset ( size . width * hslColor . hue / 360 ,
size . height * ( 1 - hslColor . saturation ) ) ,
size . height * 0.04 ,
size . height * 0.04 ,
Paint ( )
Paint ( )
. . color = pointerColor ? ? ( useWhiteForeground ( hslColor . toColor ( ) ) ? Colors . white : Colors . black )
. . color = pointerColor ? ?
( useWhiteForeground ( hslColor . toColor ( ) )
? Colors . white
: Colors . black )
. . strokeWidth = 1.5
. . strokeWidth = 1.5
. . style = PaintingStyle . stroke ,
. . style = PaintingStyle . stroke ,
) ;
) ;
@ -362,10 +388,12 @@ class RGBWithRedColorPainter extends CustomPainter {
) ;
) ;
canvas . drawCircle (
canvas . drawCircle (
Offset ( size . width * color . blue / 255 , size . height * ( 1 - color . green / 255 ) ) ,
Offset (
size . width * color . blue / 255 , size . height * ( 1 - color . green / 255 ) ) ,
size . height * 0.04 ,
size . height * 0.04 ,
Paint ( )
Paint ( )
. . color = pointerColor ? ? ( useWhiteForeground ( color ) ? Colors . white : Colors . black )
. . color = pointerColor ? ?
( useWhiteForeground ( color ) ? Colors . white : Colors . black )
. . strokeWidth = 1.5
. . strokeWidth = 1.5
. . style = PaintingStyle . stroke ,
. . style = PaintingStyle . stroke ,
) ;
) ;
@ -408,10 +436,12 @@ class RGBWithGreenColorPainter extends CustomPainter {
) ;
) ;
canvas . drawCircle (
canvas . drawCircle (
Offset ( size . width * color . blue / 255 , size . height * ( 1 - color . red / 255 ) ) ,
Offset (
size . width * color . blue / 255 , size . height * ( 1 - color . red / 255 ) ) ,
size . height * 0.04 ,
size . height * 0.04 ,
Paint ( )
Paint ( )
. . color = pointerColor ? ? ( useWhiteForeground ( color ) ? Colors . white : Colors . black )
. . color = pointerColor ? ?
( useWhiteForeground ( color ) ? Colors . white : Colors . black )
. . strokeWidth = 1.5
. . strokeWidth = 1.5
. . style = PaintingStyle . stroke ,
. . style = PaintingStyle . stroke ,
) ;
) ;
@ -454,10 +484,12 @@ class RGBWithBlueColorPainter extends CustomPainter {
) ;
) ;
canvas . drawCircle (
canvas . drawCircle (
Offset ( size . width * color . red / 255 , size . height * ( 1 - color . green / 255 ) ) ,
Offset (
size . width * color . red / 255 , size . height * ( 1 - color . green / 255 ) ) ,
size . height * 0.04 ,
size . height * 0.04 ,
Paint ( )
Paint ( )
. . color = pointerColor ? ? ( useWhiteForeground ( color ) ? Colors . white : Colors . black )
. . color = pointerColor ? ?
( useWhiteForeground ( color ) ? Colors . white : Colors . black )
. . strokeWidth = 1.5
. . strokeWidth = 1.5
. . style = PaintingStyle . stroke ,
. . style = PaintingStyle . stroke ,
) ;
) ;
@ -496,18 +528,26 @@ class HUEColorWheelPainter extends CustomPainter {
Color ( 0x00FFFFFF ) ,
Color ( 0x00FFFFFF ) ,
] ,
] ,
) ;
) ;
canvas . drawCircle ( center , radio , Paint ( ) . . shader = gradientS . createShader ( rect ) ) ;
canvas . drawCircle (
canvas . drawCircle ( center , radio , Paint ( ) . . shader = gradientR . createShader ( rect ) ) ;
center , radio , Paint ( ) . . shader = gradientS . createShader ( rect ) ) ;
canvas . drawCircle ( center , radio , Paint ( ) . . color = Colors . black . withOpacity ( 1 - hsvColor . value ) ) ;
canvas . drawCircle (
center , radio , Paint ( ) . . shader = gradientR . createShader ( rect ) ) ;
canvas . drawCircle ( center , radio ,
Paint ( ) . . color = Colors . black . withOpacity ( 1 - hsvColor . value ) ) ;
canvas . drawCircle (
canvas . drawCircle (
Offset (
Offset (
center . dx + hsvColor . saturation * radio * cos ( ( hsvColor . hue * pi / 180 ) ) ,
center . dx +
center . dy - hsvColor . saturation * radio * sin ( ( hsvColor . hue * pi / 180 ) ) ,
hsvColor . saturation * radio * cos ( ( hsvColor . hue * pi / 180 ) ) ,
center . dy -
hsvColor . saturation * radio * sin ( ( hsvColor . hue * pi / 180 ) ) ,
) ,
) ,
size . height * 0.04 ,
size . height * 0.04 ,
Paint ( )
Paint ( )
. . color = pointerColor ? ? ( useWhiteForeground ( hsvColor . toColor ( ) ) ? Colors . white : Colors . black )
. . color = pointerColor ? ?
( useWhiteForeground ( hsvColor . toColor ( ) )
? Colors . white
: Colors . black )
. . strokeWidth = 1.5
. . strokeWidth = 1.5
. . style = PaintingStyle . stroke ,
. . style = PaintingStyle . stroke ,
) ;
) ;
@ -519,7 +559,8 @@ class HUEColorWheelPainter extends CustomPainter {
/ / / Painter for hue ring .
/ / / Painter for hue ring .
class HueRingPainter extends CustomPainter {
class HueRingPainter extends CustomPainter {
const HueRingPainter ( this . hsvColor , { this . displayThumbColor = true , this . strokeWidth = 5 } ) ;
const HueRingPainter ( this . hsvColor ,
{ this . displayThumbColor = true , this . strokeWidth = 5 } ) ;
final HSVColor hsvColor ;
final HSVColor hsvColor ;
final bool displayThumbColor ;
final bool displayThumbColor ;
@ -553,7 +594,11 @@ class HueRingPainter extends CustomPainter {
center . dx + radio * cos ( ( hsvColor . hue * pi / 180 ) ) ,
center . dx + radio * cos ( ( hsvColor . hue * pi / 180 ) ) ,
center . dy - radio * sin ( ( hsvColor . hue * pi / 180 ) ) ,
center . dy - radio * sin ( ( hsvColor . hue * pi / 180 ) ) ,
) ;
) ;
canvas . drawShadow ( Path ( ) . . addOval ( Rect . fromCircle ( center: offset , radius: 12 ) ) , Colors . black , 3.0 , true ) ;
canvas . drawShadow (
Path ( ) . . addOval ( Rect . fromCircle ( center: offset , radius: 12 ) ) ,
Colors . black ,
3.0 ,
true ) ;
canvas . drawCircle (
canvas . drawCircle (
offset ,
offset ,
size . height * 0.04 ,
size . height * 0.04 ,
@ -729,7 +774,8 @@ class ThumbPainter extends CustomPainter {
canvas . drawShadow (
canvas . drawShadow (
Path ( )
Path ( )
. . addOval (
. . addOval (
Rect . fromCircle ( center: const Offset ( 0.5 , 2.0 ) , radius: size . width * 1.8 ) ,
Rect . fromCircle (
center: const Offset ( 0.5 , 2.0 ) , radius: size . width * 1.8 ) ,
) ,
) ,
Colors . black ,
Colors . black ,
3.0 ,
3.0 ,
@ -816,7 +862,11 @@ class ColorPickerLabel extends StatefulWidget {
this . hsvColor , {
this . hsvColor , {
Key ? key ,
Key ? key ,
this . enableAlpha = true ,
this . enableAlpha = true ,
this . colorLabelTypes = const [ ColorLabelType . rgb , ColorLabelType . hsv , ColorLabelType . hsl ] ,
this . colorLabelTypes = const [
ColorLabelType . rgb ,
ColorLabelType . hsv ,
ColorLabelType . hsl
] ,
this . textStyle ,
this . textStyle ,
} ) : assert ( colorLabelTypes . length > 0 ) ,
} ) : assert ( colorLabelTypes . length > 0 ) ,
super ( key: key ) ;
super ( key: key ) ;
@ -885,7 +935,8 @@ class _ColorPickerLabelState extends State<ColorPickerLabel> {
List < Widget > colorValueLabels ( ) {
List < Widget > colorValueLabels ( ) {
double fontSize = 14 ;
double fontSize = 14 ;
if ( widget . textStyle ! = null & & widget . textStyle ? . fontSize ! = null ) fontSize = widget . textStyle ? . fontSize ? ? 14 ;
if ( widget . textStyle ! = null & & widget . textStyle ? . fontSize ! = null )
fontSize = widget . textStyle ? . fontSize ? ? 14 ;
return [
return [
for ( String item in _colorTypes [ _colorType ] ? ? [ ] )
for ( String item in _colorTypes [ _colorType ] ? ? [ ] )
@ -899,14 +950,17 @@ class _ColorPickerLabelState extends State<ColorPickerLabel> {
children: < Widget > [
children: < Widget > [
Text (
Text (
item ,
item ,
style: widget . textStyle ? ? Theme . of ( context ) . textTheme . bodyLarge ,
style: widget . textStyle ? ?
Theme . of ( context ) . textTheme . bodyLarge ,
) ,
) ,
const SizedBox ( height: 10.0 ) ,
const SizedBox ( height: 10.0 ) ,
Expanded (
Expanded (
child: Text (
child: Text (
colorValue ( widget . hsvColor , _colorType ) [ _colorTypes [ _colorType ] ! . indexOf ( item ) ] ,
colorValue ( widget . hsvColor , _colorType ) [
_colorTypes [ _colorType ] ! . indexOf ( item ) ] ,
overflow: TextOverflow . ellipsis ,
overflow: TextOverflow . ellipsis ,
style: widget . textStyle ? ? Theme . of ( context ) . textTheme . bodyMedium ,
style: widget . textStyle ? ?
Theme . of ( context ) . textTheme . bodyMedium ,
) ,
) ,
) ,
) ,
] ,
] ,
@ -977,12 +1031,18 @@ class _ColorPickerInputState extends State<ColorPickerInput> {
widget . color . red . toRadixString ( 16 ) . toUpperCase ( ) . padLeft ( 2 , ' 0 ' ) +
widget . color . red . toRadixString ( 16 ) . toUpperCase ( ) . padLeft ( 2 , ' 0 ' ) +
widget . color . green . toRadixString ( 16 ) . toUpperCase ( ) . padLeft ( 2 , ' 0 ' ) +
widget . color . green . toRadixString ( 16 ) . toUpperCase ( ) . padLeft ( 2 , ' 0 ' ) +
widget . color . blue . toRadixString ( 16 ) . toUpperCase ( ) . padLeft ( 2 , ' 0 ' ) +
widget . color . blue . toRadixString ( 16 ) . toUpperCase ( ) . padLeft ( 2 , ' 0 ' ) +
( widget . enableAlpha ? widget . color . alpha . toRadixString ( 16 ) . toUpperCase ( ) . padLeft ( 2 , ' 0 ' ) : ' ' ) ;
( widget . enableAlpha
? widget . color . alpha
. toRadixString ( 16 )
. toUpperCase ( )
. padLeft ( 2 , ' 0 ' )
: ' ' ) ;
}
}
return Padding (
return Padding (
padding: const EdgeInsets . only ( top: 5.0 ) ,
padding: const EdgeInsets . only ( top: 5.0 ) ,
child: Row ( mainAxisAlignment: MainAxisAlignment . center , children: [
child: Row ( mainAxisAlignment: MainAxisAlignment . center , children: [
if ( ! widget . embeddedText ) Text ( ' Hex ' , style: Theme . of ( context ) . textTheme . bodyLarge ) ,
if ( ! widget . embeddedText )
Text ( ' Hex ' , style: Theme . of ( context ) . textTheme . bodyLarge ) ,
const SizedBox ( width: 10 ) ,
const SizedBox ( width: 10 ) ,
SizedBox (
SizedBox (
width: ( Theme . of ( context ) . textTheme . bodyMedium ? . fontSize ? ? 14 ) * 10 ,
width: ( Theme . of ( context ) . textTheme . bodyMedium ? . fontSize ? ? 14 ) * 10 ,
@ -1001,7 +1061,8 @@ class _ColorPickerInputState extends State<ColorPickerInput> {
onChanged: ( String value ) {
onChanged: ( String value ) {
String input = value ;
String input = value ;
if ( value . length = = 9 ) {
if ( value . length = = 9 ) {
input = value . split ( ' ' ) . getRange ( 7 , 9 ) . join ( ) + value . split ( ' ' ) . getRange ( 1 , 7 ) . join ( ) ;
input = value . split ( ' ' ) . getRange ( 7 , 9 ) . join ( ) +
value . split ( ' ' ) . getRange ( 1 , 7 ) . join ( ) ;
}
}
final Color ? color = colorFromHex ( input ) ;
final Color ? color = colorFromHex ( input ) ;
if ( color ! = null ) {
if ( color ! = null ) {
@ -1035,7 +1096,8 @@ class ColorPickerSlider extends StatelessWidget {
void slideEvent ( RenderBox getBox , BoxConstraints box , Offset globalPosition ) {
void slideEvent ( RenderBox getBox , BoxConstraints box , Offset globalPosition ) {
double localDx = getBox . globalToLocal ( globalPosition ) . dx - 15.0 ;
double localDx = getBox . globalToLocal ( globalPosition ) . dx - 15.0 ;
double progress = localDx . clamp ( 0.0 , box . maxWidth - 30.0 ) / ( box . maxWidth - 30.0 ) ;
double progress =
localDx . clamp ( 0.0 , box . maxWidth - 30.0 ) / ( box . maxWidth - 30.0 ) ;
switch ( trackType ) {
switch ( trackType ) {
case TrackType . hue:
case TrackType . hue:
/ / 360 is the same as zero
/ / 360 is the same as zero
@ -1055,16 +1117,20 @@ class ColorPickerSlider extends StatelessWidget {
onColorChanged ( hslToHsv ( hsvToHsl ( hsvColor ) . withLightness ( progress ) ) ) ;
onColorChanged ( hslToHsv ( hsvToHsl ( hsvColor ) . withLightness ( progress ) ) ) ;
break ;
break ;
case TrackType . red:
case TrackType . red:
onColorChanged ( HSVColor . fromColor ( hsvColor . toColor ( ) . withRed ( ( progress * 0xff ) . round ( ) ) ) ) ;
onColorChanged ( HSVColor . fromColor (
hsvColor . toColor ( ) . withRed ( ( progress * 0xff ) . round ( ) ) ) ) ;
break ;
break ;
case TrackType . green:
case TrackType . green:
onColorChanged ( HSVColor . fromColor ( hsvColor . toColor ( ) . withGreen ( ( progress * 0xff ) . round ( ) ) ) ) ;
onColorChanged ( HSVColor . fromColor (
hsvColor . toColor ( ) . withGreen ( ( progress * 0xff ) . round ( ) ) ) ) ;
break ;
break ;
case TrackType . blue:
case TrackType . blue:
onColorChanged ( HSVColor . fromColor ( hsvColor . toColor ( ) . withBlue ( ( progress * 0xff ) . round ( ) ) ) ) ;
onColorChanged ( HSVColor . fromColor (
hsvColor . toColor ( ) . withBlue ( ( progress * 0xff ) . round ( ) ) ) ) ;
break ;
break ;
case TrackType . alpha:
case TrackType . alpha:
onColorChanged ( hsvColor . withAlpha ( localDx . clamp ( 0.0 , box . maxWidth - 30.0 ) / ( box . maxWidth - 30.0 ) ) ) ;
onColorChanged ( hsvColor . withAlpha (
localDx . clamp ( 0.0 , box . maxWidth - 30.0 ) / ( box . maxWidth - 30.0 ) ) ) ;
break ;
break ;
}
}
}
}
@ -1081,26 +1147,34 @@ class ColorPickerSlider extends StatelessWidget {
break ;
break ;
case TrackType . saturation:
case TrackType . saturation:
thumbOffset + = ( box . maxWidth - 30.0 ) * hsvColor . saturation ;
thumbOffset + = ( box . maxWidth - 30.0 ) * hsvColor . saturation ;
thumbColor = HSVColor . fromAHSV ( 1.0 , hsvColor . hue , hsvColor . saturation , 1.0 ) . toColor ( ) ;
thumbColor =
HSVColor . fromAHSV ( 1.0 , hsvColor . hue , hsvColor . saturation , 1.0 )
. toColor ( ) ;
break ;
break ;
case TrackType . saturationForHSL:
case TrackType . saturationForHSL:
thumbOffset + = ( box . maxWidth - 30.0 ) * hsvToHsl ( hsvColor ) . saturation ;
thumbOffset + = ( box . maxWidth - 30.0 ) * hsvToHsl ( hsvColor ) . saturation ;
thumbColor = HSLColor . fromAHSL ( 1.0 , hsvColor . hue , hsvToHsl ( hsvColor ) . saturation , 0.5 ) . toColor ( ) ;
thumbColor = HSLColor . fromAHSL (
1.0 , hsvColor . hue , hsvToHsl ( hsvColor ) . saturation , 0.5 )
. toColor ( ) ;
break ;
break ;
case TrackType . value:
case TrackType . value:
thumbOffset + = ( box . maxWidth - 30.0 ) * hsvColor . value ;
thumbOffset + = ( box . maxWidth - 30.0 ) * hsvColor . value ;
thumbColor = HSVColor . fromAHSV ( 1.0 , hsvColor . hue , 1.0 , hsvColor . value ) . toColor ( ) ;
thumbColor = HSVColor . fromAHSV ( 1.0 , hsvColor . hue , 1.0 , hsvColor . value )
. toColor ( ) ;
break ;
break ;
case TrackType . lightness:
case TrackType . lightness:
thumbOffset + = ( box . maxWidth - 30.0 ) * hsvToHsl ( hsvColor ) . lightness ;
thumbOffset + = ( box . maxWidth - 30.0 ) * hsvToHsl ( hsvColor ) . lightness ;
thumbColor = HSLColor . fromAHSL ( 1.0 , hsvColor . hue , 1.0 , hsvToHsl ( hsvColor ) . lightness ) . toColor ( ) ;
thumbColor = HSLColor . fromAHSL (
1.0 , hsvColor . hue , 1.0 , hsvToHsl ( hsvColor ) . lightness )
. toColor ( ) ;
break ;
break ;
case TrackType . red:
case TrackType . red:
thumbOffset + = ( box . maxWidth - 30.0 ) * hsvColor . toColor ( ) . red / 0xff ;
thumbOffset + = ( box . maxWidth - 30.0 ) * hsvColor . toColor ( ) . red / 0xff ;
thumbColor = hsvColor . toColor ( ) . withOpacity ( 1.0 ) ;
thumbColor = hsvColor . toColor ( ) . withOpacity ( 1.0 ) ;
break ;
break ;
case TrackType . green:
case TrackType . green:
thumbOffset + = ( box . maxWidth - 30.0 ) * hsvColor . toColor ( ) . green / 0xff ;
thumbOffset + =
( box . maxWidth - 30.0 ) * hsvColor . toColor ( ) . green / 0xff ;
thumbColor = hsvColor . toColor ( ) . withOpacity ( 1.0 ) ;
thumbColor = hsvColor . toColor ( ) . withOpacity ( 1.0 ) ;
break ;
break ;
case TrackType . blue:
case TrackType . blue:
@ -1145,10 +1219,12 @@ class ColorPickerSlider extends StatelessWidget {
builder: ( BuildContext context , BoxConstraints box ) {
builder: ( BuildContext context , BoxConstraints box ) {
RenderBox ? getBox = context . findRenderObject ( ) as RenderBox ? ;
RenderBox ? getBox = context . findRenderObject ( ) as RenderBox ? ;
return GestureDetector (
return GestureDetector (
onPanDown: ( DragDownDetails details ) = >
onPanDown: ( DragDownDetails details ) = > getBox ! = null
getBox ! = null ? slideEvent ( getBox , box , details . globalPosition ) : null ,
? slideEvent ( getBox , box , details . globalPosition )
onPanUpdate: ( DragUpdateDetails details ) = >
: null ,
getBox ! = null ? slideEvent ( getBox , box , details . globalPosition ) : null ,
onPanUpdate: ( DragUpdateDetails details ) = > getBox ! = null
? slideEvent ( getBox , box , details . globalPosition )
: null ,
) ;
) ;
} ,
} ,
) ,
) ,
@ -1212,7 +1288,8 @@ class ColorPickerArea extends StatelessWidget {
onColorChanged ( hsvColor . withHue ( horizontal * 360 ) . withValue ( vertical ) ) ;
onColorChanged ( hsvColor . withHue ( horizontal * 360 ) . withValue ( vertical ) ) ;
break ;
break ;
case PaletteType . hsvWithValue:
case PaletteType . hsvWithValue:
onColorChanged ( hsvColor . withHue ( horizontal * 360 ) . withSaturation ( vertical ) ) ;
onColorChanged (
hsvColor . withHue ( horizontal * 360 ) . withSaturation ( vertical ) ) ;
break ;
break ;
case PaletteType . hsl:
case PaletteType . hsl:
case PaletteType . hslWithHue:
case PaletteType . hslWithHue:
@ -1232,17 +1309,26 @@ class ColorPickerArea extends StatelessWidget {
break ;
break ;
case PaletteType . rgbWithRed:
case PaletteType . rgbWithRed:
onColorChanged ( HSVColor . fromColor (
onColorChanged ( HSVColor . fromColor (
hsvColor . toColor ( ) . withBlue ( ( horizontal * 255 ) . round ( ) ) . withGreen ( ( vertical * 255 ) . round ( ) ) ,
hsvColor
. toColor ( )
. withBlue ( ( horizontal * 255 ) . round ( ) )
. withGreen ( ( vertical * 255 ) . round ( ) ) ,
) ) ;
) ) ;
break ;
break ;
case PaletteType . rgbWithGreen:
case PaletteType . rgbWithGreen:
onColorChanged ( HSVColor . fromColor (
onColorChanged ( HSVColor . fromColor (
hsvColor . toColor ( ) . withBlue ( ( horizontal * 255 ) . round ( ) ) . withRed ( ( vertical * 255 ) . round ( ) ) ,
hsvColor
. toColor ( )
. withBlue ( ( horizontal * 255 ) . round ( ) )
. withRed ( ( vertical * 255 ) . round ( ) ) ,
) ) ;
) ) ;
break ;
break ;
case PaletteType . rgbWithBlue:
case PaletteType . rgbWithBlue:
onColorChanged ( HSVColor . fromColor (
onColorChanged ( HSVColor . fromColor (
hsvColor . toColor ( ) . withRed ( ( horizontal * 255 ) . round ( ) ) . withGreen ( ( vertical * 255 ) . round ( ) ) ,
hsvColor
. toColor ( )
. withRed ( ( horizontal * 255 ) . round ( ) )
. withGreen ( ( vertical * 255 ) . round ( ) ) ,
) ) ;
) ) ;
break ;
break ;
default :
default :
@ -1254,7 +1340,8 @@ class ColorPickerArea extends StatelessWidget {
onColorChanged ( hsvColor . withHue ( hue ) . withSaturation ( radio ) ) ;
onColorChanged ( hsvColor . withHue ( hue ) . withSaturation ( radio ) ) ;
}
}
void _handleGesture ( Offset position , BuildContext context , double height , double width ) {
void _handleGesture (
Offset position , BuildContext context , double height , double width ) {
RenderBox ? getBox = context . findRenderObject ( ) as RenderBox ? ;
RenderBox ? getBox = context . findRenderObject ( ) as RenderBox ? ;
if ( getBox = = null ) return ;
if ( getBox = = null ) return ;
@ -1265,9 +1352,15 @@ class ColorPickerArea extends StatelessWidget {
if ( paletteType = = PaletteType . hueWheel ) {
if ( paletteType = = PaletteType . hueWheel ) {
Offset center = Offset ( width / 2 , height / 2 ) ;
Offset center = Offset ( width / 2 , height / 2 ) ;
double radio = width < = height ? width / 2 : height / 2 ;
double radio = width < = height ? width / 2 : height / 2 ;
double dist = sqrt ( pow ( horizontal - center . dx , 2 ) + pow ( vertical - center . dy , 2 ) ) / radio ;
double dist =
double rad = ( atan2 ( horizontal - center . dx , vertical - center . dy ) / pi + 1 ) / 2 * 360 ;
sqrt ( pow ( horizontal - center . dx , 2 ) + pow ( vertical - center . dy , 2 ) ) /
_handleColorWheelChange ( ( ( rad + 90 ) % 360 ) . clamp ( 0 , 360 ) , dist . clamp ( 0 , 1 ) ) ;
radio ;
double rad =
( atan2 ( horizontal - center . dx , vertical - center . dy ) / pi + 1 ) /
2 *
360 ;
_handleColorWheelChange (
( ( rad + 90 ) % 360 ) . clamp ( 0 , 360 ) , dist . clamp ( 0 , 1 ) ) ;
} else {
} else {
_handleColorRectChange ( horizontal / width , 1 - vertical / height ) ;
_handleColorRectChange ( horizontal / width , 1 - vertical / height ) ;
}
}
@ -1282,12 +1375,16 @@ class ColorPickerArea extends StatelessWidget {
return RawGestureDetector (
return RawGestureDetector (
gestures: {
gestures: {
_AlwaysWinPanGestureRecognizer: GestureRecognizerFactoryWithHandlers < _AlwaysWinPanGestureRecognizer > (
_AlwaysWinPanGestureRecognizer:
GestureRecognizerFactoryWithHandlers <
_AlwaysWinPanGestureRecognizer > (
( ) = > _AlwaysWinPanGestureRecognizer ( ) ,
( ) = > _AlwaysWinPanGestureRecognizer ( ) ,
( _AlwaysWinPanGestureRecognizer instance ) {
( _AlwaysWinPanGestureRecognizer instance ) {
instance
instance
. . onDown = ( ( details ) = > _handleGesture ( details . globalPosition , context , height , width ) )
. . onDown = ( ( details ) = > _handleGesture (
. . onUpdate = ( ( details ) = > _handleGesture ( details . globalPosition , context , height , width ) ) ;
details . globalPosition , context , height , width ) )
. . onUpdate = ( ( details ) = > _handleGesture (
details . globalPosition , context , height , width ) ) ;
} ,
} ,
) ,
) ,
} ,
} ,
@ -1298,22 +1395,32 @@ class ColorPickerArea extends StatelessWidget {
case PaletteType . hsvWithHue:
case PaletteType . hsvWithHue:
return CustomPaint ( painter: HSVWithHueColorPainter ( hsvColor ) ) ;
return CustomPaint ( painter: HSVWithHueColorPainter ( hsvColor ) ) ;
case PaletteType . hsvWithSaturation:
case PaletteType . hsvWithSaturation:
return CustomPaint ( painter: HSVWithSaturationColorPainter ( hsvColor ) ) ;
return CustomPaint (
painter: HSVWithSaturationColorPainter ( hsvColor ) ) ;
case PaletteType . hsvWithValue:
case PaletteType . hsvWithValue:
return CustomPaint ( painter: HSVWithValueColorPainter ( hsvColor ) ) ;
return CustomPaint (
painter: HSVWithValueColorPainter ( hsvColor ) ) ;
case PaletteType . hsl:
case PaletteType . hsl:
case PaletteType . hslWithHue:
case PaletteType . hslWithHue:
return CustomPaint ( painter: HSLWithHueColorPainter ( hsvToHsl ( hsvColor ) ) ) ;
return CustomPaint (
painter: HSLWithHueColorPainter ( hsvToHsl ( hsvColor ) ) ) ;
case PaletteType . hslWithSaturation:
case PaletteType . hslWithSaturation:
return CustomPaint ( painter: HSLWithSaturationColorPainter ( hsvToHsl ( hsvColor ) ) ) ;
return CustomPaint (
painter:
HSLWithSaturationColorPainter ( hsvToHsl ( hsvColor ) ) ) ;
case PaletteType . hslWithLightness:
case PaletteType . hslWithLightness:
return CustomPaint ( painter: HSLWithLightnessColorPainter ( hsvToHsl ( hsvColor ) ) ) ;
return CustomPaint (
painter:
HSLWithLightnessColorPainter ( hsvToHsl ( hsvColor ) ) ) ;
case PaletteType . rgbWithRed:
case PaletteType . rgbWithRed:
return CustomPaint ( painter: RGBWithRedColorPainter ( hsvColor . toColor ( ) ) ) ;
return CustomPaint (
painter: RGBWithRedColorPainter ( hsvColor . toColor ( ) ) ) ;
case PaletteType . rgbWithGreen:
case PaletteType . rgbWithGreen:
return CustomPaint ( painter: RGBWithGreenColorPainter ( hsvColor . toColor ( ) ) ) ;
return CustomPaint (
painter: RGBWithGreenColorPainter ( hsvColor . toColor ( ) ) ) ;
case PaletteType . rgbWithBlue:
case PaletteType . rgbWithBlue:
return CustomPaint ( painter: RGBWithBlueColorPainter ( hsvColor . toColor ( ) ) ) ;
return CustomPaint (
painter: RGBWithBlueColorPainter ( hsvColor . toColor ( ) ) ) ;
case PaletteType . hueWheel:
case PaletteType . hueWheel:
return CustomPaint ( painter: HUEColorWheelPainter ( hsvColor ) ) ;
return CustomPaint ( painter: HUEColorWheelPainter ( hsvColor ) ) ;
default :
default :
@ -1342,7 +1449,8 @@ class ColorPickerHueRing extends StatelessWidget {
final bool displayThumbColor ;
final bool displayThumbColor ;
final double strokeWidth ;
final double strokeWidth ;
void _handleGesture ( Offset position , BuildContext context , double height , double width ) {
void _handleGesture (
Offset position , BuildContext context , double height , double width ) {
RenderBox ? getBox = context . findRenderObject ( ) as RenderBox ? ;
RenderBox ? getBox = context . findRenderObject ( ) as RenderBox ? ;
if ( getBox = = null ) return ;
if ( getBox = = null ) return ;
@ -1352,9 +1460,15 @@ class ColorPickerHueRing extends StatelessWidget {
Offset center = Offset ( width / 2 , height / 2 ) ;
Offset center = Offset ( width / 2 , height / 2 ) ;
double radio = width < = height ? width / 2 : height / 2 ;
double radio = width < = height ? width / 2 : height / 2 ;
double dist = sqrt ( pow ( horizontal - center . dx , 2 ) + pow ( vertical - center . dy , 2 ) ) / radio ;
double dist =
double rad = ( atan2 ( horizontal - center . dx , vertical - center . dy ) / pi + 1 ) / 2 * 360 ;
sqrt ( pow ( horizontal - center . dx , 2 ) + pow ( vertical - center . dy , 2 ) ) /
if ( dist > 0.7 & & dist < 1.3 ) onColorChanged ( hsvColor . withHue ( ( ( rad + 90 ) % 360 ) . clamp ( 0 , 360 ) ) ) ;
radio ;
double rad =
( atan2 ( horizontal - center . dx , vertical - center . dy ) / pi + 1 ) /
2 *
360 ;
if ( dist > 0.7 & & dist < 1.3 )
onColorChanged ( hsvColor . withHue ( ( ( rad + 90 ) % 360 ) . clamp ( 0 , 360 ) ) ) ;
}
}
@ override
@ override
@ -1366,17 +1480,22 @@ class ColorPickerHueRing extends StatelessWidget {
return RawGestureDetector (
return RawGestureDetector (
gestures: {
gestures: {
_AlwaysWinPanGestureRecognizer: GestureRecognizerFactoryWithHandlers < _AlwaysWinPanGestureRecognizer > (
_AlwaysWinPanGestureRecognizer:
GestureRecognizerFactoryWithHandlers <
_AlwaysWinPanGestureRecognizer > (
( ) = > _AlwaysWinPanGestureRecognizer ( ) ,
( ) = > _AlwaysWinPanGestureRecognizer ( ) ,
( _AlwaysWinPanGestureRecognizer instance ) {
( _AlwaysWinPanGestureRecognizer instance ) {
instance
instance
. . onDown = ( ( details ) = > _handleGesture ( details . globalPosition , context , height , width ) )
. . onDown = ( ( details ) = > _handleGesture (
. . onUpdate = ( ( details ) = > _handleGesture ( details . globalPosition , context , height , width ) ) ;
details . globalPosition , context , height , width ) )
. . onUpdate = ( ( details ) = > _handleGesture (
details . globalPosition , context , height , width ) ) ;
} ,
} ,
) ,
) ,
} ,
} ,
child: CustomPaint (
child: CustomPaint (
painter: HueRingPainter ( hsvColor , displayThumbColor: displayThumbColor , strokeWidth: strokeWidth ) ,
painter: HueRingPainter ( hsvColor ,
displayThumbColor: displayThumbColor , strokeWidth: strokeWidth ) ,
) ,
) ,
) ;
) ;
} ,
} ,
@ -1399,5 +1518,6 @@ class _AlwaysWinPanGestureRecognizer extends PanGestureRecognizer {
class UpperCaseTextFormatter extends TextInputFormatter {
class UpperCaseTextFormatter extends TextInputFormatter {
@ override
@ override
TextEditingValue formatEditUpdate ( oldValue , TextEditingValue newValue ) = >
TextEditingValue formatEditUpdate ( oldValue , TextEditingValue newValue ) = >
TextEditingValue ( text: newValue . text . toUpperCase ( ) , selection: newValue . selection ) ;
TextEditingValue (
text: newValue . text . toUpperCase ( ) , selection: newValue . selection ) ;
}
}