-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Implement full size color widget
- Loading branch information
Showing
3 changed files
with
86 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,91 @@ | ||
import 'package:bootstrap_icons/bootstrap_icons.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_colorpicker/flutter_colorpicker.dart'; | ||
import 'package:yonomi_device_widgets/assets/traits/unknown_item_icon.dart'; | ||
import 'package:yonomi_device_widgets/providers/color_provider.dart'; | ||
import 'package:yonomi_device_widgets/ui/widget_style_constants.dart'; | ||
import 'package:yonomi_platform_sdk/yonomi-sdk.dart'; | ||
|
||
class ColorWidget extends StatelessWidget { | ||
ColorWidget(ColorProvider _colorProvider); | ||
final ColorProvider _colorProvider; | ||
final Color _textColor = WidgetStyleConstants.darkTextColor; | ||
final Color _iconColor = WidgetStyleConstants.deviceDetailIconColorActive; | ||
|
||
ColorWidget(this._colorProvider, {Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
// TODO: implement build | ||
throw UnimplementedError(); | ||
return _colorProvider.isBusy | ||
? Center(child: CircularProgressIndicator()) | ||
: Column(mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[ | ||
Row( | ||
children: <Widget>[ | ||
Text( | ||
'COLOR', | ||
style: Theme.of(context) | ||
.textTheme | ||
.headline6 | ||
?.copyWith(color: _textColor), | ||
), | ||
], | ||
), | ||
SizedBox(height: 10), | ||
Center( | ||
child: SizedBox( | ||
width: 100, | ||
height: 100, | ||
child: _colorProvider.isPerformingAction | ||
? CircularProgressIndicator() | ||
: UnknownItemIcon( | ||
size: 100, | ||
color: _iconColor, | ||
))), | ||
SizedBox(height: 10), | ||
_stateRow(context), | ||
]); | ||
} | ||
|
||
Widget _stateRow(BuildContext context) { | ||
final state = _colorProvider.getColorState; | ||
if (state == null) { | ||
return Container(); | ||
} else { | ||
final pickedColor = HSVColor.fromAHSV( | ||
1.0, state.h.toDouble(), state.s / 100.0, state.b / 100.0); | ||
return Row( | ||
children: <Widget>[ | ||
Center( | ||
child: CircleAvatar( | ||
backgroundColor: pickedColor.toColor(), | ||
radius: 46, | ||
)), | ||
Text( | ||
'HSB(${state.h}, ${state.s}, ${state.b})', | ||
style: Theme.of(context) | ||
.textTheme | ||
.headline6 | ||
?.copyWith(color: _textColor), | ||
), | ||
IconButton( | ||
onPressed: () { | ||
SlidePicker( | ||
pickerColor: pickedColor.toColor(), | ||
onColorChanged: (color) { | ||
final calculatedColor = HSVColor.fromColor(color); | ||
_colorProvider.setColorAction(HSBColor( | ||
calculatedColor.hue.toInt(), | ||
(calculatedColor.saturation * 100).toInt(), | ||
(calculatedColor.value * 100).toInt())); | ||
}, | ||
colorModel: ColorModel.hsv, | ||
); | ||
}, | ||
icon: Icon( | ||
BootstrapIcons.pencil, | ||
color: WidgetStyleConstants.globalSuccessColor, | ||
)) | ||
], | ||
); | ||
} | ||
} | ||
} |
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