This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/entities/climate/widgets/mode_swicth.dart
2020-04-04 12:00:15 +00:00

49 lines
1.0 KiB
Dart

part of '../../../main.dart';
class ModeSwitchWidget extends StatelessWidget {
final String caption;
final onChange;
final bool value;
final bool expanded;
final EdgeInsets padding;
ModeSwitchWidget({
Key key,
@required this.caption,
@required this.onChange,
this.value,
this.expanded: true,
this.padding: const EdgeInsets.only(left: Sizes.leftWidgetPadding, right: Sizes.rightWidgetPadding)
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Padding(
padding: this.padding,
child: Row(
children: <Widget>[
_buildCaption(context),
Switch(
onChanged: (value) => onChange(value),
value: value ?? false,
)
],
)
);
}
Widget _buildCaption(BuildContext context) {
Widget captionWidget = Text(
"$caption",
style: Theme.of(context).textTheme.body1,
);
if (expanded) {
return Expanded(
child: captionWidget,
);
}
return captionWidget;
}
}