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

74 lines
1.9 KiB
Dart
Raw Normal View History

2019-08-24 21:22:32 +03:00
part of '../../../main.dart';
2018-10-27 14:27:41 +03:00
class CoverStateWidget extends StatelessWidget {
void _open(CoverEntity entity) {
2019-10-28 19:59:47 +02:00
ConnectionManager().callService(
2019-11-08 21:37:41 +02:00
domain: entity.domain,
service: "open_cover",
entityId: entity.entityId
);
2018-10-27 14:27:41 +03:00
}
void _close(CoverEntity entity) {
2019-10-28 19:59:47 +02:00
ConnectionManager().callService(
2019-11-08 21:37:41 +02:00
domain: entity.domain,
service: "close_cover",
entityId: entity.entityId
);
2018-10-27 14:27:41 +03:00
}
void _stop(CoverEntity entity) {
2019-10-28 19:59:47 +02:00
ConnectionManager().callService(
2019-11-08 21:37:41 +02:00
domain: entity.domain,
service: "stop_cover",
entityId: entity.entityId
);
2018-10-27 14:27:41 +03:00
}
@override
Widget build(BuildContext context) {
final entityModel = EntityModel.of(context);
final CoverEntity entity = entityModel.entityWrapper.entity;
2018-10-27 14:27:41 +03:00
List<Widget> buttons = [];
if (entity.supportOpen) {
buttons.add(IconButton(
icon: Icon(
MaterialDesignIcons.getIconDataFromIconName("mdi:arrow-up"),
2018-11-12 20:28:10 +02:00
size: Sizes.iconSize,
2018-10-27 14:27:41 +03:00
),
onPressed: entity.canBeOpened ? () => _open(entity) : null));
} else {
buttons.add(Container(
2018-11-12 20:28:10 +02:00
width: Sizes.iconSize + 20.0,
2018-10-27 14:27:41 +03:00
));
}
if (entity.supportStop) {
buttons.add(IconButton(
icon: Icon(
MaterialDesignIcons.getIconDataFromIconName("mdi:stop"),
2018-11-12 20:28:10 +02:00
size: Sizes.iconSize,
2018-10-27 14:27:41 +03:00
),
onPressed: () => _stop(entity)));
} else {
buttons.add(Container(
2018-11-12 20:28:10 +02:00
width: Sizes.iconSize + 20.0,
2018-10-27 14:27:41 +03:00
));
}
if (entity.supportClose) {
buttons.add(IconButton(
icon: Icon(
MaterialDesignIcons.getIconDataFromIconName("mdi:arrow-down"),
2018-11-12 20:28:10 +02:00
size: Sizes.iconSize,
2018-10-27 14:27:41 +03:00
),
onPressed: entity.canBeClosed ? () => _close(entity) : null));
} else {
buttons.add(Container(
2018-11-12 20:28:10 +02:00
width: Sizes.iconSize + 20.0,
2018-10-27 14:27:41 +03:00
));
}
return Row(
children: buttons,
);
}
}