Bring back separate entity page

This commit is contained in:
Yegor Vialov
2020-04-13 18:15:14 +00:00
parent 2125c46143
commit 8bf2d31e72
2 changed files with 15 additions and 71 deletions

View File

@ -13,8 +13,6 @@ class _EntityViewPageState extends State<EntityViewPage> {
StreamSubscription _refreshDataSubscription; StreamSubscription _refreshDataSubscription;
StreamSubscription _stateSubscription; StreamSubscription _stateSubscription;
Entity entity; Entity entity;
Entity forwardToMainPage;
bool _popScheduled = false;
@override @override
void initState() { void initState() {
@ -35,16 +33,6 @@ class _EntityViewPageState extends State<EntityViewPage> {
@override @override
Widget build(BuildContext context) { 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( return new Scaffold(
appBar: new AppBar( appBar: new AppBar(
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){ leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
@ -52,21 +40,14 @@ class _EntityViewPageState extends State<EntityViewPage> {
}), }),
title: new Text("${entity.displayName}"), 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 @override
void dispose(){ void dispose(){
if (_stateSubscription != null) _stateSubscription.cancel(); if (_stateSubscription != null) _stateSubscription.cancel();
if (_refreshDataSubscription != null) _refreshDataSubscription.cancel(); if (_refreshDataSubscription != null) _refreshDataSubscription.cancel();
eventBus.fire(ShowEntityPageEvent(entity: forwardToMainPage));
super.dispose(); super.dispose();
} }
} }

View File

@ -25,7 +25,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
int _previousViewCount; int _previousViewCount;
bool _showLoginButton = false; bool _showLoginButton = false;
bool _preventAppRefresh = false; bool _preventAppRefresh = false;
Entity _entityToShow;
@override @override
void initState() { void initState() {
@ -125,9 +124,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
} }
await HomeAssistant().fetchData(uiOnly).then((_) { await HomeAssistant().fetchData(uiOnly).then((_) {
_hideBottomBar(); _hideBottomBar();
if (_entityToShow != null) {
_entityToShow = HomeAssistant().entities.get(_entityToShow.entityId);
}
}).catchError((e) { }).catchError((e) {
if (e is HAError) { if (e is HAError) {
_setErrorState(e); _setErrorState(e);
@ -302,12 +298,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
} }
void _showEntityPage(String entityId) { void _showEntityPage(String entityId) {
setState(() { Navigator.push(
_entityToShow = HomeAssistant().entities?.get(entityId); context,
if (_entityToShow != null) { MaterialPageRoute(
_mainScrollController?.jumpTo(0); builder: (context) => EntityViewPage(entityId: entityId),
} )
}); );
/*if (_entityToShow!= null && MediaQuery.of(context).size.width < Sizes.tabletMinWidth) { /*if (_entityToShow!= null && MediaQuery.of(context).size.width < Sizes.tabletMinWidth) {
Navigator.push( Navigator.push(
context, context,
@ -591,7 +587,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
} }
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final ScrollController _mainScrollController = ScrollController();
Widget _buildScaffoldBody(bool empty) { Widget _buildScaffoldBody(bool empty) {
List<PopupMenuItem<String>> serviceMenuItems = []; List<PopupMenuItem<String>> serviceMenuItems = [];
@ -696,30 +691,9 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
), ),
); );
} }
} else {
if (_entityToShow != null && MediaQuery.of(context).size.width >= Sizes.tabletMinWidth) {
mainScrollBody = Flex(
direction: Axis.horizontal,
children: <Widget>[
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 { } else {
mainScrollBody = HomeAssistant().ui.build(context, _viewsTabController); mainScrollBody = HomeAssistant().ui.build(context, _viewsTabController);
} }
}
return NestedScrollView( return NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
@ -774,7 +748,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
_scaffoldKey.currentState.openDrawer(); _scaffoldKey.currentState.openDrawer();
}, },
), ),
bottom: (empty || _entityToShow != null) ? null : TabBar( bottom: empty ? null : TabBar(
controller: _viewsTabController, controller: _viewsTabController,
tabs: buildUIViewTabs(), tabs: buildUIViewTabs(),
isScrollable: true, isScrollable: true,
@ -784,7 +758,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
]; ];
}, },
body: mainScrollBody, body: mainScrollBody,
controller: _mainScrollController,
); );
} }
@ -849,22 +822,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
body: _buildScaffoldBody(true) body: _buildScaffoldBody(true)
); );
} else { } else {
return WillPopScope( return Scaffold(
child: Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
drawer: _buildAppDrawer(), drawer: _buildAppDrawer(),
primary: false, primary: false,
bottomNavigationBar: bottomBar, bottomNavigationBar: bottomBar,
body: _buildScaffoldBody(false) body: _buildScaffoldBody(false)
),
onWillPop: () {
if (_entityToShow != null) {
eventBus.fire(ShowEntityPageEvent());
return Future.value(false);
} else {
return Future.value(true);
}
},
); );
} }
} }