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
[go_router_builder] generated location is not correct in some cases #102710
Comments
Hi @leoshusar, thanks for filing the issue. I am able to reproduce the issue on windows the generated getter has a backslash instead of a forward slash on windows, as a result, the path is incorrect also the dollar gets escaped. String get location => GoRouteData.$location(
'/families\${Uri.encodeComponent(familyId)}',
); it should be String get location => GoRouteData.$location(
'/families/${Uri.encodeComponent(familyId)}',
); Reproducible on both stable and the master channel. main.g.dart// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'main.dart';
// **************************************************************************
// GoRouterGenerator
// **************************************************************************
List<GoRoute> get $appRoutes => [
$homeRoute,
];
GoRoute get $homeRoute => GoRouteData.$route(
path: '/families',
factory: $HomeRouteExtension._fromState,
routes: [
GoRouteData.$route(
path: ':familyId',
factory: $FamilyRouteExtension._fromState,
),
],
);
extension $HomeRouteExtension on HomeRoute {
static HomeRoute _fromState(GoRouterState state) => const HomeRoute();
String get location => GoRouteData.$location(
'/families',
);
void go(BuildContext buildContext) => buildContext.go(location, extra: this);
}
extension $FamilyRouteExtension on FamilyRoute {
static FamilyRoute _fromState(GoRouterState state) => FamilyRoute(
state.params['familyId']!,
);
String get location => GoRouteData.$location(
'/families\${Uri.encodeComponent(familyId)}',
);
void go(BuildContext buildContext) => buildContext.go(location, extra: this);
}
code sample
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: public_member_api_docs
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'data.dart';
part 'main.g.dart';
void main() => runApp(App());
class App extends StatelessWidget {
App({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => MaterialApp.router(
routeInformationParser: _router.routeInformationParser,
routerDelegate: _router.routerDelegate,
title: _appTitle,
);
final GoRouter _router = GoRouter(routes: $appRoutes);
}
@TypedGoRoute<HomeRoute>(
path: '/families',
routes: <TypedGoRoute<GoRouteData>>[
TypedGoRoute<FamilyRoute>(path: ':familyId')
],
)
class HomeRoute extends GoRouteData {
const HomeRoute();
@override
Widget build(BuildContext context) => const HomeScreen();
}
class FamilyRoute extends GoRouteData {
const FamilyRoute(this.familyId);
final String familyId;
@override
Widget build(BuildContext context) =>
FamilyScreen(family: familyById(familyId));
}
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text(_appTitle)),
body: ListView(
children: <Widget>[
for (final Family family in familyData)
ListTile(
title: Text(family.name),
onTap: () => FamilyRoute(family.id).go(context),
)
],
),
);
}
class FamilyScreen extends StatelessWidget {
const FamilyScreen({required this.family, Key? key}) : super(key: key);
final Family family;
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: Text(family.name)),
body: ListView(
children: <Widget>[
for (final Person p in family.people)
ListTile(
title: Text(p.name),
),
],
),
);
}
const String _appTitle = 'GoRouter Example: builder';
flutter doctor -v (windows)
|
@chunhtai I think you misassigned :) I'm not the PR author. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
When you define
TypedGoRoute
like this:This is generated:
The
location
getter is wrong, it should be'/families/${Uri.encodeComponent(familyId)}'
.Code sample is taken from here.
Also if you use child route with only param like this:
This also generates incorrect location:
should be
'/${Uri.encodeComponent(fid)}/${Uri.encodeComponent(pid.toString())}/${Uri.encodeComponent(_$PersonDetailsEnumMap[details]!)}'
Code sample here.
Logs
The text was updated successfully, but these errors were encountered: