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/cover/widgets/cover_state.dart
2019-11-08 19:37:41 +00:00

74 lines
1.9 KiB
Dart

part of '../../../main.dart';
class CoverStateWidget extends StatelessWidget {
void _open(CoverEntity entity) {
ConnectionManager().callService(
domain: entity.domain,
service: "open_cover",
entityId: entity.entityId
);
}
void _close(CoverEntity entity) {
ConnectionManager().callService(
domain: entity.domain,
service: "close_cover",
entityId: entity.entityId
);
}
void _stop(CoverEntity entity) {
ConnectionManager().callService(
domain: entity.domain,
service: "stop_cover",
entityId: entity.entityId
);
}
@override
Widget build(BuildContext context) {
final entityModel = EntityModel.of(context);
final CoverEntity entity = entityModel.entityWrapper.entity;
List<Widget> buttons = [];
if (entity.supportOpen) {
buttons.add(IconButton(
icon: Icon(
MaterialDesignIcons.getIconDataFromIconName("mdi:arrow-up"),
size: Sizes.iconSize,
),
onPressed: entity.canBeOpened ? () => _open(entity) : null));
} else {
buttons.add(Container(
width: Sizes.iconSize + 20.0,
));
}
if (entity.supportStop) {
buttons.add(IconButton(
icon: Icon(
MaterialDesignIcons.getIconDataFromIconName("mdi:stop"),
size: Sizes.iconSize,
),
onPressed: () => _stop(entity)));
} else {
buttons.add(Container(
width: Sizes.iconSize + 20.0,
));
}
if (entity.supportClose) {
buttons.add(IconButton(
icon: Icon(
MaterialDesignIcons.getIconDataFromIconName("mdi:arrow-down"),
size: Sizes.iconSize,
),
onPressed: entity.canBeClosed ? () => _close(entity) : null));
} else {
buttons.add(Container(
width: Sizes.iconSize + 20.0,
));
}
return Row(
children: buttons,
);
}
}