refactor: enhance child route management in ClientPaths and StaffPaths; ensure proper handling of empty child paths

This commit is contained in:
Achintha Isuru
2026-02-04 17:58:37 -05:00
parent fa6fa90bb8
commit b5c3af580c
6 changed files with 53 additions and 20 deletions

View File

@@ -1,19 +1,20 @@
import 'package:client_authentication/client_authentication.dart'
as client_authentication;
import 'package:client_create_order/client_create_order.dart'
as client_create_order;
import 'package:client_hubs/client_hubs.dart' as client_hubs;
import 'package:client_main/client_main.dart' as client_main;
import 'package:client_settings/client_settings.dart' as client_settings;
import 'package:core_localization/core_localization.dart' as core_localization; import 'package:core_localization/core_localization.dart' as core_localization;
import 'package:design_system/design_system.dart'; import 'package:design_system/design_system.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_modular/flutter_modular.dart'; import 'package:flutter_modular/flutter_modular.dart';
import 'package:client_authentication/client_authentication.dart'
as client_authentication;
import 'package:client_main/client_main.dart' as client_main;
import 'package:client_settings/client_settings.dart' as client_settings;
import 'package:client_hubs/client_hubs.dart' as client_hubs;
import 'package:client_create_order/client_create_order.dart'
as client_create_order;
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:krow_core/core.dart'; import 'package:krow_core/core.dart';
import 'firebase_options.dart'; import 'firebase_options.dart';
void main() async { void main() async {
@@ -32,23 +33,23 @@ class AppModule extends Module {
@override @override
void routes(RouteManager r) { void routes(RouteManager r) {
// Initial route points to the client authentication flow // Initial route points to the client authentication flow
r.module('/', module: client_authentication.ClientAuthenticationModule()); r.module(ClientPaths.root, module: client_authentication.ClientAuthenticationModule());
// Client main shell with bottom navigation (includes home as a child) // Client main shell with bottom navigation (includes home as a child)
r.module('/client-main', module: client_main.ClientMainModule()); r.module(ClientPaths.main, module: client_main.ClientMainModule());
// Client settings route // Client settings route
r.module( r.module(
'/client-settings', ClientPaths.settings,
module: client_settings.ClientSettingsModule(), module: client_settings.ClientSettingsModule(),
); );
// Client hubs route // Client hubs route
r.module('/client-hubs', module: client_hubs.ClientHubsModule()); r.module(ClientPaths.hubs, module: client_hubs.ClientHubsModule());
// Client create order route // Client create order route
r.module( r.module(
'/create-order', ClientPaths.createOrder,
module: client_create_order.ClientCreateOrderModule(), module: client_create_order.ClientCreateOrderModule(),
); );
} }

View File

@@ -48,7 +48,7 @@ extension ClientNavigator on IModularNavigator {
/// This is typically called after successful authentication or when /// This is typically called after successful authentication or when
/// returning to the main application from a deep feature. /// returning to the main application from a deep feature.
/// ///
/// Uses absolute navigation to ensure proper routing from any context. /// Uses pushNamed to avoid trailing slash issues with navigate().
void toClientHome() { void toClientHome() {
navigate(ClientPaths.home); navigate(ClientPaths.home);
} }

View File

@@ -16,7 +16,21 @@ class ClientPaths {
/// Generate child route based on the given route and parent route /// Generate child route based on the given route and parent route
/// ///
/// This is useful for creating nested routes within modules. /// This is useful for creating nested routes within modules.
static String childRoute(String parent, String child) => child.replaceFirst(parent, ''); static String childRoute(String parent, String child) {
final String childPath = child.replaceFirst(parent, '');
// check if the child path is empty
if (childPath.isEmpty) {
return '/';
}
// ensure the child path starts with a '/'
if (!childPath.startsWith('/')) {
return '/$childPath';
}
return childPath;
}
// ========================================================================== // ==========================================================================
// AUTHENTICATION // AUTHENTICATION

View File

@@ -16,7 +16,21 @@ class StaffPaths {
/// Generate child route based on the given route and parent route /// Generate child route based on the given route and parent route
/// ///
/// This is useful for creating nested routes within modules. /// This is useful for creating nested routes within modules.
static String childRoute(String parent, String child) => child.replaceFirst(parent, ''); static String childRoute(String parent, String child) {
final String childPath = child.replaceFirst(parent, '');
// check if the child path is empty
if (childPath.isEmpty) {
return '/';
}
// ensure the child path starts with a '/'
if (!childPath.startsWith('/')) {
return '/$childPath';
}
return childPath;
}
// ========================================================================== // ==========================================================================
// AUTHENTICATION // AUTHENTICATION
@@ -93,7 +107,8 @@ class StaffPaths {
/// Personal information onboarding. /// Personal information onboarding.
/// ///
/// Collect basic personal information during staff onboarding. /// Collect basic personal information during staff onboarding.
static const String onboardingPersonalInfo = '/worker-main/onboarding/personal-info'; static const String onboardingPersonalInfo =
'/worker-main/onboarding/personal-info';
/// Emergency contact information. /// Emergency contact information.
/// ///

View File

@@ -37,7 +37,7 @@ class ClientSignInPage extends StatelessWidget {
final TranslationsClientAuthenticationSignInPageEn i18n = t.client_authentication.sign_in_page; final TranslationsClientAuthenticationSignInPageEn i18n = t.client_authentication.sign_in_page;
final ClientAuthBloc authBloc = Modular.get<ClientAuthBloc>(); final ClientAuthBloc authBloc = Modular.get<ClientAuthBloc>();
return BlocProvider.value( return BlocProvider<ClientAuthBloc>.value(
value: authBloc, value: authBloc,
child: BlocConsumer<ClientAuthBloc, ClientAuthState>( child: BlocConsumer<ClientAuthBloc, ClientAuthState>(
listener: (BuildContext context, ClientAuthState state) { listener: (BuildContext context, ClientAuthState state) {

View File

@@ -47,6 +47,9 @@ class ClientHomeModule extends Module {
@override @override
void routes(RouteManager r) { void routes(RouteManager r) {
r.child(ClientPaths.childRoute(ClientPaths.home, ClientPaths.home), child: (_) => const ClientHomePage()); r.child(
ClientPaths.childRoute(ClientPaths.home, ClientPaths.home),
child: (_) => const ClientHomePage(),
);
} }
} }