Skip to content

Commit 25a982d

Browse files
committed
- For PersistentTabView.custom, List<Widget> screens has been replaced with List<CustomNavBarScreen> screens.
- Property `routeAndNavigatorSettings` has been removed from `PersistentTabView.custom`. You now define `RouteAndNavigatorSettings` for each screen separately in `CustomNavBarScreen`. Please refer to the [Readme](https://pub.dev/packages/persistent_bottom_nav_bar#custom-navigation-bar-styling) file for more instructions.
1 parent 5407475 commit 25a982d

8 files changed

Lines changed: 165 additions & 139 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [6.2.0] - 2024-07-11
9+
- **Breaking Changes**
10+
- For `PersistentTabView.custom`, `List<Widget> screens` has been replaced with `List<CustomNavBarScreen> screens`.
11+
- Property `routeAndNavigatorSettings` has been removed from `PersistentTabView.custom`. You now define `RouteAndNavigatorSettings` for each screen separately in `CustomNavBarScreen`. Please refer to the [Readme](https://pub.dev/packages/persistent_bottom_nav_bar#custom-navigation-bar-styling) file for more instructions.
12+
813
## [6.1.1] - 2024-07-11
914
- Updated README.md
1015

README.md

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ If you are pushing a new `modal` screen, use the following function:
206206
207207
```
208208

209+
Pop all screens until the first screen on the selected tab
210+
211+
```dart
212+
213+
PersistentNavBarNavigator.popUntilFirstScreenOnSelectedTabScreen(
214+
context,
215+
routeName: "/", //If you haven't defined a routeName for the first screen of the selected tab then don't use the optional property `routeName`. Otherwise it may not work as intended
216+
);
217+
218+
```
219+
209220
### Some Useful Tips
210221

211222
- Pop to any screen in the navigation graph for a given tab:
@@ -342,7 +353,48 @@ If you want to have your own style for the navigation bar, follow these steps:
342353
return PersistentTabView.custom(
343354
context,
344355
controller: _controller,
345-
screens: _buildScreens(),
356+
screens: [
357+
CustomNavBarScreen(
358+
//You can declare route settings for custom navigation bar screen here
359+
routeAndNavigatorSettings: RouteAndNavigatorSettings(
360+
initialRoute: "/",
361+
routes: {
362+
"/first": (final context) => const MainScreen2(),
363+
"/second": (final context) => const MainScreen3(),
364+
},
365+
),
366+
screen: MainScreen(
367+
menuScreenContext: widget.menuScreenContext,
368+
scrollController: _scrollControllers.first,
369+
370+
), ),
371+
CustomNavBarScreen(
372+
screen: MainScreen(
373+
menuScreenContext: widget.menuScreenContext,
374+
scrollController: _scrollControllers[1],
375+
376+
),
377+
),
378+
CustomNavBarScreen(
379+
screen: MainScreen(
380+
menuScreenContext: widget.menuScreenContext,
381+
scrollController: _scrollControllers[2],
382+
),
383+
),
384+
CustomNavBarScreen(
385+
screen: MainScreen(
386+
menuScreenContext: widget.menuScreenContext,
387+
scrollController: _scrollControllers[3],
388+
389+
),
390+
),
391+
CustomNavBarScreen(
392+
screen: MainScreen(
393+
menuScreenContext: widget.menuScreenContext,
394+
scrollController: _scrollControllers.last,
395+
),
396+
),
397+
],
346398
itemCount: 5,
347399
isVisible: true,
348400
hideOnScrollSettings: HideOnScrollSettings(
@@ -351,8 +403,7 @@ If you want to have your own style for the navigation bar, follow these steps:
351403
),
352404
backgroundColor: Colors.grey.shade900,
353405
customWidget: CustomNavBarWidget(
354-
_navBarsItems(),
355-
onItemSelected: (final index) {
406+
_navBarsItems(), onItemSelected: (final index) {
356407
//Scroll to top for custom widget. For non custom widget, declare property `scrollController` in `PersistentBottomNavBarItem`.
357408
if (index == _controller.index) {
358409
_scrollControllers[index].animateTo(0, duration: const Duration(milliseconds: 200), curve: Curves.ease);
@@ -364,8 +415,7 @@ If you want to have your own style for the navigation bar, follow these steps:
364415
selectedIndex: _controller.index,
365416
),
366417
),
367-
}
368-
}
418+
} }
369419
370420
```
371421

example/lib/custom-widget-tabs.widget.dart

Lines changed: 68 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -43,61 +43,78 @@ class _CustomWidgetExampleState extends State<CustomWidgetExample> {
4343
super.dispose();
4444
}
4545

46-
List<Widget> _buildScreens() => [
47-
MainScreen(
48-
menuScreenContext: widget.menuScreenContext,
49-
scrollController: _scrollControllers.first,
50-
hideStatus: _hideNavBar,
51-
showNavBarStyles: false,
52-
onScreenHideButtonPressed: () {
53-
setState(() {
54-
_hideNavBar = !_hideNavBar;
55-
});
56-
},
46+
List<CustomNavBarScreen> _buildScreens() => [
47+
CustomNavBarScreen(
48+
routeAndNavigatorSettings: RouteAndNavigatorSettings(
49+
initialRoute: "/",
50+
routes: {
51+
"/first": (final context) => const MainScreen2(),
52+
"/second": (final context) => const MainScreen3(),
53+
},
54+
),
55+
screen: MainScreen(
56+
menuScreenContext: widget.menuScreenContext,
57+
scrollController: _scrollControllers.first,
58+
hideStatus: _hideNavBar,
59+
showNavBarStyles: false,
60+
onScreenHideButtonPressed: () {
61+
setState(() {
62+
_hideNavBar = !_hideNavBar;
63+
});
64+
},
65+
),
5766
),
58-
MainScreen(
59-
menuScreenContext: widget.menuScreenContext,
60-
scrollController: _scrollControllers[1],
61-
hideStatus: _hideNavBar,
62-
showNavBarStyles: false,
63-
onScreenHideButtonPressed: () {
64-
setState(() {
65-
_hideNavBar = !_hideNavBar;
66-
});
67-
},
67+
CustomNavBarScreen(
68+
screen: MainScreen(
69+
menuScreenContext: widget.menuScreenContext,
70+
scrollController: _scrollControllers[1],
71+
hideStatus: _hideNavBar,
72+
showNavBarStyles: false,
73+
onScreenHideButtonPressed: () {
74+
setState(() {
75+
_hideNavBar = !_hideNavBar;
76+
});
77+
},
78+
),
6879
),
69-
MainScreen(
70-
menuScreenContext: widget.menuScreenContext,
71-
scrollController: _scrollControllers[2],
72-
hideStatus: _hideNavBar,
73-
showNavBarStyles: false,
74-
onScreenHideButtonPressed: () {
75-
setState(() {
76-
_hideNavBar = !_hideNavBar;
77-
});
78-
},
80+
CustomNavBarScreen(
81+
screen: MainScreen(
82+
menuScreenContext: widget.menuScreenContext,
83+
scrollController: _scrollControllers[2],
84+
hideStatus: _hideNavBar,
85+
showNavBarStyles: false,
86+
onScreenHideButtonPressed: () {
87+
setState(() {
88+
_hideNavBar = !_hideNavBar;
89+
});
90+
},
91+
),
7992
),
80-
MainScreen(
81-
menuScreenContext: widget.menuScreenContext,
82-
scrollController: _scrollControllers[3],
83-
hideStatus: _hideNavBar,
84-
showNavBarStyles: false,
85-
onScreenHideButtonPressed: () {
86-
setState(() {
87-
_hideNavBar = !_hideNavBar;
88-
});
89-
},
93+
CustomNavBarScreen(
94+
screen: MainScreen(
95+
menuScreenContext: widget.menuScreenContext,
96+
scrollController: _scrollControllers[3],
97+
hideStatus: _hideNavBar,
98+
showNavBarStyles: false,
99+
onScreenHideButtonPressed: () {
100+
setState(() {
101+
_hideNavBar = !_hideNavBar;
102+
});
103+
},
104+
),
90105
),
91-
MainScreen(
92-
menuScreenContext: widget.menuScreenContext,
93-
scrollController: _scrollControllers.last,
94-
hideStatus: _hideNavBar,
95-
showNavBarStyles: false,
96-
onScreenHideButtonPressed: () {
97-
setState(() {
98-
_hideNavBar = !_hideNavBar;
99-
});
100-
},
106+
CustomNavBarScreen(
107+
screen: MainScreen(
108+
menuScreenContext: widget.menuScreenContext,
109+
scrollController: _scrollControllers.last,
110+
hideStatus: _hideNavBar,
111+
showNavBarStyles: false,
112+
onScreenHideButtonPressed: () {
113+
setState(() {
114+
_hideNavBar = !_hideNavBar;
115+
});
116+
},
117+
),
101118
),
102119
];
103120

lib/models/persistent_bottom_nav_item.widget.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class PersistentBottomNavBarItem {
1818
this.onSelectedTabPressWhenNoScreensPushed,
1919
this.iconAnimationController,
2020
this.scrollController,
21-
this.routeAndNavigatorSettings = const RouteAndNavigatorSettings(),
21+
this.routeAndNavigatorSettings,
2222
this.scrollToTopOnNavBarItemPress = true,
2323
this.onPressed})
2424
: assert(opacity >= 0 && opacity <= 1.0,
@@ -75,7 +75,7 @@ class PersistentBottomNavBarItem {
7575

7676
final double iconSize;
7777

78-
final RouteAndNavigatorSettings routeAndNavigatorSettings;
78+
final RouteAndNavigatorSettings? routeAndNavigatorSettings;
7979

8080
///For animated icons to work, this property must not be `null` or left empty.
8181
final AnimationController? iconAnimationController;

lib/models/route_settings.model.dart

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,46 +44,10 @@ class RouteAndNavigatorSettings {
4444
);
4545
}
4646

47-
class CustomWidgetRouteAndNavigatorSettings {
48-
const CustomWidgetRouteAndNavigatorSettings({
49-
this.defaultTitle,
50-
this.routes,
51-
this.onGenerateRoute,
52-
this.onUnknownRoute,
53-
this.initialRoute,
54-
this.navigatorObservers = const <NavigatorObserver>[],
55-
this.navigatorKeys,
56-
});
57-
final String? defaultTitle;
47+
class CustomNavBarScreen {
48+
const CustomNavBarScreen(
49+
{required this.screen, this.routeAndNavigatorSettings});
5850

59-
final Map<String, WidgetBuilder>? routes;
60-
61-
final RouteFactory? onGenerateRoute;
62-
63-
final RouteFactory? onUnknownRoute;
64-
65-
final String? initialRoute;
66-
67-
final List<NavigatorObserver> navigatorObservers;
68-
69-
final List<GlobalKey<NavigatorState>>? navigatorKeys;
70-
71-
CustomWidgetRouteAndNavigatorSettings copyWith({
72-
final String? defaultTitle,
73-
final Map<String, WidgetBuilder>? routes,
74-
final RouteFactory? onGenerateRoute,
75-
final RouteFactory? onUnknownRoute,
76-
final String? initialRoute,
77-
final List<NavigatorObserver>? navigatorObservers,
78-
final List<GlobalKey<NavigatorState>>? navigatorKeys,
79-
}) =>
80-
CustomWidgetRouteAndNavigatorSettings(
81-
defaultTitle: defaultTitle ?? this.defaultTitle,
82-
routes: routes ?? this.routes,
83-
onGenerateRoute: onGenerateRoute ?? this.onGenerateRoute,
84-
onUnknownRoute: onUnknownRoute ?? this.onUnknownRoute,
85-
initialRoute: initialRoute ?? this.initialRoute,
86-
navigatorObservers: navigatorObservers ?? this.navigatorObservers,
87-
navigatorKeys: navigatorKeys ?? this.navigatorKeys,
88-
);
51+
final Widget screen;
52+
final RouteAndNavigatorSettings? routeAndNavigatorSettings;
8953
}

0 commit comments

Comments
 (0)