2018-09-29 16:19:01 +03:00
|
|
|
part of 'main.dart';
|
|
|
|
|
|
|
|
class EntityViewPage extends StatefulWidget {
|
|
|
|
EntityViewPage({Key key, this.entity}) : super(key: key);
|
|
|
|
|
|
|
|
Entity entity;
|
|
|
|
|
|
|
|
@override
|
|
|
|
_EntityViewPageState createState() => new _EntityViewPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _EntityViewPageState extends State<EntityViewPage> {
|
|
|
|
String _title;
|
|
|
|
Entity _entity;
|
2018-09-29 17:59:38 +03:00
|
|
|
StreamSubscription _stateSubscription;
|
2018-09-29 16:19:01 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_entity = widget.entity;
|
2018-09-29 17:59:38 +03:00
|
|
|
if (_stateSubscription != null) _stateSubscription.cancel();
|
|
|
|
_stateSubscription = eventBus.on<StateChangedEvent>().listen((event) {
|
2018-09-30 01:07:02 +03:00
|
|
|
if (event.entityId == _entity.entityId) {
|
|
|
|
setState(() {});
|
|
|
|
}
|
2018-09-29 17:59:38 +03:00
|
|
|
});
|
2018-09-29 16:19:01 +03:00
|
|
|
_prepareData();
|
|
|
|
}
|
|
|
|
|
|
|
|
_prepareData() async {
|
|
|
|
_title = _entity.displayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return new Scaffold(
|
|
|
|
appBar: new AppBar(
|
|
|
|
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
|
|
|
|
Navigator.pop(context);
|
|
|
|
}),
|
|
|
|
// Here we take the value from the MyHomePage object that was created by
|
|
|
|
// the App.build method, and use it to set our appbar title.
|
|
|
|
title: new Text(_title),
|
|
|
|
),
|
|
|
|
body: Padding(
|
|
|
|
padding: EdgeInsets.all(10.0),
|
|
|
|
child: ListView(
|
|
|
|
children: <Widget>[
|
2018-09-30 10:15:32 +03:00
|
|
|
_entity.buildWidget(false),
|
|
|
|
_entity.buildAdditionalWidget()
|
2018-09-29 16:19:01 +03:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2018-09-29 17:59:38 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose(){
|
2018-09-30 10:00:19 +03:00
|
|
|
if (_entity is InputEntity && (_entity as InputEntity).tmpState != _entity.state) {
|
|
|
|
eventBus.fire(new ServiceCallEvent(_entity.domain, "set_value", _entity.entityId, {"value": "${(_entity as InputEntity).tmpState}"}));
|
|
|
|
TheLogger.log("Debug", "Saving changed input value for ${_entity.entityId}");
|
|
|
|
}
|
2018-09-29 17:59:38 +03:00
|
|
|
if (_stateSubscription != null) _stateSubscription.cancel();
|
|
|
|
super.dispose();
|
|
|
|
}
|
2018-09-29 16:19:01 +03:00
|
|
|
}
|