diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b88be5..6880bcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/example/lib/routes.dart b/example/lib/routes.dart index 051443f..60a105a 100644 --- a/example/lib/routes.dart +++ b/example/lib/routes.dart @@ -28,22 +28,27 @@ List 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("library"), diff --git a/example/pubspec.lock b/example/pubspec.lock index a619637..25a69bf 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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: @@ -23,7 +23,7 @@ packages: path: ".." relative: true source: path - version: "1.3.0" + version: "1.4.0" boolean_selector: dependency: transitive description: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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" diff --git a/lib/bart/bart_model.dart b/lib/bart/bart_model.dart index 8a8e782..e263a06 100644 --- a/lib/bart/bart_model.dart +++ b/lib/bart/bart_model.dart @@ -13,6 +13,7 @@ typedef BartPageBuilder = Widget Function( typedef IconBuilder = Widget Function( BuildContext context, + bool isActive, ); class BartMenuRoute { diff --git a/lib/bart/widgets/bottom_bar/styles/bottom_bar_cupertino.dart b/lib/bart/widgets/bottom_bar/styles/bottom_bar_cupertino.dart index d6f51e6..d53d117 100644 --- a/lib/bart/widgets/bottom_bar/styles/bottom_bar_cupertino.dart +++ b/lib/bart/widgets/bottom_bar/styles/bottom_bar_cupertino.dart @@ -22,13 +22,17 @@ class BartCupertinoBottomBar extends StatefulWidget { } class _BartCupertinoBottomBarState extends State { + List? _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, @@ -43,23 +47,31 @@ class _BartCupertinoBottomBarState extends State { ); } - List 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 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(); + } } diff --git a/lib/bart/widgets/bottom_bar/styles/bottom_bar_material.dart b/lib/bart/widgets/bottom_bar/styles/bottom_bar_material.dart index efb98f8..a8fc2c0 100644 --- a/lib/bart/widgets/bottom_bar/styles/bottom_bar_material.dart +++ b/lib/bart/widgets/bottom_bar/styles/bottom_bar_material.dart @@ -99,6 +99,7 @@ class _BartMaterial3BottomBarState extends State { (element) => element.type == BartMenuRouteType.bottomNavigation) .map( (route) { + final routeIndex = widget.routes.indexOf(route); if (route.icon != null) { return NavigationDestination( icon: Icon(route.icon), @@ -108,7 +109,10 @@ class _BartMaterial3BottomBarState extends State { ); } 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) diff --git a/lib/bart/widgets/side_bar/rail_sidebar.dart b/lib/bart/widgets/side_bar/rail_sidebar.dart index 358dbe8..a214872 100644 --- a/lib/bart/widgets/side_bar/rail_sidebar.dart +++ b/lib/bart/widgets/side_bar/rail_sidebar.dart @@ -72,8 +72,12 @@ class _WebRailSideBarContainerState extends State { 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 { diff --git a/pubspec.lock b/pubspec.lock index 8b8afd0..41db79f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -45,10 +45,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: @@ -74,10 +74,10 @@ packages: dependency: "direct dev" description: name: flutter_lints - sha256: ad76540d21c066228ee3f9d1dad64a9f7e46530e8bb7c85011a88bc1fd874bc5 + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "3.0.1" flutter_test: dependency: "direct dev" description: flutter @@ -119,10 +119,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: @@ -148,18 +148,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: @@ -180,10 +180,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: @@ -220,9 +220,9 @@ 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" + dart: ">=3.2.0-194.0.dev <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 081b5c7..6949544 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bart description: A bottom navigation bar using navigator 2 for switching tabs -version: 1.3.0+2 +version: 1.4.0 homepage: https://en.apparence.io repository: https://github.com/Apparence-io/bart