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
Yegor Vialov 84d283de2b VIP #120
2018-10-07 23:06:06 +03:00

66 lines
1.7 KiB
Dart

part of 'main.dart';
class EntityViewPage extends StatefulWidget {
EntityViewPage({Key key, @required this.entity, @required this.homeAssistant }) : super(key: key);
final Entity entity;
final HomeAssistant homeAssistant;
@override
_EntityViewPageState createState() => new _EntityViewPageState();
}
class _EntityViewPageState extends State<EntityViewPage> {
String _title;
StreamSubscription _stateSubscription;
@override
void initState() {
super.initState();
if (_stateSubscription != null) _stateSubscription.cancel();
_stateSubscription = eventBus.on<StateChangedEvent>().listen((event) {
if (event.entityId == widget.entity.entityId) {
setState(() {});
}
});
_prepareData();
_getHistory();
}
void _prepareData() async {
_title = widget.entity.displayName;
}
void _getHistory() {
widget.homeAssistant.getHistory(widget.entity.entityId).then((List history) {
if (history != null) {
}
});
}
@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: widget.entity.buildWidget(context, EntityWidgetType.extended)
),
);
}
@override
void dispose(){
if (_stateSubscription != null) _stateSubscription.cancel();
super.dispose();
}
}