From 4f4ac3b574f3f01471e5da377a5cf989c885cc23 Mon Sep 17 00:00:00 2001 From: estevez-dev Date: Sun, 10 Mar 2019 23:41:14 +0200 Subject: [PATCH] Resolves #310 Add assumed state for locks --- lib/entity_class/lock_entity.class.dart | 11 ++++- lib/entity_widgets/state/lock_state.dart | 60 +++++++++++++++++++----- 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/lib/entity_class/lock_entity.class.dart b/lib/entity_class/lock_entity.class.dart index 0eea6a9..9ed21f0 100644 --- a/lib/entity_class/lock_entity.class.dart +++ b/lib/entity_class/lock_entity.class.dart @@ -7,6 +7,15 @@ class LockEntity extends Entity { @override Widget _buildStatePart(BuildContext context) { - return LockStateWidget(); + return LockStateWidget( + assumedState: false, + ); + } + + @override + Widget _buildStatePartForPage(BuildContext context) { + return LockStateWidget( + assumedState: true, + ); } } \ No newline at end of file diff --git a/lib/entity_widgets/state/lock_state.dart b/lib/entity_widgets/state/lock_state.dart index 7c7889d..ceeac4e 100644 --- a/lib/entity_widgets/state/lock_state.dart +++ b/lib/entity_widgets/state/lock_state.dart @@ -2,6 +2,10 @@ part of '../../main.dart'; class LockStateWidget extends StatelessWidget { + final bool assumedState; + + const LockStateWidget({Key key, this.assumedState: false}) : super(key: key); + void _lock(Entity entity) { eventBus.fire(new ServiceCallEvent("lock", "lock", entity.entityId, null)); } @@ -14,19 +18,49 @@ class LockStateWidget extends StatelessWidget { Widget build(BuildContext context) { final entityModel = EntityModel.of(context); final LockEntity entity = entityModel.entityWrapper.entity; - 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), + if (assumedState) { + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + height: 34.0, + child: FlatButton( + onPressed: () => _unlock(entity), + child: Text("UNLOCK", + textAlign: TextAlign.right, + 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), + ), + ) + ); + } } } \ No newline at end of file