Skip to content

Commit

Permalink
refactor: Make tiles have customizable background color
Browse files Browse the repository at this point in the history
  • Loading branch information
rlperez committed Dec 29, 2021
1 parent db0ec27 commit cd0fa7f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/traits/detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class DetailScreenWidget extends StatelessWidget {
}
}

Widget _createTraitListWidget(Trait trait) {
Widget _createTraitListWidget(Trait trait, {backgroundColor = Colors.white}) {
switch (trait.runtimeType) {
case LockTrait:
return Consumer<LockProvider>(builder: (_, lockProvider, child) {
Expand Down Expand Up @@ -145,10 +145,12 @@ class DetailScreenWidget extends StatelessWidget {
case BatteryLevelTrait:
return Consumer<BatteryLevelTraitProvider>(
builder: (_, batteryLevelTraitProvider, child) {
return BatteryExpandWidget(batteryLevelTraitProvider);
return BatteryExpandWidget(batteryLevelTraitProvider,
backgroundColor: backgroundColor);
});
default:
return DeviceExpandableWidget(
backgroundColor: backgroundColor,
leftIcon: UnknownItemIcon(
size: 20.0,
color: WidgetStyleConstants.deviceDetailIconColorActive,
Expand Down
4 changes: 3 additions & 1 deletion lib/traits/expandable/battery_expand_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import 'package:yonomi_device_widgets/traits/expandable/device_expandable_widget
import 'package:yonomi_device_widgets/ui/widget_style_constants.dart';

class BatteryExpandWidget extends DeviceExpandableWidget {
BatteryExpandWidget(_batteryLevelTraitProvider, {Key? key})
BatteryExpandWidget(_batteryLevelTraitProvider,
{Color? backgroundColor, Key? key})
: super(
backgroundColor: backgroundColor,
leftIcon:
_getBatteryLevelIcon(_batteryLevelTraitProvider.getBatteryLevel),
headerText: Text(
Expand Down
5 changes: 5 additions & 0 deletions lib/traits/expandable/device_expandable_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ class DeviceExpandableWidget extends StatelessWidget {

final Widget? content;

final Color? backgroundColor;

DeviceExpandableWidget(
{required this.leftIcon,
required this.headerText,
this.rightIcon,
this.content,
this.backgroundColor,
Key? key})
: super(key: key);

Expand All @@ -27,6 +30,7 @@ class DeviceExpandableWidget extends StatelessWidget {
return ExpansionTile(
childrenPadding: EdgeInsets.all(8.0),
trailing: rightIcon,
backgroundColor: backgroundColor,
title: Row(children: [
leftIcon,
Padding(padding: EdgeInsets.all(8.0)),
Expand All @@ -41,6 +45,7 @@ class DeviceExpandableWidget extends StatelessWidget {

Widget _tile() {
return ListTile(
tileColor: backgroundColor,
trailing: rightIcon,
title: Row(children: [
leftIcon,
Expand Down

0 comments on commit cd0fa7f

Please sign in to comment.