GithubHelp home page GithubHelp logo

Comments (7)

krosiek avatar krosiek commented on June 19, 2024 1

The problem was that dsahboard package did not have auto_route_generator inside pubspec.yaml.
I have navigation package that exports auto_route:

export 'package:auto_route/auto_route.dart';

And I didn't want to include auto_route and auto_route_generator in any of other packages than navigation
Do you think it is possible to avoid adding auto_route_generator to each package that has screens and still generate .gm.dart files?

from auto_route_library.

Milad-Akarie avatar Milad-Akarie commented on June 19, 2024

Hey @krosiek routers annotated with @AutoRouterConfig.module() should generate a file with extension .gm.dart,
I just merged a pull request that fixes a related issue, #1626

also make sure you run the generator on each package, micro or root.

from auto_route_library.

krosiek avatar krosiek commented on June 19, 2024

I am using

auto_route: ^7.7.0
auto_route_generator: ^7.2.0
build_runner: ^2.4.5

I have changed extension to .gm.dart

import 'dashboard_routes.gm.dart';

I run

dart run build_runner build --delete-conflicting-outputs  

in the dashboard package. The command completes without any error, but no files are generated.
What else can I test? Am I missing some configuration files?

from auto_route_library.

krosiek avatar krosiek commented on June 19, 2024

@Milad-Akarie let me know if there is any precise documentation about it please. Maybe I missed some steps.

from auto_route_library.

Milad-Akarie avatar Milad-Akarie commented on June 19, 2024

@krosiek What exactly are you having trouble with?

from auto_route_library.

muhammadjonyorqinov avatar muhammadjonyorqinov commented on June 19, 2024

1 I added the module routing to each package and generated gm.dart file I did not have any problem
2. I added that module to main rootStackRouter and generated main app router.gr.dart
3. But at the end when I navigate or set as initial routing is not being able to find it

Splash routing

import 'package:splash/splash_module.gm.dart';

@AutoRouterConfig.module(
  replaceInRouteName: 'Page,Route',
)
class SplashModule extends $SplashModule {
  final List<AutoRoute> routes = [
    AutoRoute(
      page: SplashScreen.page,
      path: '/',
      initial: true,
    ),
  ];
}

Splash routing gm.dart file

// GENERATED CODE - DO NOT MODIFY BY HAND

// **************************************************************************
// AutoRouterGenerator
// **************************************************************************

// ignore_for_file: type=lint
// coverage:ignore-file

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:auto_route/auto_route.dart' as _i2;
import 'package:splash/src/presentation/screens/splash_screen.dart' as _i1;

abstract class $SplashModule extends _i2.AutoRouterModule {
  @override
  final Map<String, _i2.PageFactory> pagesMap = {
    SplashScreen.name: (routeData) {
      return _i2.AutoRoutePage<dynamic>(
        routeData: routeData,
        child: const _i1.SplashScreen(),
      );
    }
  };
}

/// generated route for
/// [_i1.SplashScreen]
class SplashScreen extends _i2.PageRouteInfo<void> {
  const SplashScreen({List<_i2.PageRouteInfo>? children})
      : super(
          SplashScreen.name,
          initialChildren: children,
        );

  static const String name = 'SplashScreen';

  static const _i2.PageInfo<void> page = _i2.PageInfo<void>(name);
}

Main routing

import 'package:app_packages/modules.dart' hide SplashScreen;
import 'package:auto_route/auto_route.dart';
import 'app_router.gr.dart';
import 'core/constants/navigation/navigation_constant.dart';

/// Whenever you add new route run   flutter pub run build_runner build in terminal
@AutoRouterConfig(replaceInRouteName: 'Page,Route', modules: [SplashModule])
// extend the generated private router
class AppRouter extends $AppRouter {
  @override
  RouteType get defaultRouteType => const RouteType.material();
  @override
  final List<AutoRoute> routes = [
    AutoRoute(
      page: BottomNavBarScreen.page,
      path: NavigationConst.HOME_PAGE_VIEW,
    ),
  ];
} 

Main routing gr.dart file

// GENERATED CODE - DO NOT MODIFY BY HAND

// **************************************************************************
// AutoRouterGenerator
// **************************************************************************

// ignore_for_file: type=lint
// coverage:ignore-file

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:app_packages/modules.dart' as _i3;
import 'package:auto_route/auto_route.dart' as _i2;
import 'package:flutter/material.dart' as _i4;
import 'package:mobile/views/home/bottom_nav_bar/_bottom_nav_bar.dart' as _i1;

abstract class $AppRouter extends _i2.RootStackRouter {
  $AppRouter({super.navigatorKey});

  @override
  final Map<String, _i2.PageFactory> pagesMap = {
    BottomNavBarScreen.name: (routeData) {
      final args = routeData.argsAs<BottomNavBarScreenArgs>(
          orElse: () => const BottomNavBarScreenArgs());
      return _i2.AutoRoutePage<dynamic>(
        routeData: routeData,
        child: _i1.BottomNavBarScreen(key: args.key),
      );
    },
    ..._i3.SplashModule().pagesMap,
  };
}

/// generated route for
/// [_i1.BottomNavBarScreen]
class BottomNavBarScreen extends _i2.PageRouteInfo<BottomNavBarScreenArgs> {
  BottomNavBarScreen({
    _i4.Key? key,
    List<_i2.PageRouteInfo>? children,
  }) : super(
          BottomNavBarScreen.name,
          args: BottomNavBarScreenArgs(key: key),
          initialChildren: children,
        );

  static const String name = 'BottomNavBarScreen';

  static const _i2.PageInfo<BottomNavBarScreenArgs> page =
      _i2.PageInfo<BottomNavBarScreenArgs>(name);
}

class BottomNavBarScreenArgs {
  const BottomNavBarScreenArgs({this.key});

  final _i4.Key? key;

  @override
  String toString() {
    return 'BottomNavBarScreenArgs{key: $key}';
  }
}

Error

Can not resolve initial route

What should I do in order this work without any problem @Milad-Akarie

from auto_route_library.

Milad-Akarie avatar Milad-Akarie commented on June 19, 2024

@muhammadjonyorqinov I think the issue here is that you defined the sub routes-mapping inside of the model, you should either define them inside of the root router or manually adding the mapping there

the recommended approach is that you don't define in routes-mapping inside of your module

class SplashModule extends $SplashModule {
// routes shouldn't be defined here
  final List<AutoRoute> routes = [
    AutoRoute(
      page: SplashScreen.page,
      path: '/',
      initial: true,
    ),
  ];
}
@AutoRouterConfig(replaceInRouteName: 'Page,Route', modules: [SplashModule])
// extend the generated private router
class AppRouter extends $AppRouter {
  @override
  RouteType get defaultRouteType => const RouteType.material();
  @override
  final List<AutoRoute> routes = [
      /// add here
    AutoRoute(
      page: SplashScreen.page,
      path: '/',
      initial: true,
    ),
    AutoRoute(
      page: BottomNavBarScreen.page,
      path: NavigationConst.HOME_PAGE_VIEW,
    ),
  ];
} 

from auto_route_library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.