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

36 lines
978 B
Dart
Raw Normal View History

part of '../main.dart';
2018-10-02 00:41:40 +03:00
class _SelectEntityWidgetState extends _EntityWidgetState {
List<String> _listOptions = [];
@override
2018-10-02 23:10:40 +03:00
void setNewState(newValue) {
2018-10-02 00:41:40 +03:00
eventBus.fire(new ServiceCallEvent(widget.entity.domain, "select_option", widget.entity.entityId,
{"option": "$newValue"}));
}
@override
Widget _buildActionWidget(BuildContext context) {
2018-10-02 00:41:40 +03:00
_listOptions.clear();
2018-10-07 15:03:51 +03:00
if (widget.entity.attributes["options"] != null) {
widget.entity.attributes["options"].forEach((value){
2018-10-02 00:41:40 +03:00
_listOptions.add(value.toString());
});
}
return Expanded(
//width: Entity.INPUT_WIDTH,
child: DropdownButton<String>(
2018-10-02 00:41:40 +03:00
value: widget.entity.state,
items: this._listOptions.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (_) {
2018-10-02 23:10:40 +03:00
setNewState(_);
},
),
);
}
}