diff --git a/lib/core/ui/bottom_bar/navigation_bar.dart b/lib/core/ui/bottom_bar/navigation_bar.dart index d615a948..e2b36a63 100644 --- a/lib/core/ui/bottom_bar/navigation_bar.dart +++ b/lib/core/ui/bottom_bar/navigation_bar.dart @@ -21,14 +21,22 @@ class LunaBottomNavigationBar extends StatefulWidget { this.leadingOnTab, this.scrollControllers, }) : super(key: key) { - assert(icons.length == titles.length, - 'An unequal amount of titles and icons were passed to LunaNavigationBar.'); - if (leadingOnTab != null) - assert(icons.length == leadingOnTab.length, - 'An unequal amount of icons and leadingOnTab were passed to LunaNavigationBar.'); - if (scrollControllers != null) - assert(icons.length == scrollControllers.length, - 'An unequal amount of icons and scrollControllers were passed to LunaNavigationBar.'); + assert( + icons.length == titles.length, + 'An unequal amount of titles and icons were passed to LunaNavigationBar.', + ); + if (leadingOnTab != null) { + assert( + icons.length == leadingOnTab.length, + 'An unequal amount of icons and leadingOnTab were passed to LunaNavigationBar.', + ); + } + if (scrollControllers != null) { + assert( + icons.length == scrollControllers.length, + 'An unequal amount of icons and scrollControllers were passed to LunaNavigationBar.', + ); + } } @override diff --git a/lib/modules/dashboard/routes/dashboard/route.dart b/lib/modules/dashboard/routes/dashboard/route.dart index c6d9d8b9..73e15f81 100644 --- a/lib/modules/dashboard/routes/dashboard/route.dart +++ b/lib/modules/dashboard/routes/dashboard/route.dart @@ -26,7 +26,8 @@ class _State extends State<_DashboardHomeRoute> { void initState() { super.initState(); _pageController = LunaPageController( - initialPage: DashboardDatabaseValue.NAVIGATION_INDEX.data); + initialPage: DashboardDatabaseValue.NAVIGATION_INDEX.data, + ); } @override @@ -51,7 +52,9 @@ class _State extends State<_DashboardHomeRoute> { useDrawer: true, scrollControllers: DashboardNavigationBar.scrollControllers, pageController: _pageController, - actions: [DashboardAppBarSwitchViewAction()], + actions: [ + DashboardAppBarSwitchViewAction(pageController: _pageController) + ], ); } diff --git a/lib/modules/dashboard/routes/dashboard/widgets/appbar_switch_view_action.dart b/lib/modules/dashboard/routes/dashboard/widgets/appbar_switch_view_action.dart index 4524253a..043f7cfc 100644 --- a/lib/modules/dashboard/routes/dashboard/widgets/appbar_switch_view_action.dart +++ b/lib/modules/dashboard/routes/dashboard/widgets/appbar_switch_view_action.dart @@ -2,23 +2,62 @@ import 'package:flutter/material.dart'; import 'package:lunasea/core.dart'; import 'package:lunasea/modules/dashboard.dart'; -class DashboardAppBarSwitchViewAction extends StatelessWidget { +class DashboardAppBarSwitchViewAction extends StatefulWidget { + final PageController pageController; + DashboardAppBarSwitchViewAction({ + Key key, + @required this.pageController, + }) : super(key: key); + + @override + State createState() => _State(); +} + +class _State extends State { + bool _showButton = false; + + @override + void initState() { + widget.pageController?.addListener(_pageControllerListener); + super.initState(); + } + + @override + void dispose() { + widget.pageController?.removeListener(_pageControllerListener); + super.dispose(); + } + + void _pageControllerListener() { + // TODO: This should be accessed in a better way: Add enum of page titles that can be mapped via an extension to icons, strings, etc. + if ((widget.pageController?.page?.round() == 1)) { + setState(() => _showButton = true); + } else { + setState(() => _showButton = false); + } + } + @override Widget build(BuildContext context) { return Selector( selector: (_, state) => state.calendarStartingType, - builder: (context, view, _) => LunaIconButton( - icon: view.icon, - onPressed: () { - if (view == CalendarStartingType.CALENDAR) { - context.read().calendarStartingType = - CalendarStartingType.SCHEDULE; - } else { - context.read().calendarStartingType = - CalendarStartingType.CALENDAR; - } - }, - ), + builder: (context, view, _) { + if (_showButton) { + return LunaIconButton( + icon: view.icon, + onPressed: () { + if (view == CalendarStartingType.CALENDAR) { + context.read().calendarStartingType = + CalendarStartingType.SCHEDULE; + } else { + context.read().calendarStartingType = + CalendarStartingType.CALENDAR; + } + }, + ); + } + return Container(); + }, ); } }