Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add popAllScreensForTheSelectedTab functionality for custom navbar #166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion example/lib/custom-widget-tabs.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ class _CustomWidgetExampleState extends State<CustomWidgetExample> {
context,
controller: _controller,
screens: _buildScreens(),
items: _buildScreens()
.map((e) => PersistentBottomNavBarItem.custom())
.toList(),
confineInSafeArea: true,
itemCount: 5,
handleAndroidBackButtonPress: true,
Expand All @@ -137,9 +140,12 @@ class _CustomWidgetExampleState extends State<CustomWidgetExample> {
curve: Curves.ease,
duration: Duration(milliseconds: 200),
),
customWidget: CustomNavBarWidget(
customWidget: (NavBarEssentials navBarEssentials) => CustomNavBarWidget(
items: _navBarsItems(),
onItemSelected: (index) {
if (index == _controller.index)
navBarEssentials.popAllScreensForTheSelectedTab(index);

setState(() {
_controller.index = index; // THIS IS CRITICAL!! Don't miss it!
});
Expand Down
14 changes: 14 additions & 0 deletions lib/models/persisten-bottom-nav-item.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,18 @@ class PersistentBottomNavBarItem {
assert(icon != null);
assert(opacity >= 0 && opacity <= 1.0);
}

PersistentBottomNavBarItem.custom(
{this.icon,
this.title,
this.contentPadding = 5.0,
this.activeColor = CupertinoColors.activeBlue,
this.activeColorAlternate,
this.opacity = 1.0,
this.inactiveColor,
this.filter,
this.textStyle,
this.iconSize = 26.0,
this.onSelectedTabPressWhenNoScreensPushed,
this.onPressed});
}
8 changes: 4 additions & 4 deletions lib/models/persistent-bottom-nav-bar.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PersistentBottomNavBar extends StatelessWidget {
final NavBarDecoration navBarDecoration;
final NavBarStyle navBarStyle;
final NeumorphicProperties neumorphicProperties;
final Widget customNavBarWidget;
final Widget Function(NavBarEssentials navBarEssentials) customNavBarWidget;
final bool confineToSafeArea;
final bool hideNavigationBar;
final Function(bool, bool) onAnimationComplete;
Expand All @@ -38,7 +38,7 @@ class PersistentBottomNavBar extends StatelessWidget {
: confineToSafeArea ?? true,
child: Container(
color: this.navBarEssentials.backgroundColor,
child: this.customNavBarWidget,
child: this.customNavBarWidget(navBarEssentials),
),
)
: Container(
Expand All @@ -49,7 +49,7 @@ class PersistentBottomNavBar extends StatelessWidget {
(this.hideNavigationBar ?? false)
? false
: confineToSafeArea ?? true,
child: this.customNavBarWidget),
child: this.customNavBarWidget(navBarEssentials)),
)
: this.navBarStyle == NavBarStyle.style15 ||
this.navBarStyle == NavBarStyle.style16
Expand Down Expand Up @@ -198,7 +198,7 @@ class PersistentBottomNavBar extends StatelessWidget {

Widget getNavBarStyle() {
if (isCustomWidget) {
return customNavBarWidget;
return this.customNavBarWidget(navBarEssentials);
} else {
switch (navBarStyle) {
case NavBarStyle.style1:
Expand Down
99 changes: 55 additions & 44 deletions lib/persistent-tab-view.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,49 +140,51 @@ class PersistentTabView extends PersistentTabViewBase {
"Number of 'Navigator Keys' must be equal to the number of bottom navigation tabs.");
}

PersistentTabView.custom(
this.context, {
Key key,
@required this.screens,
this.controller,
this.margin = EdgeInsets.zero,
this.floatingActionButton,
Widget customWidget,
int itemCount,
this.resizeToAvoidBottomInset = false,
this.bottomScreenMargin,
this.selectedTabScreenContext,
this.hideNavigationBarWhenKeyboardShows = true,
this.backgroundColor = CupertinoColors.white,
this.routeAndNavigatorSettings = const RouteAndNavigatorSettings(),
this.confineInSafeArea = true,
this.onWillPop,
this.stateManagement = true,
this.handleAndroidBackButtonPress = true,
this.hideNavigationBar,
this.screenTransitionAnimation = const ScreenTransitionAnimation(),
}) : super(
key: key,
context: context,
screens: screens,
controller: controller,
margin: margin,
routeAndNavigatorSettings: routeAndNavigatorSettings,
backgroundColor: backgroundColor,
floatingActionButton: floatingActionButton,
customWidget: customWidget,
itemCount: itemCount,
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
bottomScreenMargin: bottomScreenMargin,
onWillPop: onWillPop,
confineInSafeArea: confineInSafeArea,
stateManagement: stateManagement,
handleAndroidBackButtonPress: handleAndroidBackButtonPress,
hideNavigationBar: hideNavigationBar,
screenTransitionAnimation: screenTransitionAnimation,
isCustomWidget: true,
decoration: NavBarDecoration(),
) {
PersistentTabView.custom(this.context,
{Key key,
List<PersistentBottomNavBarItem> items,
@required this.screens,
this.controller,
this.margin = EdgeInsets.zero,
this.floatingActionButton,
Widget Function(NavBarEssentials navBarEssentials) customWidget,
int itemCount,
this.resizeToAvoidBottomInset = false,
this.bottomScreenMargin,
this.selectedTabScreenContext,
this.hideNavigationBarWhenKeyboardShows = true,
this.backgroundColor = CupertinoColors.white,
this.routeAndNavigatorSettings = const RouteAndNavigatorSettings(),
this.confineInSafeArea = true,
this.onWillPop,
this.stateManagement = true,
this.handleAndroidBackButtonPress = true,
this.hideNavigationBar,
this.screenTransitionAnimation = const ScreenTransitionAnimation(),
bool popAllScreensOnTapOfSelectedTab = true})
: super(
key: key,
items: items,
context: context,
screens: screens,
controller: controller,
margin: margin,
routeAndNavigatorSettings: routeAndNavigatorSettings,
backgroundColor: backgroundColor,
floatingActionButton: floatingActionButton,
customWidget: customWidget,
itemCount: itemCount,
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
bottomScreenMargin: bottomScreenMargin,
onWillPop: onWillPop,
confineInSafeArea: confineInSafeArea,
stateManagement: stateManagement,
handleAndroidBackButtonPress: handleAndroidBackButtonPress,
hideNavigationBar: hideNavigationBar,
screenTransitionAnimation: screenTransitionAnimation,
isCustomWidget: true,
decoration: NavBarDecoration(),
popAllScreensOnTapOfSelectedTab: popAllScreensOnTapOfSelectedTab) {
assert(itemCount != null,
"In case of custom navigation bar style, the property itemCount is required!");
assert(screens != null, "screens property is required");
Expand All @@ -195,6 +197,15 @@ class PersistentTabView extends PersistentTabViewBase {
routeAndNavigatorSettings.navigatorKeys != null &&
routeAndNavigatorSettings.navigatorKeys.length != items.length,
"Number of 'Navigator Keys' must be equal to the number of bottom navigation tabs.");
assert(popAllScreensOnTapOfSelectedTab != null,
'popAllScreensOnTapOfSelectedTab must not be null');
assert(
(popAllScreensOnTapOfSelectedTab &&
items != null &&
items.isNotEmpty &&
items.length == screens.length) ||
!popAllScreensOnTapOfSelectedTab,
"items must not be null/empty and should have the same length with the screens");
}
}

Expand Down Expand Up @@ -242,7 +253,7 @@ class PersistentTabViewBase extends StatefulWidget {
final EdgeInsets margin;

///Custom navigation bar widget. To be only used when `navBarStyle` is set to `NavBarStyle.custom`.
final Widget customWidget;
final Widget Function(NavBarEssentials navBarEssentials) customWidget;

///If using `custom` navBarStyle, define this instead of the `items` property
final int itemCount;
Expand Down