2018-11-23 19:18:17 +02:00
|
|
|
part of '../../main.dart';
|
|
|
|
|
|
|
|
class LockStateWidget extends StatelessWidget {
|
|
|
|
|
2019-03-10 23:41:14 +02:00
|
|
|
final bool assumedState;
|
|
|
|
|
|
|
|
const LockStateWidget({Key key, this.assumedState: false}) : super(key: key);
|
|
|
|
|
2018-11-23 19:18:17 +02:00
|
|
|
void _lock(Entity entity) {
|
|
|
|
eventBus.fire(new ServiceCallEvent("lock", "lock", entity.entityId, null));
|
|
|
|
}
|
|
|
|
|
|
|
|
void _unlock(Entity entity) {
|
|
|
|
eventBus.fire(new ServiceCallEvent("lock", "unlock", entity.entityId, null));
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final entityModel = EntityModel.of(context);
|
|
|
|
final LockEntity entity = entityModel.entityWrapper.entity;
|
2019-03-10 23:41:14 +02:00
|
|
|
if (assumedState) {
|
|
|
|
return Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
SizedBox(
|
|
|
|
height: 34.0,
|
|
|
|
child: FlatButton(
|
|
|
|
onPressed: () => _unlock(entity),
|
|
|
|
child: Text("UNLOCK",
|
|
|
|
textAlign: TextAlign.right,
|
|
|
|
style:
|
|
|
|
new TextStyle(fontSize: Sizes.stateFontSize, color: Colors.blue),
|
|
|
|
),
|
|
|
|
)
|
2018-11-23 19:18:17 +02:00
|
|
|
),
|
2019-03-10 23:41:14 +02:00
|
|
|
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),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2018-11-23 19:18:17 +02:00
|
|
|
}
|
|
|
|
}
|