-
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.
feat(ColorTemperature): ColorTemperature dynamic widget (DX-362) (#44)
* ci: generate dartdocs and push new PR after merging to main * ci(config.yml): fixes to dartdoc generation + pr creation steps * feat(color_temperature_icon): icon to represent color temperature trait * feat(color_temperature): introduce ColorTemperatureWidget * style(misc): styling, trailing commas, etc. * feat(color_temperature_widget): add min and max color temperature range to provider and widget * feat(color_temp_slim_widget): introduce color temperature slim widget * feat(deviceWidgetFactory): have deviceWidgetFactory build colorTemperatureWidgets * test(color_temp_widget): fix test name descriptions * test(color_temp_widget_test): fix typo * refactor(color_temp_widget): fix setting up min & max on slim widget * build(pubspec.yaml): temporarily point to git PR reference * refactor(color_temp_icon): create default icon field * test(detail_screen_test): include test case for ColorTemperature * test(color_temperature_provider): improve test coverage * fix(providers): fix compilation issues to get State values with null-safe operator * ci(config.yml): print flutter version * build(pubspec.yaml): Update to use published version of dart sdk Co-authored-by: Rigoberto L. Perez <rigoberto.perez@allegion.com>
- Loading branch information
Showing
20 changed files
with
1,043 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:bootstrap_icons/bootstrap_icons.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:yonomi_device_widgets/ui/widget_style_constants.dart'; | ||
|
||
class ColorTemperatureIcon extends Icon { | ||
static const DEFAULT_ICON = BootstrapIcons.lightbulb; | ||
|
||
ColorTemperatureIcon(int colorTemperature, | ||
{size = WidgetStyleConstants.defaultDeviceIconSize, | ||
color = WidgetStyleConstants.deviceIconColor, | ||
Key? key}) | ||
: super(DEFAULT_ICON, key: key, size: size, color: color); | ||
} |
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,52 @@ | ||
import 'package:yonomi_device_widgets/providers/device_provider.dart'; | ||
import 'package:yonomi_platform_sdk/yonomi-sdk.dart'; | ||
|
||
typedef SetColorTemperatureFunction = Future<void> Function( | ||
Request request, String id, int colorTemperature); | ||
|
||
class ColorTemperatureProvider extends DeviceProvider { | ||
static const _DEFAULT_DISPLAY_NAME = 'COLOR TEMPERATURE'; | ||
|
||
late final String _deviceId; | ||
late final Request _request; | ||
|
||
ColorTemperatureProvider(Request request, String deviceId, | ||
{GetDeviceDetailsMethod getDetails = DevicesRepository.getDeviceDetails}) | ||
: super(request, deviceId, getDetails: getDetails) { | ||
this._deviceId = deviceId; | ||
this._request = request; | ||
} | ||
|
||
ColorTemperatureTrait? getColorTemperatureTrait() { | ||
return trait<ColorTemperatureTrait>() as ColorTemperatureTrait?; | ||
} | ||
|
||
int? get getColorTemperatureState => | ||
getColorTemperatureTrait()?.stateWhereType<ColorTemperature>()?.value | ||
as int?; | ||
|
||
int? get getMinColorTemperature => getColorTemperatureTrait() | ||
?.propertyWhereType<SupportedColorTemperatureRange>() | ||
.value | ||
.min as int?; | ||
|
||
int? get getMaxColorTemperature => getColorTemperatureTrait() | ||
?.propertyWhereType<SupportedColorTemperatureRange>() | ||
.value | ||
.max as int?; | ||
|
||
Future<void> setColorTemperatureAction(int colorTemperature, | ||
{GetDeviceDetailsMethod getDetails = DevicesRepository.getDeviceDetails, | ||
SetColorTemperatureFunction setColorTemperatureFunction = | ||
ColorTemperatureRepository.setColorTemperatureAction}) { | ||
return performAction<int>( | ||
colorTemperature, | ||
() => getColorTemperatureState, | ||
() => setColorTemperatureFunction(_request, _deviceId, colorTemperature), | ||
getDetails: getDetails, | ||
); | ||
} | ||
|
||
@override | ||
String get displayName => deviceDetail?.displayName ?? _DEFAULT_DISPLAY_NAME; | ||
} |
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,135 @@ | ||
import 'package:bootstrap_icons/bootstrap_icons.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:yonomi_device_widgets/mixins/toast_notifications.dart'; | ||
import 'package:yonomi_device_widgets/providers/color_temperature_provider.dart'; | ||
import 'package:yonomi_device_widgets/ui/widget_style_constants.dart'; | ||
|
||
class ColorTemperatureWidget extends StatefulWidget { | ||
final ColorTemperatureProvider _colorTemperatureProvider; | ||
late final Color _iconColor; | ||
late final Color _textColor; | ||
late final double _iconSize; | ||
|
||
static const String label = 'Color Temp.'; | ||
|
||
ColorTemperatureWidget(this._colorTemperatureProvider, | ||
{Color iconColor = WidgetStyleConstants.deviceDetailIconColorActive, | ||
Color textColor = WidgetStyleConstants.darkTextColor, | ||
double iconSize = 100, | ||
Key? key}) | ||
: super(key: key) { | ||
this._iconColor = iconColor; | ||
this._textColor = textColor; | ||
this._iconSize = iconSize; | ||
} | ||
|
||
@override | ||
State<StatefulWidget> createState() => _ColorTemperatureWidgetState(); | ||
} | ||
|
||
class _ColorTemperatureWidgetState extends State<ColorTemperatureWidget> | ||
with ToastNotifications { | ||
int? _value; | ||
|
||
static const double DEFAULT_COLOR_TEMP = 2500; | ||
static const double DEFAULT_MIN_COLOR_TEMP = 1000; | ||
static const double DEFAULT_MAX_COLOR_TEMP = 7000; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_value = widget._colorTemperatureProvider.getColorTemperatureState; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (widget._colorTemperatureProvider.isLoading) { | ||
return CircularProgressIndicator(); | ||
} else if (widget._colorTemperatureProvider.isInErrorState) { | ||
showToast(context, widget._colorTemperatureProvider.getErrorMessage); | ||
return Icon( | ||
Icons.error, | ||
color: WidgetStyleConstants.globalWarningColor, | ||
); | ||
} else { | ||
final colorTemperature = _colorTemperatureValue(); | ||
return Column( | ||
mainAxisAlignment: MainAxisAlignment.start, | ||
children: <Widget>[ | ||
Row( | ||
children: <Widget>[ | ||
Text( | ||
ColorTemperatureWidget.label.toUpperCase(), | ||
style: Theme.of(context) | ||
.textTheme | ||
.headline6 | ||
?.copyWith(color: widget._textColor), | ||
), | ||
], | ||
), | ||
SizedBox(height: 10), | ||
Container( | ||
child: Center( | ||
child: SizedBox( | ||
width: widget._iconSize, | ||
height: widget._iconSize, | ||
child: widget._colorTemperatureProvider.isPerformingAction | ||
? CircularProgressIndicator() | ||
: Icon( | ||
BootstrapIcons.sun, | ||
color: widget._iconColor, | ||
size: widget._iconSize, | ||
), | ||
)), | ||
), | ||
SizedBox(height: 10), | ||
Row(children: [ | ||
Icon(BootstrapIcons.sun, color: widget._iconColor), | ||
Expanded( | ||
child: Slider( | ||
label: ColorTemperatureWidget.label, | ||
value: colorTemperature?.toDouble() ?? DEFAULT_COLOR_TEMP, | ||
min: widget._colorTemperatureProvider.getMinColorTemperature | ||
?.toDouble() ?? | ||
DEFAULT_MIN_COLOR_TEMP, | ||
max: widget._colorTemperatureProvider.getMaxColorTemperature | ||
?.toDouble() ?? | ||
DEFAULT_MAX_COLOR_TEMP, | ||
divisions: 100, | ||
activeColor: WidgetStyleConstants.globalSuccessColor, | ||
// When onChanged is null it makes the slider disabled | ||
onChanged: (colorTemperature == null) | ||
? null | ||
: (double value) { | ||
setState(() => _value = value.toInt()); | ||
}, // Required | ||
onChangeEnd: (double value) { | ||
// Only send the update when user releases slider | ||
setState(() => _value = value.toInt()); | ||
widget._colorTemperatureProvider | ||
.setColorTemperatureAction(value.round()); | ||
}, | ||
), | ||
), | ||
Text( | ||
'${colorTemperature ?? "--"}', | ||
style: Theme.of(context) | ||
.textTheme | ||
.headline6 | ||
?.copyWith(color: widget._textColor), | ||
) | ||
]) | ||
]); | ||
} | ||
} | ||
|
||
int? _colorTemperatureValue() { | ||
if (_value == null) { | ||
setState(() { | ||
_value = widget._colorTemperatureProvider.getColorTemperatureState; | ||
super.reassemble(); | ||
}); | ||
} | ||
return _value; | ||
} | ||
} |
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
Oops, something went wrong.