From 50e9bdb32eab0603f1d4fbaf29e376aa88d8030b Mon Sep 17 00:00:00 2001 From: Hardik Date: Sun, 14 Jul 2024 22:19:54 +0530 Subject: [PATCH 1/4] fix: bottom navigation current index --- lib/app/routes/screen_extension.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/app/routes/screen_extension.dart b/lib/app/routes/screen_extension.dart index aaf138b0..8b4cad98 100644 --- a/lib/app/routes/screen_extension.dart +++ b/lib/app/routes/screen_extension.dart @@ -110,13 +110,13 @@ extension ScreenExtension on Screen { extension RoleExtension on Role { int getCurrentIndexFromRoute(GetNavConfig? currentRoute) { - final String? currentLocation = currentRoute?.location; + final String? currentLocation = currentRoute?.uri.toString(); int currentIndex = 0; if (currentLocation != null) { currentIndex = - tabs.indexWhere((tab) => currentLocation.startsWith(tab.path)); + tabs.indexWhere((tab) => currentLocation.endsWith(tab.path)); } - return (currentIndex > 0) ? currentIndex : 0; + return (currentIndex >= 0) ? currentIndex : 0; } void routeTo(int value, GetDelegate delegate) { From c1fedc493808390135d2a9826cc9f532e30afa35 Mon Sep 17 00:00:00 2001 From: Hardik Date: Mon, 15 Jul 2024 02:32:33 +0530 Subject: [PATCH 2/4] fix: handled bottom nav index for path & query parameters --- lib/app/routes/screen_extension.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/app/routes/screen_extension.dart b/lib/app/routes/screen_extension.dart index 8b4cad98..e334c4e9 100644 --- a/lib/app/routes/screen_extension.dart +++ b/lib/app/routes/screen_extension.dart @@ -113,10 +113,14 @@ extension RoleExtension on Role { final String? currentLocation = currentRoute?.uri.toString(); int currentIndex = 0; if (currentLocation != null) { - currentIndex = - tabs.indexWhere((tab) => currentLocation.endsWith(tab.path)); + // removinng '/home' from the start of the location + final filteredLocation = + currentLocation.replaceFirst(RegExp(r'^/home'), ''); + currentIndex = tabs.indexWhere((tab) { + return filteredLocation.startsWith(tab.path); + }); } - return (currentIndex >= 0) ? currentIndex : 0; + return (currentIndex > 0) ? currentIndex : 0; } void routeTo(int value, GetDelegate delegate) { From 0d780efd1735326ca43c07e2d4b138bc4e4ffaec Mon Sep 17 00:00:00 2001 From: Hardik Date: Mon, 15 Jul 2024 21:54:19 +0530 Subject: [PATCH 3/4] added check if the path mentioned is for bottom navigation --- lib/app/routes/screen_extension.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/app/routes/screen_extension.dart b/lib/app/routes/screen_extension.dart index e334c4e9..ca90f303 100644 --- a/lib/app/routes/screen_extension.dart +++ b/lib/app/routes/screen_extension.dart @@ -112,10 +112,9 @@ extension RoleExtension on Role { int getCurrentIndexFromRoute(GetNavConfig? currentRoute) { final String? currentLocation = currentRoute?.uri.toString(); int currentIndex = 0; - if (currentLocation != null) { + if (currentLocation != null && currentLocation.startsWith('/home')) { // removinng '/home' from the start of the location - final filteredLocation = - currentLocation.replaceFirst(RegExp(r'^/home'), ''); + final filteredLocation = currentLocation.replaceFirst('/home', ''); currentIndex = tabs.indexWhere((tab) { return filteredLocation.startsWith(tab.path); }); From 1180864430117bf79d40a77fd92c441308c37639 Mon Sep 17 00:00:00 2001 From: Hardik Date: Wed, 17 Jul 2024 11:50:36 +0530 Subject: [PATCH 4/4] using full path for bottom navigation --- lib/app/routes/screen_extension.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/app/routes/screen_extension.dart b/lib/app/routes/screen_extension.dart index ca90f303..23877c7d 100644 --- a/lib/app/routes/screen_extension.dart +++ b/lib/app/routes/screen_extension.dart @@ -110,13 +110,13 @@ extension ScreenExtension on Screen { extension RoleExtension on Role { int getCurrentIndexFromRoute(GetNavConfig? currentRoute) { - final String? currentLocation = currentRoute?.uri.toString(); + final String? currentLocation = currentRoute?.uri.path; int currentIndex = 0; - if (currentLocation != null && currentLocation.startsWith('/home')) { - // removinng '/home' from the start of the location - final filteredLocation = currentLocation.replaceFirst('/home', ''); + if (currentLocation != null) { currentIndex = tabs.indexWhere((tab) { - return filteredLocation.startsWith(tab.path); + String parentPath = tab.parent?.path ?? ''; + String fullPath = '$parentPath${tab.path}'; + return currentLocation.startsWith(fullPath); }); } return (currentIndex > 0) ? currentIndex : 0;