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/select/widgets/select_state.dart

53 lines
1.3 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 SelectStateWidget extends StatefulWidget {
SelectStateWidget({Key key}) : super(key: key);
@override
_SelectStateWidgetState createState() => _SelectStateWidgetState();
}
class _SelectStateWidgetState extends State<SelectStateWidget> {
void setNewState(domain, entityId, newValue) {
2019-11-08 21:37:41 +02:00
ConnectionManager().callService(
domain: domain,
service: "select_option",
entityId: entityId,
data: {"option": "$newValue"}
);
2018-10-27 14:27:41 +03:00
}
@override
Widget build(BuildContext context) {
final entityModel = EntityModel.of(context);
final SelectEntity entity = entityModel.entityWrapper.entity;
2018-10-27 14:27:41 +03:00
Widget ctrl;
if (entity.listOptions.isNotEmpty) {
ctrl = DropdownButton<String>(
value: entity.state,
2018-11-18 16:40:12 +02:00
isExpanded: true,
2018-10-27 14:27:41 +03:00
items: entity.listOptions.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (_) {
setNewState(entity.domain, entity.entityId,_);
},
);
} else {
ctrl = Text('---');
}
2018-11-18 16:40:12 +02:00
return Flexible(
flex: 2,
fit: FlexFit.tight,
2018-10-27 14:27:41 +03:00
//width: Entity.INPUT_WIDTH,
child: ctrl,
);
}
}