Resolves #52, Resolves #54 Inputs

This commit is contained in:
estevez 2018-09-29 17:38:00 +03:00
parent c0a9b89d40
commit 6834f2ca34
2 changed files with 42 additions and 18 deletions

View File

@ -30,7 +30,9 @@ class Entity {
double get maxValue => _attributes["max"] ?? 100.0; double get maxValue => _attributes["max"] ?? 100.0;
double get valueStep => _attributes["step"] ?? 1.0; double get valueStep => _attributes["step"] ?? 1.0;
double get doubleState => double.tryParse(_state) ?? 0.0; double get doubleState => double.tryParse(_state) ?? 0.0;
bool get isSlider => _attributes["mode"] == "slider"; bool get isSliderField => _attributes["mode"] == "slider";
bool get isTextField => _attributes["mode"] == "text";
bool get isPasswordField => _attributes["mode"] == "password";
String get deviceClass => _attributes["device_class"] ?? null; String get deviceClass => _attributes["device_class"] ?? null;
bool get isView => (_domain == "group") && (_attributes != null ? _attributes["view"] ?? false : false); bool get isView => (_domain == "group") && (_attributes != null ? _attributes["view"] ?? false : false);
@ -91,7 +93,7 @@ class Entity {
); );
} }
Widget buildExtendedWidget() { Widget buildExtendedWidget(String staticState) {
return Row( return Row(
children: <Widget>[ children: <Widget>[
_buildIconWidget(), _buildIconWidget(),
@ -104,7 +106,7 @@ class Entity {
Expanded( Expanded(
child: _buildNameWidget(), child: _buildNameWidget(),
), ),
_buildExtendedActionWidget() _buildExtendedActionWidget(staticState)
], ],
), ),
_buildLastUpdatedWidget() _buildLastUpdatedWidget()
@ -149,6 +151,7 @@ class Entity {
padding: EdgeInsets.fromLTRB(0.0, 0.0, Entity.RIGTH_WIDGET_PADDING, 0.0), padding: EdgeInsets.fromLTRB(0.0, 0.0, Entity.RIGTH_WIDGET_PADDING, 0.0),
child: GestureDetector( child: GestureDetector(
child: Text( child: Text(
this.isPasswordField ? "******" :
"$_state${this.unitOfMeasurement}", "$_state${this.unitOfMeasurement}",
textAlign: TextAlign.right, textAlign: TextAlign.right,
style: new TextStyle( style: new TextStyle(
@ -160,7 +163,7 @@ class Entity {
); );
} }
Widget _buildExtendedActionWidget() { Widget _buildExtendedActionWidget(String staticState) {
return _buildActionWidget(); return _buildActionWidget();
} }
} }
@ -206,7 +209,7 @@ class InputEntity extends Entity {
InputEntity(Map rawData) : super(rawData); InputEntity(Map rawData) : super(rawData);
@override @override
Widget buildExtendedWidget() { Widget buildExtendedWidget(String staticState) {
return Column( return Column(
children: <Widget>[ children: <Widget>[
SizedBox( SizedBox(
@ -223,7 +226,7 @@ class InputEntity extends Entity {
), ),
SizedBox( SizedBox(
height: Entity.EXTENDED_WIDGET_HEIGHT, height: Entity.EXTENDED_WIDGET_HEIGHT,
child: _buildExtendedActionWidget(), child: _buildExtendedActionWidget(staticState),
) )
], ],
); );
@ -231,7 +234,7 @@ class InputEntity extends Entity {
@override @override
Widget _buildActionWidget() { Widget _buildActionWidget() {
if (this.isSlider) { if (this.isSliderField) {
return Container( return Container(
width: 200.0, width: 200.0,
child: Row( child: Row(
@ -240,7 +243,7 @@ class InputEntity extends Entity {
child: Slider( child: Slider(
min: this.minValue*10, min: this.minValue*10,
max: this.maxValue*10, max: this.maxValue*10,
value: this.doubleState*10, value: (this.doubleState <= this.maxValue) && (this.doubleState >= this.minValue) ? this.doubleState*10 : this.minValue*10,
divisions: this.getValueDivisions(), divisions: this.getValueDivisions(),
onChanged: (value) { onChanged: (value) {
eventBus.fire(new StateChangedEvent(_entityId, (value.roundToDouble() / 10).toString(), true)); eventBus.fire(new StateChangedEvent(_entityId, (value.roundToDouble() / 10).toString(), true));
@ -269,18 +272,37 @@ class InputEntity extends Entity {
} }
@override @override
Widget _buildExtendedActionWidget() { Widget _buildExtendedActionWidget(String staticState) {
return Padding( return Padding(
padding: EdgeInsets.fromLTRB(Entity.LEFT_WIDGET_PADDING, 0.0, Entity.RIGTH_WIDGET_PADDING, 0.0), padding: EdgeInsets.fromLTRB(Entity.LEFT_WIDGET_PADDING, 0.0, Entity.RIGTH_WIDGET_PADDING, 0.0),
child: Container( child: Row(
child: TextField( crossAxisAlignment: CrossAxisAlignment.center,
controller: TextEditingController( children: <Widget>[
text: _state, Expanded(
child: TextField(
obscureText: this.isPasswordField,
controller: TextEditingController(
text: staticState,
),
onChanged: (value) {
staticState = value;
},
),
), ),
onChanged: (value) { SizedBox(
eventBus.fire(new ServiceCallEvent(_domain, "set_value", _entityId,{"value": "$value"})); width: 63.0,
}, child: FlatButton(
), onPressed: () {
eventBus.fire(new ServiceCallEvent(_domain, "set_value", _entityId,{"value": "$staticState"}));
},
child: Text(
"SET",
textAlign: TextAlign.right,
style: new TextStyle(fontSize: 16.0, color: Colors.blue),
),
),
)
],
) )
); );
} }

View File

@ -12,11 +12,13 @@ class EntityViewPage extends StatefulWidget {
class _EntityViewPageState extends State<EntityViewPage> { class _EntityViewPageState extends State<EntityViewPage> {
String _title; String _title;
Entity _entity; Entity _entity;
String _lastState;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_entity = widget.entity; _entity = widget.entity;
_lastState = _entity.state;
_prepareData(); _prepareData();
} }
@ -39,7 +41,7 @@ class _EntityViewPageState extends State<EntityViewPage> {
padding: EdgeInsets.all(10.0), padding: EdgeInsets.all(10.0),
child: ListView( child: ListView(
children: <Widget>[ children: <Widget>[
_entity.buildExtendedWidget() _entity.buildExtendedWidget(_lastState)
], ],
), ),
), ),