Resolves #310 Add assumed state for locks

This commit is contained in:
estevez-dev 2019-03-10 23:41:14 +02:00
parent 7064cb0e30
commit 4f4ac3b574
2 changed files with 57 additions and 14 deletions

View File

@ -7,6 +7,15 @@ class LockEntity extends Entity {
@override @override
Widget _buildStatePart(BuildContext context) { Widget _buildStatePart(BuildContext context) {
return LockStateWidget(); return LockStateWidget(
assumedState: false,
);
}
@override
Widget _buildStatePartForPage(BuildContext context) {
return LockStateWidget(
assumedState: true,
);
} }
} }

View File

@ -2,6 +2,10 @@ part of '../../main.dart';
class LockStateWidget extends StatelessWidget { class LockStateWidget extends StatelessWidget {
final bool assumedState;
const LockStateWidget({Key key, this.assumedState: false}) : super(key: key);
void _lock(Entity entity) { void _lock(Entity entity) {
eventBus.fire(new ServiceCallEvent("lock", "lock", entity.entityId, null)); eventBus.fire(new ServiceCallEvent("lock", "lock", entity.entityId, null));
} }
@ -14,19 +18,49 @@ class LockStateWidget extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final entityModel = EntityModel.of(context); final entityModel = EntityModel.of(context);
final LockEntity entity = entityModel.entityWrapper.entity; final LockEntity entity = entityModel.entityWrapper.entity;
return SizedBox( if (assumedState) {
height: 34.0, return Row(
child: FlatButton( mainAxisSize: MainAxisSize.min,
onPressed: (() { children: <Widget>[
entity.isLocked ? _unlock(entity) : _lock(entity); SizedBox(
}), height: 34.0,
child: Text( child: FlatButton(
entity.isLocked ? "UNLOCK" : "LOCK", onPressed: () => _unlock(entity),
textAlign: TextAlign.right, child: Text("UNLOCK",
style: textAlign: TextAlign.right,
new TextStyle(fontSize: Sizes.stateFontSize, color: Colors.blue), style:
new TextStyle(fontSize: Sizes.stateFontSize, color: Colors.blue),
),
)
), ),
) SizedBox(
); height: 34.0,
child: FlatButton(
onPressed: () => _lock(entity),
child: Text("LOCK",
textAlign: TextAlign.right,
style:
new TextStyle(fontSize: Sizes.stateFontSize, color: Colors.blue),
),
)
)
],
);
} else {
return SizedBox(
height: 34.0,
child: FlatButton(
onPressed: (() {
entity.isLocked ? _unlock(entity) : _lock(entity);
}),
child: Text(
entity.isLocked ? "UNLOCK" : "LOCK",
textAlign: TextAlign.right,
style:
new TextStyle(fontSize: Sizes.stateFontSize, color: Colors.blue),
),
)
);
}
} }
} }