This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/entity.page.dart

57 lines
1.4 KiB
Dart
Raw Normal View History

2018-09-29 16:19:01 +03:00
part of 'main.dart';
class EntityViewPage extends StatefulWidget {
EntityViewPage({Key key, this.entity}) : super(key: key);
2018-10-02 00:41:40 +03:00
final Entity entity;
2018-09-29 16:19:01 +03:00
@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: _entity.buildWidget(context, EntityWidgetType.extended)
2018-09-29 16:19:01 +03:00
),
);
}
2018-09-29 17:59:38 +03:00
@override
void dispose(){
if (_stateSubscription != null) _stateSubscription.cancel();
super.dispose();
}
2018-09-29 16:19:01 +03:00
}