Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to navigate accross child modules #939

Open
agustin-garcia opened this issue Feb 22, 2024 · 1 comment
Open

Unable to navigate accross child modules #939

agustin-garcia opened this issue Feb 22, 2024 · 1 comment
Labels
new New issue request attention

Comments

@agustin-garcia
Copy link

Hello,
I have the following code structure and modules, but I can't figure it out on how to navigate from Login Module (once it's been authenticated) to the AppHomeModule.

class AppModule extends Module { @override List<ModularRoute> get routes => [ ModuleRoute('/', module: AppInitialModule(), guards: [AuthGuard()]), ModuleRoute('/home_modular', module: AppHomeModule()), ModuleRoute('/login_modular', module: LoginModule()), ]; } class LoginModule extends Module { @override List<ModularRoute> get routes => [ ChildRoute('/', child: (_, __) => LoginWidget()), ]; } class AppHomeModule extends Module { @override List<ModularRoute> get routes => [ ChildRoute('/', child: (_, __) => HomeWidget(),), ChildRoute('/home_widget', child: (_, __) => HomeWidget(),), ]; }

On the LoginService, once User has been authenticated I try to navigate to HomeModule by using the following scenarios (once at the time), but none of them work:

Modular.to.navigate('/home_modular/'): It apparently initiates de the HomeMoule (as intended) based on the message: "AppHomeModule INITIALIZED", but it doesn't navigate anywhere (I mean, the App stays on the Login page)

Modular.to.navigate('/home_modular/home_widget/'): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RouteNotFoundException: Route (/home_modular/home_widget/) not found

Modular.to.navigate('/home_modular/home_widget'): It apparently initiates de the HomeMoule (as intended) based on the message: "AppHomeModule INITIALIZED", but it doesn't navigate anywhere (I mean, the App stays on the Login page)

Modular.to.pushNamed('/home_modular/'): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value E/flutter (21544): #0 ModularRouterDelegate.pushNamed (package:flutter_modular/src/presenter/navigation/modular_router_delegate.dart:147:44)

Modular.to.pushNamed('/home_modular/'): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value E/flutter (21850): #0 ModularRouterDelegate.pushNamed (package:flutter_modular/src/presenter/navigation/modular_router_delegate.dart:147:44)

Modular.to.pushNamed('/home_modular/home_widget/'): RouteNotFoundException: Route (/home_modular/home_widget/) not found

Modular.to.pushNamed('/home_modular/home_widget'): ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value E/flutter (21850): #0 ModularRouterDelegate.pushNamed (package:flutter_modular/src/presenter/navigation/modular_router_delegate.dart:147:44)

I'm testing this on:
flutter_modular: ^5.0.3
Android Emulator: 12.0 (S) - API 31
Emulator Version: 33.1.24-11237101
Flutter (Channel stable, 3.16.9, on Microsoft Windows [Version 10.0.22631.3155], locale en-US)
Windows Version (Installed version of Windows is version 10 or higher)
Android toolchain - develop for Android devices (Android SDK version 34.0.0)
Android Studio (version 2023.1)

@agustin-garcia agustin-garcia added the new New issue request attention label Feb 22, 2024
@eduardoflorence
Copy link

@agustin-garcia,

This correct is Modular.to.navigate('/home_modular/')

You did it (routeInformationParser, routerDelegate) ?

import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';

void main() {
  return runApp(ModularApp(module: AppModule(), child: AppWidget()));
}

class AppWidget extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'My Smart App',
      theme: ThemeData(primarySwatch: Colors.blue),
      routeInformationParser: Modular.routeInformationParser,
      routerDelegate: Modular.routerDelegate,
    ); 
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new New issue request attention
Projects
None yet
Development

No branches or pull requests

2 participants