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

49 lines
1.0 KiB
Dart
Raw Normal View History

2019-09-09 18:50:35 +03:00
part of '../../../main.dart';
2018-10-27 14:27:41 +03:00
class ModeSwitchWidget extends StatelessWidget {
final String caption;
final onChange;
final bool value;
2018-11-24 17:00:45 +02:00
final bool expanded;
2019-02-16 19:59:39 +02:00
final EdgeInsets padding;
2018-10-27 14:27:41 +03:00
ModeSwitchWidget({
Key key,
@required this.caption,
@required this.onChange,
2018-11-24 17:00:45 +02:00
this.value,
2019-02-16 19:59:39 +02:00
this.expanded: true,
this.padding: const EdgeInsets.only(left: Sizes.leftWidgetPadding, right: Sizes.rightWidgetPadding)
2018-10-27 14:27:41 +03:00
}) : super(key: key);
@override
Widget build(BuildContext context) {
2019-02-16 19:59:39 +02:00
return Padding(
padding: this.padding,
child: Row(
children: <Widget>[
_buildCaption(context),
2019-02-16 19:59:39 +02:00
Switch(
onChanged: (value) => onChange(value),
value: value ?? false,
)
],
)
2018-10-27 14:27:41 +03:00
);
}
Widget _buildCaption(BuildContext context) {
2018-11-24 17:00:45 +02:00
Widget captionWidget = Text(
"$caption",
style: Theme.of(context).textTheme.body1,
2018-11-24 17:00:45 +02:00
);
if (expanded) {
return Expanded(
child: captionWidget,
);
}
return captionWidget;
}
2018-10-27 14:27:41 +03:00
}