Uh oh!
There was an error while loading. Please reload this page.
[go_router_builder] Add ShellRoute support to go_router_builder - #3269
[go_router_builder] Add ShellRoute support to go_router_builder#3269johnpryan wants to merge 10 commits into
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
| ListTile( | ||
| title: Text( | ||
| '${entry.key.name} - ${entry.value}', | ||
| // TODO(kevmoo): replace `split` with `name` when min SDK is 2.15 |
| '/', | ||
| ); | ||
| void go(BuildContext context) => context.go(location, extra: this); |
There was a problem hiding this comment.
ShellRoute should not have go/push/pushRelacement
There was a problem hiding this comment.
Hmm... It probably shouldn't have a location either.
johnpryan
commented
Feb 23, 2023
I'm trying to add an example for ShellRouteData, but I'm stuck because the // 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_docsimport'package:flutter/material.dart';
import'package:go_router/go_router.dart';
part'shell_route_example.g.dart';
voidmain() =>runApp(App());
classAppextendsStatelessWidget {
App({super.key});
@overrideWidgetbuild(BuildContext context) =>MaterialApp.router(
routerConfig: _router,
);
finalGoRouter _router =GoRouter(routes: $appRoutes);
}
classHomeScreenextendsStatelessWidget {
constHomeScreen({super.key});
@overrideWidgetbuild(BuildContext context) =>Scaffold(
appBar:AppBar(title:constText('foo')),
);
}
@TypedShellRoute<MyShellRouteData>(
routes:<TypedRoute<RouteData>>[
TypedGoRoute<FooRouteData>(path:'/foo'),
TypedGoRoute<BarRouteData>(path:'/bar'),
],
)
classMyShellRouteDataextendsShellRouteData {
constMyShellRouteData();
@overrideWidgetbuilder(
BuildContext context,
GoRouterState state,
Widget navigator,
) {
returnMyShellRouteScreen(child: navigator);
}
}
classFooRouteDataextendsGoRouteData {
constFooRouteData();
@overrideWidgetbuild(BuildContext context, GoRouterState state) {
returnconstFooScreen();
}
}
classBarRouteDataextendsGoRouteData {
constBarRouteData();
@overrideWidgetbuild(BuildContext context, GoRouterState state) {
returnconstBarScreen();
}
}
classMyShellRouteScreenextendsStatelessWidget {
constMyShellRouteScreen({requiredthis.child, super.key});
finalWidget child;
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
bottomNavigationBar:BottomNavigationBar(
items:const<BottomNavigationBarItem>[
BottomNavigationBarItem(
icon:Icon(Icons.home),
label:'Foo',
),
BottomNavigationBarItem(
icon:Icon(Icons.business),
label:'Bar',
),
],
onTap: (int index) {
switch (index) {
case0:// const FooRouteData().go(context);break;
case1:// const BarRouteData().go(context);break;
}
},
),
);
}
}
classFooScreenextendsStatelessWidget {
constFooScreen({super.key});
@overrideWidgetbuild(BuildContext context) {
returnconstText('Foo');
}
}
classBarScreenextendsStatelessWidget {
constBarScreen({super.key});
@overrideWidgetbuild(BuildContext context) {
returnconstText('Bar');
}
} |
chunhtai
commented
Mar 9, 2023
Hi @johnpryan Do you know what's the state of this PR? |
johnpryan
commented
Mar 9, 2023
Sorry, this isn't ready to land yet. I'm currently busy with other projects, if someone else can work on this, feel free. The issue I mentioned in the comment above is becuase there's no generator for the ShellRoute annotation. To fix it, I think you need to wire it up in lib/go-router_builder.dart, here: so you add another GoRouterShellGenerator() or something to that array. I would also like to add more tests and a separate example for ShellRoute, similar to my comment above. |
@chunhtai I created a PR https://github.com/johnpryan/flutter_packages/pull/1 against @johnpryan 's branch: I created a
Based on your feedback, I'll add a test similar to the existing one for the I've also squashed merged the changes from master to solve the conflicts (pubspec and changelog) but maybe I shouldn't have because now the github action added all the labels... |
chunhtai
commented
Mar 10, 2023
Hi @GP4cK thanks for helping, can you create a PR directly against the flutter:main? I will close this pr. |
Depends on #2730
Fixesflutter/flutter#111909