Skip to content

Commit

Permalink
add BartMenuRoute.bottomBarBuilder isActive property to builder
Browse files Browse the repository at this point in the history
  • Loading branch information
g-apparence committed Jan 5, 2024
1 parent 8e79f6c commit 7942160
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 88 deletions.
57 changes: 37 additions & 20 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
## [1.4.0]

- add BartMenuRoute.bottomBarBuilder isActive property to builder

## [1.3.0]
* NavigationRail sidebar or custom sidebar is now available

- NavigationRail sidebar or custom sidebar is now available

## [1.2.1]
* Fix prevent rebuilding bottom items when route change

- Fix prevent rebuilding bottom items when route change

## [1.2.0]
* Add BartMenuRoute.bottomBarBuilder to build a single item bottom bar (so you can show notification badge on it)
* Add onRouteChanged callback to BartScaffold to get notified when route change

- Add BartMenuRoute.bottomBarBuilder to build a single item bottom bar (so you
can show notification badge on it)
- Add onRouteChanged callback to BartScaffold to get notified when route change

## [1.1.0]
* Material 3 bottom bar theme
* Hide / show bottom bar from action

- Material 3 bottom bar theme
- Hide / show bottom bar from action

## [1.0.0]
* enable hot reload
* parent context is now available
* will pop scope is now supported
* nested route can be canceled by tapping on parent tab item
* rework how Bart work to improve stability & performance

- enable hot reload
- parent context is now available
- will pop scope is now supported
- nested route can be canceled by tapping on parent tab item
- rework how Bart work to improve stability & performance

## [0.3.1]
* upgrade android example project

- upgrade android example project

## [0.3.0]
* preserve state and scroll within navigation if cache activated

- preserve state and scroll within navigation if cache activated

## [0.2.0]
* remove unnecessary null check

- remove unnecessary null check

## [0.1.1] - Transitions
* handle transition for routes (optionnal) default is none
* handle transition duration for routes (optionnal) default is 300ms

- handle transition for routes (optionnal) default is none
- handle transition duration for routes (optionnal) default is 300ms

## [0.1.0] - Add settings to page build
* add args setting to sub navigation

- add args setting to sub navigation

## [0.0.3] - Cache and Appbar animation
* show or hide appbar with animation
* preserve page in cache (see readme)

- show or hide appbar with animation
- preserve page in cache (see readme)

## [0.0.1] - First release
* first release

