mirror of
https://github.com/jagandeepbrar/lunasea.git
synced 2026-08-31 04:32:32 +00:00
fix(dashboard): Only show AppBar toggle icon on calendar page
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<StatefulWidget> createState() => _State();
|
||||
}
|
||||
|
||||
class _State extends State<DashboardAppBarSwitchViewAction> {
|
||||
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<DashboardState, CalendarStartingType>(
|
||||
selector: (_, state) => state.calendarStartingType,
|
||||
builder: (context, view, _) => LunaIconButton(
|
||||
icon: view.icon,
|
||||
onPressed: () {
|
||||
if (view == CalendarStartingType.CALENDAR) {
|
||||
context.read<DashboardState>().calendarStartingType =
|
||||
CalendarStartingType.SCHEDULE;
|
||||
} else {
|
||||
context.read<DashboardState>().calendarStartingType =
|
||||
CalendarStartingType.CALENDAR;
|
||||
}
|
||||
},
|
||||
),
|
||||
builder: (context, view, _) {
|
||||
if (_showButton) {
|
||||
return LunaIconButton(
|
||||
icon: view.icon,
|
||||
onPressed: () {
|
||||
if (view == CalendarStartingType.CALENDAR) {
|
||||
context.read<DashboardState>().calendarStartingType =
|
||||
CalendarStartingType.SCHEDULE;
|
||||
} else {
|
||||
context.read<DashboardState>().calendarStartingType =
|
||||
CalendarStartingType.CALENDAR;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
return Container();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user