diff --git a/lib/traits/device_widget_factory.dart b/lib/traits/device_widget_factory.dart index d086dee6..d7768e9e 100644 --- a/lib/traits/device_widget_factory.dart +++ b/lib/traits/device_widget_factory.dart @@ -13,7 +13,9 @@ import 'package:yonomi_device_widgets/traits/slim/base_slim_widget.dart'; import 'package:yonomi_device_widgets/traits/slim/battery_slim_widget.dart'; import 'package:yonomi_device_widgets/traits/slim/lock_slim_widget.dart'; import 'package:yonomi_device_widgets/traits/slim/power_slim_widget.dart'; +import 'package:yonomi_device_widgets/traits/slim/thermostat_slim_widget.dart'; import 'package:yonomi_device_widgets/traits/slim/unknown_slim_widget.dart'; +import 'package:yonomi_device_widgets/traits/thermostat_widget.dart'; import 'package:yonomi_device_widgets/traits/unknown_widget.dart'; import 'package:yonomi_device_widgets/ui/widget_style_constants.dart'; @@ -42,7 +44,7 @@ class DeviceWidgetFactory { case ThermostatProvider: return Consumer( builder: (_, thermostatProvider, child) { - return Text('${thermostatProvider.targetTemperature.toInt()}'); + return ThermostatWidget(thermostatProvider, textColor: textColor); }, ); default: @@ -76,13 +78,12 @@ class DeviceWidgetFactory { }); case ThermostatProvider: return Consumer( - builder: (_, thermostatProvider, child) { - return BaseSlimWidget( - leftIcon: Icon(BootstrapIcons.thermometer), - headerText: Text( - 'Target Temperature: ${thermostatProvider.targetTemperature.toInt()}')); - }, - ); + builder: (_, thermostatProvider, child) { + return ThermostatSlimWidget( + thermostatProvider, + backgroundColor: backgroundColor, + ); + }); default: return UnknownSlimWidget(name ?? '', backgroundColor: backgroundColor); } diff --git a/lib/traits/slim/thermostat_slim_widget.dart b/lib/traits/slim/thermostat_slim_widget.dart new file mode 100644 index 00000000..dee71c72 --- /dev/null +++ b/lib/traits/slim/thermostat_slim_widget.dart @@ -0,0 +1,21 @@ +import 'package:bootstrap_icons/bootstrap_icons.dart'; +import 'package:flutter/material.dart'; +import 'package:yonomi_device_widgets/providers/thermostat_provider.dart'; +import 'package:yonomi_device_widgets/traits/slim/base_slim_widget.dart'; +import 'package:yonomi_device_widgets/ui/widget_style_constants.dart'; + +class ThermostatSlimWidget extends BaseSlimWidget { + ThermostatSlimWidget(ThermostatProvider thermostatProvider, + {Color? backgroundColor, Key? key}) + : super( + provider: thermostatProvider, + leftIcon: Icon(BootstrapIcons.thermometer, + size: 20.0, + color: WidgetStyleConstants.deviceDetailIconColorActive), + headerText: Text( + 'Target Temperature: ${thermostatProvider.targetTemperature.toInt()}\u{00B0}', + style: TextStyle( + fontSize: 20, color: WidgetStyleConstants.darkTextColor)), + backgroundColor: backgroundColor, + key: key); +} diff --git a/lib/traits/thermostat_widget.dart b/lib/traits/thermostat_widget.dart new file mode 100644 index 00000000..7a3297cb --- /dev/null +++ b/lib/traits/thermostat_widget.dart @@ -0,0 +1,68 @@ +import 'package:bootstrap_icons/bootstrap_icons.dart'; +import 'package:flutter/material.dart'; +import 'package:yonomi_device_widgets/providers/thermostat_provider.dart'; +import 'package:yonomi_device_widgets/ui/widget_style_constants.dart'; + +class ThermostatWidget extends StatelessWidget { + final ThermostatProvider _thermostatProvider; + + late final Color _textColor; + + ThermostatWidget(this._thermostatProvider, + {Color textColor = WidgetStyleConstants.darkTextColor, Key? key}) + : super(key: key) { + this._textColor = textColor; + } + + Widget _centerText(TextStyle? style) { + return Row(children: [ + Icon( + BootstrapIcons.thermometer, + size: style?.height, + color: style?.color, + ), + Text( + '${_thermostatProvider.targetTemperature.toInt()}\u{00B0}', + style: style, + ) + ]); + } + + @override + Widget build(BuildContext context) { + return Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Row( + children: [ + Text( + _thermostatProvider.displayName, + style: Theme.of(context) + .textTheme + .headline6 + ?.copyWith(color: _textColor), + textAlign: TextAlign.center, + ), + ], + ), + SizedBox( + height: 30, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Center( + child: _centerText(Theme.of(context) + .textTheme + .headline2 + ?.copyWith(color: _textColor)), + ) + ], + ), + SizedBox( + height: 30, + ), + ], + ); + } +} diff --git a/test/traits/detail_screen_test.dart b/test/traits/detail_screen_test.dart index 8c2fc4c9..1cc39fe2 100644 --- a/test/traits/detail_screen_test.dart +++ b/test/traits/detail_screen_test.dart @@ -16,6 +16,8 @@ import 'package:yonomi_device_widgets/traits/power_widget.dart'; import 'package:yonomi_device_widgets/traits/slim/battery_slim_widget.dart'; import 'package:yonomi_device_widgets/traits/slim/lock_slim_widget.dart'; import 'package:yonomi_device_widgets/traits/slim/power_slim_widget.dart'; +import 'package:yonomi_device_widgets/traits/slim/thermostat_slim_widget.dart'; +import 'package:yonomi_device_widgets/traits/thermostat_widget.dart'; import 'package:yonomi_device_widgets/ui/widget_style_constants.dart'; import 'package:yonomi_platform_sdk/yonomi-sdk.dart'; @@ -105,7 +107,8 @@ class DetailScreenTest BatteryLevelProvider mockBatteryLevelProvider, ThermostatProvider mockThermostatProvider) { return MaterialApp( - home: Column(children: [ + home: SingleChildScrollView( + child: Column(children: [ MultiProvider( providers: [ ChangeNotifierProvider.value( @@ -120,7 +123,7 @@ class DetailScreenTest ], child: DetailScreenWidget(req, deviceId), ), - ]), + ])), ); } } @@ -200,7 +203,8 @@ void main() { await tester.pumpWidget(test.createDetailScreenWidgetForTraits( [ThermostatTrait(TargetTemperature(100.0))], request, testedDeviceId)); - expect(find.text('100'), findsOneWidget); + expect(find.byType(ThermostatWidget), findsOneWidget); + expect(find.text('100°'), findsOneWidget); }); testWidgets( @@ -223,7 +227,8 @@ void main() { UnknownTrait('unknown'), BatteryLevelTrait(BatteryLevel(100)), PowerTrait(IsOnOff(true)), - LockTrait(IsLocked(false)) + LockTrait(IsLocked(false)), + ThermostatTrait(TargetTemperature(99)) ], request, testedDeviceId)); expect(find.byType(LockWidget), findsOneWidget); @@ -231,6 +236,7 @@ void main() { expect(find.byType(BatterySlimWidget), findsOneWidget); expect(find.byType(LockSlimWidget), findsOneWidget); expect(find.byType(PowerSlimWidget), findsOneWidget); + expect(find.byType(ThermostatSlimWidget), findsOneWidget); expect(find.byType(MultiProvider), findsOneWidget); @@ -239,6 +245,11 @@ void main() { expect(batteryWidget.headerText.data, contains('Battery Level: 100%')); expect(batteryWidget.headerText.style?.color, WidgetStyleConstants.globalSuccessColor); + + final thermostatWidget = + tester.widget(find.byType(ThermostatSlimWidget)); + expect( + thermostatWidget.headerText.data, contains('Target Temperature: 99°')); }); testWidgets(