- first release
33 changes: 19 additions & 14 deletions example/lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,27 @@ List<BartMenuRoute> subRoutes() {
),
BartMenuRoute.bottomBarBuilder(
label: "Library",
builder: (context) => BottomBarIcon.builder(
icon: const Icon(Icons.notifications),
top: -4.0,
right: 0.0,
notificationBuilder: (context) => Container(
decoration: const BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
builder: (context, isActive) {
return BottomBarIcon.builder(
icon: Icon(
Icons.notifications,
color: isActive ? Colors.blue : Colors.grey,
),
padding: const EdgeInsets.all(4),
child: const Text(
"1",
style: TextStyle(color: Colors.white, fontSize: 10),
top: -4.0,
right: 0.0,
notificationBuilder: (context) => Container(
decoration: const BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
padding: const EdgeInsets.all(4),
child: const Text(
"1",
style: TextStyle(color: Colors.white, fontSize: 10),
),
),
),
),
);
},
path: '/library',
pageBuilder: (parentContext, tabContext, settings) => const FakeListPage(
key: PageStorageKey<String>("library"),
Expand Down
34 changes: 17 additions & 17 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ packages:
dependency: "direct main"
description:
name: animations
sha256: ef57563eed3620bd5d75ad96189846aca1e033c0c45fc9a7d26e80ab02b88a70
sha256: d3d6dcfb218225bbe68e87ccf6378bbb2e32a94900722c5f81611dad089911cb
url: "https://pub.dev"
source: hosted
version: "2.0.8"
version: "2.0.11"
async:
dependency: transitive
description:
Expand All @@ -23,7 +23,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.3.0"
version: "1.4.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -60,10 +60,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.2"
version: "1.18.0"
csslib:
dependency: transitive
description:
Expand Down Expand Up @@ -142,10 +142,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
path:
dependency: transitive
description:
Expand All @@ -171,18 +171,18 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand All @@ -203,10 +203,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
version: "0.6.1"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -243,10 +243,10 @@ packages:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
version: "0.3.0"
sdks:
dart: ">=3.1.0 <4.0.0"
flutter: ">=3.7.0"
dart: ">=3.2.0 <4.0.0"
flutter: ">=3.16.0"
1 change: 1 addition & 0 deletions lib/bart/bart_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef BartPageBuilder = Widget Function(

typedef IconBuilder = Widget Function(
BuildContext context,
bool isActive,
);

class BartMenuRoute {
Expand Down
50 changes: 31 additions & 19 deletions lib/bart/widgets/bottom_bar/styles/bottom_bar_cupertino.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ class BartCupertinoBottomBar extends StatefulWidget {
}

class _BartCupertinoBottomBarState extends State<BartCupertinoBottomBar> {
List<BottomNavigationBarItem>? _items;

@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: widget.currentIndexNotifier,
builder: ((context, int index, child) {
_items = buildRouteWidgetList(context);
return CupertinoTabBar(
items: buildRouteWidgetList(context),
key: const ValueKey('bottom_bar'),
items: _items!,
currentIndex: index,
iconSize: widget.theme.iconSize,
border: widget.theme.border,
Expand All @@ -43,23 +47,31 @@ class _BartCupertinoBottomBarState extends State<BartCupertinoBottomBar> {
);
}

List<BottomNavigationBarItem> buildRouteWidgetList(BuildContext context) =>
widget.routes.map(
(route) {
if (route.icon != null) {
return BottomNavigationBarItem(
icon: Icon(route.icon),
label: route.label,
);
} else if (route.iconBuilder != null) {
return BottomNavigationBarItem(
icon: route.iconBuilder!(context),
label: route.label,
);
}
throw Exception(
"You must provide an icon or an iconBuilder for each route",
List<BottomNavigationBarItem> buildRouteWidgetList(BuildContext context) {
return widget.routes
.where((element) => element.type == BartMenuRouteType.bottomNavigation)
.map(
(route) {
final routeIndex = widget.routes.indexOf(route);

if (route.icon != null) {
return BottomNavigationBarItem(
icon: Icon(route.icon),
label: route.label,
);
} else if (route.iconBuilder != null) {
return BottomNavigationBarItem(
icon: route.iconBuilder!(
context,
routeIndex == widget.currentIndexNotifier.value,
),
label: route.label,
);
},
).toList();
}
throw Exception(
"You must provide an icon or an iconBuilder for each route",
);
},
).toList();
}
}
6 changes: 5 additions & 1 deletion lib/bart/widgets/bottom_bar/styles/bottom_bar_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class _BartMaterial3BottomBarState extends State<BartMaterial3BottomBar> {
(element) => element.type == BartMenuRouteType.bottomNavigation)
.map(
(route) {
final routeIndex = widget.routes.indexOf(route);
if (route.icon != null) {
return NavigationDestination(
icon: Icon(route.icon),
Expand All @@ -108,7 +109,10 @@ class _BartMaterial3BottomBarState extends State<BartMaterial3BottomBar> {
);
} else if (route.iconBuilder != null) {
return NavigationDestination(
icon: route.iconBuilder!(context),
icon: route.iconBuilder!(
context,
routeIndex == widget.currentIndexNotifier.value,
),
label: route.label ?? '',
// selectedIcon: route.selectedIconBuilder != null
// ? route.selectedIconBuilder!(context)
Expand Down
6 changes: 5 additions & 1 deletion lib/bart/widgets/side_bar/rail_sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ class _WebRailSideBarContainerState extends State<WebRailSideBarContainer> {
label: Text(route.label ?? ''),
);
} else if (route.iconBuilder != null) {
final routeIndex = widget.routes.indexOf(route);
return NavigationRailDestination(
icon: route.iconBuilder!(context),
icon: route.iconBuilder!(
context,
routeIndex == MenuRouter.of(context).indexNotifier.value,
),
label: Text(route.label ?? ''),
);
} else {
Expand Down
Loading

0 comments on commit 7942160

Please sign in to comment.