Skip to content

Commit

Permalink
Merge pull request #45 from maheshmnj/issue-38
Browse files Browse the repository at this point in the history
Propagate NavbarItem updates to NavigationBar
  • Loading branch information
maheshj01 authored Apr 30, 2024
2 parents 2acb365 + 47cd754 commit 27e6fa0
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 143 deletions.
8 changes: 0 additions & 8 deletions .flutter-plugins

This file was deleted.

1 change: 0 additions & 1 deletion .flutter-plugins-dependencies

This file was deleted.

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
.buildlog/
.history
.svn/
.metadata
.pubignore
migrate_working_dir/
.flutter-plugins-dependencies
.flutter-plugins
.metadata

# IntelliJ related
*.iml
Expand Down
10 changes: 0 additions & 10 deletions .metadata

This file was deleted.

23 changes: 15 additions & 8 deletions .pubignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp

_.class
_.log
_.pyc
_.swp
.DS_Store
.atom/
.buildlog/
Expand All @@ -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/
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) -->
- Propagate NavbarItem updates to Navbar [Issue #38](https://github.com/maheshmnj/navbar_router/issues/38)

## [0.7.3] Dec 30, 2023

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## **navbar_router v0.7.3**
## **navbar_router v0.7.4**

<a href="https://pub.dev/packages/navbar_router"><img src="https://img.shields.io/pub/v/navbar_router.svg" alt="Pub"></a>

Expand Down Expand Up @@ -267,7 +267,6 @@ NavbarItem(Icons.home_outlined, 'Home',

<img src="https://github.com/maheshmnj/navbar_router/assets/31410839/2362187a-0a19-41a0-938c-214c103e64dd">


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?
Expand Down
45 changes: 0 additions & 45 deletions example/.metadata

This file was deleted.

87 changes: 40 additions & 47 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:developer';
import 'dart:math' hide log;

Expand Down Expand Up @@ -103,44 +102,6 @@ class HomePage extends ConsumerStatefulWidget {
}

class _HomePageState extends ConsumerState<HomePage> {
List<NavbarItem> 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<int, Map<String, Widget>> _routes = const {
0: {
'/': HomeFeeds(),
Expand All @@ -164,14 +125,14 @@ class _HomePageState extends ConsumerState<HomePage> {
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() {
Expand All @@ -193,6 +154,33 @@ class _HomePageState extends ConsumerState<HomePage> {
final size = MediaQuery.of(context).size;
final appRef = ref.watch(appProvider);

List<NavbarItem> 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(
Expand Down Expand Up @@ -665,6 +653,11 @@ class _UserProfileState extends State<UserProfile> {
}
}

@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down
27 changes: 17 additions & 10 deletions lib/src/navbar_decoration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
26 changes: 16 additions & 10 deletions lib/src/navbar_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class _NavbarRouterState extends State<NavbarRouter>
initialize();
}

void initialize({bool isUpdate = false}) {
void initialize() {
NavbarNotifier.length = widget.destinations.length;
// init badge
List<NavbarBadge> badges = [];
Expand All @@ -211,12 +211,19 @@ class _NavbarRouterState extends State<NavbarRouter>
// 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);
}
}

Expand Down Expand Up @@ -249,6 +256,7 @@ class _NavbarRouterState extends State<NavbarRouter>

@override
void didUpdateWidget(covariant NavbarRouter oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.destinationAnimationCurve !=
oldWidget.destinationAnimationCurve ||
widget.destinationAnimationDuration !=
Expand All @@ -258,10 +266,8 @@ class _NavbarRouterState extends State<NavbarRouter>
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() {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

1 comment on commit 27e6fa0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.