diff --git a/.flutter-plugins b/.flutter-plugins deleted file mode 100644 index 111c042..0000000 --- a/.flutter-plugins +++ /dev/null @@ -1,8 +0,0 @@ -# This is a generated file; do not edit or check into version control. -url_launcher=/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher-6.2.6/ -url_launcher_android=/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_android-6.3.1/ -url_launcher_ios=/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_ios-6.2.5/ -url_launcher_linux=/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_linux-3.1.1/ -url_launcher_macos=/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_macos-3.1.0/ -url_launcher_web=/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_web-2.3.1/ -url_launcher_windows=/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_windows-3.1.1/ diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies deleted file mode 100644 index f32b3dd..0000000 --- a/.flutter-plugins-dependencies +++ /dev/null @@ -1 +0,0 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"url_launcher_ios","path":"/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_ios-6.2.5/","native_build":true,"dependencies":[]}],"android":[{"name":"url_launcher_android","path":"/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_android-6.3.1/","native_build":true,"dependencies":[]}],"macos":[{"name":"url_launcher_macos","path":"/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_macos-3.1.0/","native_build":true,"dependencies":[]}],"linux":[{"name":"url_launcher_linux","path":"/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_linux-3.1.1/","native_build":true,"dependencies":[]}],"windows":[{"name":"url_launcher_windows","path":"/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_windows-3.1.1/","native_build":true,"dependencies":[]}],"web":[{"name":"url_launcher_web","path":"/Users/mahesh/.pub-cache/hosted/pub.dev/url_launcher_web-2.3.1/","dependencies":[]}]},"dependencyGraph":[{"name":"url_launcher","dependencies":["url_launcher_android","url_launcher_ios","url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_android","dependencies":[]},{"name":"url_launcher_ios","dependencies":[]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2024-04-24 09:13:08.481317","version":"3.19.3"} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 96486fd..1496cb0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,12 @@ .buildlog/ .history .svn/ +.metadata +.pubignore migrate_working_dir/ +.flutter-plugins-dependencies +.flutter-plugins +.metadata # IntelliJ related *.iml diff --git a/.metadata b/.metadata deleted file mode 100644 index d3da16e..0000000 --- a/.metadata +++ /dev/null @@ -1,10 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: cd41fdd495f6944ecd3506c21e94c6567b073278 - channel: stable - -project_type: package diff --git a/.pubignore b/.pubignore index 0878a92..cd415c2 100644 --- a/.pubignore +++ b/.pubignore @@ -1,8 +1,9 @@ # Miscellaneous -*.class -*.log -*.pyc -*.swp + +_.class +_.log +_.pyc +_.swp .DS_Store .atom/ .buildlog/ @@ -12,21 +13,27 @@ migrate_working_dir/ # IntelliJ related -*.iml -*.ipr -*.iws + +_.iml +_.ipr +\*.iws .idea/ docs/ # The .vscode folder contains launch configuration and tasks you configure in + # VS Code which you may wish to be included in version control, so this line + # is commented out by default. + #.vscode/ # Flutter/Dart/Pub related + # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. + /pubspec.lock -**/doc/api/ +\*\*/doc/api/ .dart_tool/ .packages build/ diff --git a/CHANGELOG.md b/CHANGELOG.md index aaf5938..1f0a700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ - Adds Support for Navbarbadges #[PR 43](https://github.com/maheshmnj/navbar_router/pull/43/) - Expose NavigationRail properties to NavbarRouter Part of [Issue #41](https://github.com/maheshmnj/navbar_router/issues/41) - Improve closing and opening of NavigationRail on Window resize/programmatically - +- Propagate NavbarItem updates to Navbar [Issue #38](https://github.com/maheshmnj/navbar_router/issues/38) ## [0.7.3] Dec 30, 2023 diff --git a/README.md b/README.md index 5be812f..c894f83 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## **navbar_router v0.7.3** +## **navbar_router v0.7.4** Pub @@ -267,7 +267,6 @@ NavbarItem(Icons.home_outlined, 'Home', - For detailed description of all the features and properties please visit the [documentation](https://docs.maheshjamdade.com/navbar_router) ### Curious how the navbar_router works? diff --git a/example/.metadata b/example/.metadata deleted file mode 100644 index 2e239db..0000000 --- a/example/.metadata +++ /dev/null @@ -1,45 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled. - -version: - revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - channel: stable - -project_type: app - -# Tracks metadata for the flutter migrate command -migration: - platforms: - - platform: root - create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - - platform: android - create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - - platform: ios - create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - - platform: linux - create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - - platform: macos - create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - - platform: web - create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - - platform: windows - create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 - - # User provided section - - # List of Local paths (relative to this file) that should be - # ignored by the migrate tool. - # - # Files that are not part of the templates will be ignored by default. - unmanaged_files: - - 'lib/main.dart' - - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/lib/main.dart b/example/lib/main.dart index 5f1298f..b13eb21 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'dart:developer'; import 'dart:math' hide log; @@ -103,44 +102,6 @@ class HomePage extends ConsumerStatefulWidget { } class _HomePageState extends ConsumerState { - List items = [ - NavbarItem(Icons.home_outlined, 'Home', - backgroundColor: colors[0], - selectedIcon: const Icon( - Icons.home, - size: 26, - ), - badge: const NavbarBadge( - badgeText: "11", - showBadge: true, - )), - NavbarItem(Icons.shopping_bag_outlined, 'Products', - backgroundColor: colors[1], - selectedIcon: const Icon( - Icons.shopping_bag, - size: 26, - ), - badge: const NavbarBadge( - badgeText: "8", - showBadge: true, - )), - NavbarItem(Icons.person_outline, 'Me', - backgroundColor: colors[2], - selectedIcon: const Icon( - Icons.person, - size: 26, - ), - // dot badge - badge: const NavbarBadge( - badgeText: "", showBadge: true, color: Colors.amber)), - NavbarItem(Icons.settings_outlined, 'Settings', - backgroundColor: colors[0], - selectedIcon: const Icon( - Icons.settings, - size: 26, - )), - ]; - final Map> _routes = const { 0: { '/': HomeFeeds(), @@ -164,14 +125,14 @@ class _HomePageState extends ConsumerState { DateTime newTime = DateTime.now(); /// This is only for demo purposes - void simulateTabChange({int times = 2, int delayInMs = 1000}) { - WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { - for (int i = 0; i < items.length * times; i++) { - NavbarNotifier.index = i % items.length; - await Future.delayed(Duration(milliseconds: delayInMs)); - } - }); - } + // void simulateTabChange({int times = 2, int delayInMs = 1000}) { + // WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { + // for (int i = 0; i < items.length * times; i++) { + // NavbarNotifier.index = i % items.length; + // await Future.delayed(Duration(milliseconds: delayInMs)); + // } + // }); + // } @override void initState() { @@ -193,6 +154,33 @@ class _HomePageState extends ConsumerState { final size = MediaQuery.of(context).size; final appRef = ref.watch(appProvider); + List items = [ + NavbarItem(Icons.home_outlined, 'Home', + backgroundColor: colors[0], + selectedIcon: const Icon( + Icons.home, + size: 26, + )), + NavbarItem(Icons.shopping_bag_outlined, 'Products', + backgroundColor: colors[1], + selectedIcon: const Icon( + Icons.shopping_bag, + size: 26, + )), + NavbarItem(Icons.person_outline, 'Me', + backgroundColor: colors[2], + selectedIcon: const Icon( + Icons.person, + size: 26, + )), + NavbarItem(Icons.settings_outlined, 'Settings', + backgroundColor: colors[0], + selectedIcon: Icon( + color: Theme.of(context).colorScheme.primary, + Icons.settings, + size: 26, + )), + ]; return Scaffold( resizeToAvoidBottomInset: false, floatingActionButton: AnimatedBuilder( @@ -665,6 +653,11 @@ class _UserProfileState extends State { } } + @override + void initState() { + super.initState(); + } + @override Widget build(BuildContext context) { return Scaffold( diff --git a/lib/src/navbar_decoration.dart b/lib/src/navbar_decoration.dart index f80c84e..2a18bb2 100644 --- a/lib/src/navbar_decoration.dart +++ b/lib/src/navbar_decoration.dart @@ -29,16 +29,23 @@ class NavbarItem { final NavbarBadge badge; @override - bool operator ==(Object other) => - identical(this, other) || - other is NavbarItem && - runtimeType == other.runtimeType && - iconData == other.iconData && - text == other.text && - child.runtimeType == other.child.runtimeType && - selectedIcon.runtimeType == other.selectedIcon.runtimeType && - backgroundColor == other.backgroundColor && - badge == other.badge; + bool operator ==(Object other) { + bool result = other is NavbarItem && + runtimeType == other.runtimeType && + iconData == other.iconData && + text == other.text && + child.runtimeType == other.child.runtimeType && + selectedIcon.runtimeType == other.selectedIcon.runtimeType && + backgroundColor == other.backgroundColor && + badge == other.badge; + if ((other as NavbarItem).selectedIcon.runtimeType == Icon && result) { + result = (selectedIcon as Icon).color == + (other.selectedIcon as Icon).color && + (selectedIcon as Icon).icon == (other.selectedIcon as Icon).icon && + (selectedIcon as Icon).size == (other.selectedIcon as Icon).size; + } + return identical(this, other) || result; + } @override int get hashCode => diff --git a/lib/src/navbar_router.dart b/lib/src/navbar_router.dart index 322c325..a841196 100644 --- a/lib/src/navbar_router.dart +++ b/lib/src/navbar_router.dart @@ -196,7 +196,7 @@ class _NavbarRouterState extends State initialize(); } - void initialize({bool isUpdate = false}) { + void initialize() { NavbarNotifier.length = widget.destinations.length; // init badge List badges = []; @@ -211,12 +211,19 @@ class _NavbarRouterState extends State // set badge list here NavbarNotifier.setBadges(badges); NavbarNotifier.hideBadgeOnPageChanged = widget.hideBadgeOnPageChanged; - - if (!isUpdate) { - initAnimation(); - NavbarNotifier.index = widget.initialIndex; - // re-enable the initial badge that was hidden on setting NavbarNotifier.index - NavbarNotifier.makeBadgeVisible(NavbarNotifier.currentIndex, true); + + // re-enable the initial badge that was hidden on setting NavbarNotifier.index + NavbarNotifier.makeBadgeVisible(NavbarNotifier.currentIndex, true); + initAnimation(); + NavbarNotifier.index = widget.initialIndex; + } + + void updateWidget() { + items.clear(); + NavbarNotifier.length = widget.destinations.length; + for (int i = 0; i < NavbarNotifier.length; i++) { + final navbaritem = widget.destinations[i].navbarItem; + items.add(navbaritem); } } @@ -249,6 +256,7 @@ class _NavbarRouterState extends State @override void didUpdateWidget(covariant NavbarRouter oldWidget) { + super.didUpdateWidget(oldWidget); if (widget.destinationAnimationCurve != oldWidget.destinationAnimationCurve || widget.destinationAnimationDuration != @@ -258,10 +266,8 @@ class _NavbarRouterState extends State if (widget.destinations.length != oldWidget.destinations.length || widget.type != oldWidget.type || !listEquals(oldWidget.destinations, widget.destinations)) { - clearInitialization(); - initialize(isUpdate: true); + updateWidget(); } - super.didUpdateWidget(oldWidget); } double getPadding() { diff --git a/pubspec.yaml b/pubspec.yaml index cc6fa39..a6a8212 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: navbar_router description: A flutter package to build advanced bottomnavbar with minimal code and hassle -version: 0.7.3 +version: 0.7.4 homepage: https://github.com/maheshmnj/navbar_router repository: https://github.com/maheshmnj/navbar_router issue_tracker: https://github.com/maheshmnj/navbar_router/issues diff --git a/test/navbar_router_test.dart b/test/navbar_router_test.dart index 8dce1bf..bf0ccf4 100644 --- a/test/navbar_router_test.dart +++ b/test/navbar_router_test.dart @@ -1724,4 +1724,53 @@ void main() { await tester.pumpAndSettle(); expect(NavbarNotifier.currentIndex, equals(2)); }); + + testWidgets('NavbarItem properties can be changed during runtime', + (tester) async { + Color backgroundColor = Colors.red; + List navItems = [ + NavbarItem(Icons.home_outlined, 'Home', + backgroundColor: backgroundColor, + selectedIcon: const Icon( + key: Key("HomeIconSelected"), + Icons.home_outlined, + size: 26, + )), + const NavbarItem(Icons.shopping_bag_outlined, 'Products', + backgroundColor: Colors.orange, + selectedIcon: Icon( + Icons.shopping_bag_outlined, + key: Key("ProductsIconSelected"), + size: 26, + )), + const NavbarItem(Icons.person_outline, 'Me', + backgroundColor: Colors.teal, + selectedIcon: Icon( + key: Key("MeIconSelected"), + Icons.person, + size: 26, + )), + const NavbarItem(Icons.settings_outlined, 'Settings', + backgroundColor: Colors.red, + selectedIcon: Icon( + Icons.settings, + size: 26, + )), + ]; + await tester.pumpWidget(boilerplate(navBarItems: navItems)); + await tester.pumpAndSettle(); + expect(NavbarNotifier.currentIndex, equals(0)); + expect((navItems[2].selectedIcon as Icon).color, isNull); + navItems[2] = const NavbarItem(Icons.person_outline, 'Me', + backgroundColor: Colors.teal, + selectedIcon: Icon( + key: Key("MeIconSelected"), + Icons.person, + color: Colors.green, + size: 26, + )); + + await tester.pumpAndSettle(); + expect((navItems[2].selectedIcon as Icon).color, Colors.green); + }); }