Skip to content

Commit

Permalink
Fix popAllScreensOnTapOfSelectedTab and onSelectedTabPressWhenNoScree…
Browse files Browse the repository at this point in the history
…nsPushed not working properly when an initialRoute was set for that tab
  • Loading branch information
jb3rndt committed Apr 24, 2024
1 parent 8da642e commit 212f57b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- popAllScreensOnTapOfSelectedTab and onSelectedTabPressWhenNoScreensPushed did not work properly when an initialRoute was set for that tab

## [5.2.2] - 2024-04-11
### Fixed
- NavigatorConfig.initialRoute did not get passed to the respective Navigator
- Mark ItemConfig.color and filter as deprecated

## [5.2.1] - 2024-04-10
### Fixed
Expand Down Expand Up @@ -559,6 +564,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Includes platform specific behavior as an option (specify it in the two navigator functions).
- Based on flutter's Cupertino(iOS) bottom navigation bar.

[Unreleased]: https://github.com/jb3rndt/PersistentBottomNavBarV2/compare/5.2.2...HEAD
[5.2.2]: https://github.com/jb3rndt/PersistentBottomNavBarV2/compare/5.2.1...5.2.2
[5.2.1]: https://github.com/jb3rndt/PersistentBottomNavBarV2/compare/5.2.0...5.2.1
[5.2.0]: https://github.com/jb3rndt/PersistentBottomNavBarV2/compare/5.1.0...5.2.0
Expand Down
36 changes: 13 additions & 23 deletions lib/components/persistent_tab_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,16 @@ class _PersistentTabViewState extends State<PersistentTabView> {
if (!widget.handleAndroidBackButtonPress && widget.onWillPop != null) {
return widget.onWillPop!(_contextList[_controller.index]!);
} else {
if (_controller.historyIsEmpty() &&
!_navigatorKeys[_controller.index].currentState!.canPop()) {
final navigator = _navigatorKeys[_controller.index].currentState!;
if (_controller.historyIsEmpty() && !navigator.canPop()) {
if (widget.handleAndroidBackButtonPress && widget.onWillPop != null) {
return widget.onWillPop!(_contextList[_controller.index]!);
}
// CanPop should be true in this case, so we dont return true because the pop already happened
return false;
} else {
if (_navigatorKeys[_controller.index].currentState!.canPop()) {
_navigatorKeys[_controller.index].currentState!.pop();
if (navigator.canPop()) {
navigator.pop();
} else {
_controller.jumpToPreviousTab();
}
Expand All @@ -402,26 +402,16 @@ class _PersistentTabViewState extends State<PersistentTabView> {
void popAllScreens() {
if (widget.popAllScreensOnTapOfSelectedTab ||
widget.popAllScreensOnTapAnyTabs) {
if (widget.tabs[_controller.index]
.onSelectedTabPressWhenNoScreensPushed !=
null &&
!Navigator.of(_contextList[_controller.index]!).canPop()) {
widget.tabs[_controller.index].onSelectedTabPressWhenNoScreensPushed!();
}

if (widget.popActionScreens == PopActionScreensType.once) {
if (Navigator.of(_contextList[_controller.index]!).canPop()) {
Navigator.of(_contextList[_controller.index]!).pop(context);
return;
}
final navigator = _navigatorKeys[_controller.index].currentState!;
if (!navigator.canPop()) {
widget.tabs[_controller.index].onSelectedTabPressWhenNoScreensPushed
?.call();
} else {
Navigator.popUntil(
_contextList[_controller.index]!,
ModalRoute.withName(
widget.tabs[_controller.index].navigatorConfig.initialRoute ??
Navigator.defaultRouteName,
),
);
if (widget.popActionScreens == PopActionScreensType.once) {
navigator.maybePop(context);
} else {
navigator.popUntil(ModalRoute.withName(Navigator.defaultRouteName));
}
}
}
}
Expand Down

0 comments on commit 212f57b

Please sign in to comment.