Resolves #224 Main UI tablet support

This commit is contained in:
estevez-dev
2019-09-14 18:32:44 +03:00
parent 20ffe03139
commit 6da7a5ab90
15 changed files with 194 additions and 124 deletions

View File

@ -10,9 +10,10 @@ class EntityViewPage extends StatefulWidget {
}
class _EntityViewPageState extends State<EntityViewPage> {
String _title;
StreamSubscription _refreshDataSubscription;
StreamSubscription _stateSubscription;
Entity entity;
Entity forwardToMainPage;
@override
void initState() {
@ -26,16 +27,18 @@ class _EntityViewPageState extends State<EntityViewPage> {
_refreshDataSubscription = eventBus.on<RefreshDataFinishedEvent>().listen((event) {
setState(() {});
});
_prepareData();
entity = HomeAssistant().entities.get(widget.entityId);
}
void _prepareData() async {
_title = HomeAssistant().entities.get(widget.entityId).displayName;
}
@override
Widget build(BuildContext context) {
Widget body;
if (MediaQuery.of(context).size.width >= Sizes.tabletMinWidth) {
_popAfterBuild();
body = PageLoadingIndicator();
} else {
body = entity.buildEntityPageWidget(context);
}
return new Scaffold(
appBar: new AppBar(
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
@ -43,16 +46,23 @@ class _EntityViewPageState extends State<EntityViewPage> {
}),
// 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),
title: new Text("${entity.displayName}"),
),
body: HomeAssistant().entities.get(widget.entityId).buildEntityPageWidget(context),
body: body,
);
}
_popAfterBuild() async {
forwardToMainPage = entity;
await Future.delayed(Duration(milliseconds: 300));
Navigator.of(context).pop();
}
@override
void dispose(){
if (_stateSubscription != null) _stateSubscription.cancel();
if (_refreshDataSubscription != null) _refreshDataSubscription.cancel();
eventBus.fire(ShowEntityPageEvent(entity: forwardToMainPage));
super.dispose();
}
}