Skip to content

Commit

Permalink
Navigation/MD pages: pop all but first on select (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-loose committed Jan 9, 2023
1 parent 546ebe3 commit bace561
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/src/layouts/yaru_landscape_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const _kLeftPaneResizingRegionAnimationDuration = Duration(milliseconds: 250);

class _YaruLandscapeLayoutState extends State<YaruLandscapeLayout> {
late int _selectedIndex;
final _navigatorKey = GlobalKey<NavigatorState>();

double? _paneWidth;
double? _initialPaneWidth;
Expand Down Expand Up @@ -83,6 +84,7 @@ class _YaruLandscapeLayoutState extends State<YaruLandscapeLayout> {
void _onTap(int index) {
widget.controller.index = index;
widget.onSelected?.call(_selectedIndex);
_navigatorKey.currentState?.popUntil((route) => route.isFirst);
}

void updatePaneWidth({
Expand Down Expand Up @@ -189,6 +191,7 @@ class _YaruLandscapeLayoutState extends State<YaruLandscapeLayout> {
),
child: ScaffoldMessenger(
child: Navigator(
key: _navigatorKey,
pages: [
MaterialPage(
key: ValueKey(_selectedIndex),
Expand Down
3 changes: 3 additions & 0 deletions lib/src/layouts/yaru_navigation_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class YaruNavigationPage extends StatefulWidget {
class _YaruNavigationPageState extends State<YaruNavigationPage> {
late final ScrollController _scrollController;
late YaruPageController _pageController;
final _navigatorKey = GlobalKey<NavigatorState>();

@override
void initState() {
Expand Down Expand Up @@ -127,6 +128,7 @@ class _YaruNavigationPageState extends State<YaruNavigationPage> {
void _onTap(int index) {
_pageController.index = index;
widget.onSelected?.call(index);
_navigatorKey.currentState?.popUntil((route) => route.isFirst);
}

Widget _buildNavigationRail(BuildContext context, BoxConstraints constraint) {
Expand Down Expand Up @@ -167,6 +169,7 @@ class _YaruNavigationPageState extends State<YaruNavigationPage> {
pageTransitionsTheme: theme.pageTransitions,
),
child: Navigator(
key: _navigatorKey,
pages: [
MaterialPage(
key: ValueKey(index),
Expand Down

0 comments on commit bace561

Please sign in to comment.