Repository navigation
Conversation
…1 router The default router generator silently ignored CustomRoute.customRouteBuilder because Navigator 1's onGenerateRoute has no BuildContext to invoke the builder with. Emit a build-time warning pointing users to navigator2: true instead of dropping the option silently. Refs Stacked-Org/stacked#1164 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
LCOV of commit
|
| Metric | Coverage | Details |
|---|---|---|
| 📈 Lines | 🔴 64.7% | 1616 / 2496 lines |
| 🔧 Functions | ⚪ N/A | no data found |
| 🌿 Branches | ⚪ N/A | no data found |
📁 Files Changed Coverage
| File | Lines | Functions | Branches |
|---|---|---|---|
| No coverage data for changed files |
🟢 ≥ 90% · 🟡 ≥ 70% · 🔴 below 70% · ⚪ no data
Full coverage report
f4473c9 to
bf3ff6e
Compare
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
bf3ff6e to
d7afbef
Compare
| // ignore: avoid_print | ||
| print( | ||
| '\nWARNING => CustomRoute.customRouteBuilder on \'${route.routeName}\' is only supported by the Navigator 2 router.\n' | ||
| 'Set `navigator2: true` in your @StackedApp / stacked config to use it; it is ignored by the default router.\n'); |
There was a problem hiding this comment.
The warning's remediation is wrong. navigator2 is not a @StackedApp parameter (StackedApp in stacked_shared has no such field). It is a builder option: GeneratorConfig.fromJson(options.config) reads it in lib/builder.dart, so it lives in build.yaml under targets: $default: builders: stacked_generator|stackedRouterGenerator: options: navigator2: true. A user who follows this message and writes @StackedApp(navigator2: true, ...) gets a compile error ("no named parameter 'navigator2'"). "stacked config" (stacked.json) doesn't control it either. Please point to the build.yaml builder option instead.
| 'Set `navigator2: true` in your @StackedApp / stacked config to use it; it is ignored by the default router.\n'); | |
| 'Set `navigator2: true` in the stacked_generator|stackedRouterGenerator builder options in build.yaml to use it; it is ignored by the default router.\n'); |
navigator2 is a stacked_generator builder option, not a @stackedapp parameter. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
| final generatedWithout = routerClassBuilderHelper | ||
| .mapOfPages([withoutBuilder]).buildLibraryForClass; | ||
| final generatedWith = routerClassBuilderHelper | ||
| .mapOfPages([withBuilder]).buildLibraryForClass; |
There was a problem hiding this comment.
Nit (low): this call builds the route with customRouteBuilder set outside any print-capturing zone, so the new production print fires for real here and the four-line WARNING => ... block is emitted into the test runner's stdout on every dart test run (confirmed locally — it shows up between the +5 and +6 lines). The two tests below already wrap mapOfPages in runZoned with a print override; wrapping this one the same way (or just reusing the captured-output helper) keeps the suite output clean.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Summary
Refs Stacked-Org/stacked#1164:
CustomRoute.customRouteBuilderis silently ignored by the default (Navigator 1) router generator, which always emits aPageRouteBuilder. Only the Navigator 2 generator honours it.Why not just support it in Navigator 1
The builder contract is
Route<T> Function<T>(BuildContext context, Widget child, CustomRoute page). Navigator 1'sonGenerateRoute(RouteSettings)has noBuildContext, so the generated router has nothing to call the builder with. Supporting it there would require a second, incompatible builder signature, which would be confusing and a breaking change for anyone with a builder written for Navigator 2. That was tried first and abandoned.Change
router_class_builder_helper.dart: generated output is unchanged. WhencustomRouteBuilderis set on a route in the Navigator 1 path, the generator now prints a build-time warning, using the sameprint('WARNING => ...')convention already used inroute_config_resolver.dart:No throw, so builds that succeeded before still succeed.
Tests
router_class_builder_helper_test.dart: output with and withoutcustomRouteBuilderis byte-identical; the warning is printed when the builder is set (captured viarunZonedprint interception); no warning when unset.Verification
dart test: 330 passed, 1 pre-existing skipdart analyze lib test: no new issuesNote for reviewers:
dev_dependencies: freezed: ^4.0.0onmainrequires Dart 3.12, which the current Flutter stable does not ship. I ran the suite with a temporary local downgrade and revertedpubspec.yamlbefore committing.🤖 Generated with Claude Code