Separate entity classes on different files

This commit is contained in:
estevez
2018-10-01 21:57:54 +03:00
parent bc4969dae8
commit 4a0b447f00
9 changed files with 493 additions and 487 deletions

View File

@ -0,0 +1,39 @@
part of '../main.dart';
class SelectEntity extends Entity {
List<String> _listOptions = [];
String get initialValue => _attributes["initial"] ?? null;
SelectEntity(Map rawData) : super(rawData) {
if (_attributes["options"] != null) {
_attributes["options"].forEach((value){
_listOptions.add(value.toString());
});
}
}
@override
void sendNewState(newValue) {
eventBus.fire(new ServiceCallEvent(_domain, "select_option", _entityId,
{"option": "$newValue"}));
}
@override
Widget _buildActionWidget(bool inCard, BuildContext context) {
return Container(
width: Entity.INPUT_WIDTH,
child: DropdownButton<String>(
value: _state,
items: this._listOptions.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (_) {
sendNewState(_);
},
),
);
}
}