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/entity_class/select_entity.class.dart
2018-10-02 00:41:40 +03:00

36 lines
994 B
Dart

part of '../main.dart';
class _SelectEntityWidgetState extends _EntityWidgetState {
List<String> _listOptions = [];
@override
void sendNewState(newValue) {
eventBus.fire(new ServiceCallEvent(widget.entity.domain, "select_option", widget.entity.entityId,
{"option": "$newValue"}));
}
@override
Widget _buildActionWidget(bool inCard, BuildContext context) {
_listOptions.clear();
if (widget.entity._attributes["options"] != null) {
widget.entity._attributes["options"].forEach((value){
_listOptions.add(value.toString());
});
}
return Container(
width: Entity.INPUT_WIDTH,
child: DropdownButton<String>(
value: widget.entity.state,
items: this._listOptions.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (_) {
sendNewState(_);
},
),
);
}
}