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);
|
2018-11-16 22:32:43 +02:00
|
|
|
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(
|
2019-02-22 15:15:27 +02:00
|
|
|
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(
|
2019-02-22 15:15:27 +02:00
|
|
|
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(
|
2019-02-22 15:15:27 +02:00
|
|
|
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,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|