Comments (7)
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.
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.
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.
@Milad-Akarie let me know if there is any precise documentation about it please. Maybe I missed some steps.
from auto_route_library.
@krosiek What exactly are you having trouble with?
from auto_route_library.
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.
@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)
- revaluateListenable does not cause reevaluation for nested routes in AutoTabRouter tabs HOT 1
- Custom Route Navigation Overlapping Bottom Bar HOT 2
- Default global route transition HOT 2
- Custom Route Builder Example?
- When resizing the window, the interface is not re-rendered. HOT 2
- Route classes not generated HOT 1
- AutoRoute Helper not available with Android Studio Giraffe | 2022.3.1 Patch 2 HOT 6
- system "back" button close app in nested navigation HOT 4
- [Question] Shouldn't usesPathAsKey work in this case ? HOT 8
- AutoTabsRouter caches the pages. HOT 3
- Widget Inspector Error with Wildcard RedirectRoute HOT 2
- resolver.next(true) in Guard, on browser refresh pushes to initial route
- Route Arguments are always null inside AutoRouterObserver when using navigateNamed HOT 1
- AppBar back button disappears when pressing F5 on a web page
- Can't register AutoRoute v6 with GetIt HOT 2
- TabsRouter: updating `homeIndex` has no effect
- Testcases for Bottom Navigation Bar that uses AutoRouterScaffold HOT 2
- Conditional Transition Animation Based on Previous Route HOT 1
- Deeplink in CamelCase doesn't match
- Navigation doesn't work properly, if `AutoRouteGuard.onNavigation` method is overridden as async method HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from auto_route_library.