From 8bf2d31e72963008fccdc620b52a687cca3d924b Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Mon, 13 Apr 2020 18:15:14 +0000 Subject: [PATCH] Bring back separate entity page --- lib/pages/entity.page.dart | 21 +---------- lib/pages/main/main.page.dart | 65 ++++++++--------------------------- 2 files changed, 15 insertions(+), 71 deletions(-) diff --git a/lib/pages/entity.page.dart b/lib/pages/entity.page.dart index 253fac7..8d378f0 100644 --- a/lib/pages/entity.page.dart +++ b/lib/pages/entity.page.dart @@ -13,8 +13,6 @@ class _EntityViewPageState extends State { StreamSubscription _refreshDataSubscription; StreamSubscription _stateSubscription; Entity entity; - Entity forwardToMainPage; - bool _popScheduled = false; @override void initState() { @@ -35,16 +33,6 @@ class _EntityViewPageState extends State { @override Widget build(BuildContext context) { - Widget body; - if (MediaQuery.of(context).size.width >= Sizes.tabletMinWidth) { - if (!_popScheduled) { - _popScheduled = true; - _popAfterBuild(); - } - body = PageLoadingIndicator(); - } else { - body = EntityPageLayout(entity: entity); - } return new Scaffold( appBar: new AppBar( leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){ @@ -52,21 +40,14 @@ class _EntityViewPageState extends State { }), title: new Text("${entity.displayName}"), ), - body: body, + body: EntityPageLayout(entity: entity), ); } - _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(); } } \ No newline at end of file diff --git a/lib/pages/main/main.page.dart b/lib/pages/main/main.page.dart index 5ebdd38..ff55e4f 100644 --- a/lib/pages/main/main.page.dart +++ b/lib/pages/main/main.page.dart @@ -25,7 +25,6 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker int _previousViewCount; bool _showLoginButton = false; bool _preventAppRefresh = false; - Entity _entityToShow; @override void initState() { @@ -125,9 +124,6 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker } await HomeAssistant().fetchData(uiOnly).then((_) { _hideBottomBar(); - if (_entityToShow != null) { - _entityToShow = HomeAssistant().entities.get(_entityToShow.entityId); - } }).catchError((e) { if (e is HAError) { _setErrorState(e); @@ -302,12 +298,12 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker } void _showEntityPage(String entityId) { - setState(() { - _entityToShow = HomeAssistant().entities?.get(entityId); - if (_entityToShow != null) { - _mainScrollController?.jumpTo(0); - } - }); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => EntityViewPage(entityId: entityId), + ) + ); /*if (_entityToShow!= null && MediaQuery.of(context).size.width < Sizes.tabletMinWidth) { Navigator.push( context, @@ -591,7 +587,6 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker } final GlobalKey _scaffoldKey = new GlobalKey(); - final ScrollController _mainScrollController = ScrollController(); Widget _buildScaffoldBody(bool empty) { List> serviceMenuItems = []; @@ -697,28 +692,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker ); } } else { - if (_entityToShow != null && MediaQuery.of(context).size.width >= Sizes.tabletMinWidth) { - mainScrollBody = Flex( - direction: Axis.horizontal, - children: [ - Expanded( - child: HomeAssistant().ui.build(context, _viewsTabController), - ), - Container( - width: Sizes.mainPageScreenSeparatorWidth, - color: Colors.blue, - ), - ConstrainedBox( - constraints: BoxConstraints.tightFor(width: Sizes.entityPageMaxWidth), - child: EntityPageLayout(entity: _entityToShow, showClose: true,), - ) - ], - ); - } else if (_entityToShow != null) { - mainScrollBody = EntityPageLayout(entity: _entityToShow, showClose: true,); - } else { - mainScrollBody = HomeAssistant().ui.build(context, _viewsTabController); - } + mainScrollBody = HomeAssistant().ui.build(context, _viewsTabController); } return NestedScrollView( @@ -774,7 +748,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker _scaffoldKey.currentState.openDrawer(); }, ), - bottom: (empty || _entityToShow != null) ? null : TabBar( + bottom: empty ? null : TabBar( controller: _viewsTabController, tabs: buildUIViewTabs(), isScrollable: true, @@ -784,7 +758,6 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker ]; }, body: mainScrollBody, - controller: _mainScrollController, ); } @@ -849,22 +822,12 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker body: _buildScaffoldBody(true) ); } else { - return WillPopScope( - child: Scaffold( - key: _scaffoldKey, - drawer: _buildAppDrawer(), - primary: false, - bottomNavigationBar: bottomBar, - body: _buildScaffoldBody(false) - ), - onWillPop: () { - if (_entityToShow != null) { - eventBus.fire(ShowEntityPageEvent()); - return Future.value(false); - } else { - return Future.value(true); - } - }, + return Scaffold( + key: _scaffoldKey, + drawer: _buildAppDrawer(), + primary: false, + bottomNavigationBar: bottomBar, + body: _buildScaffoldBody(false) ); } }