Open a-h-mzd opened 1 year ago
Hey @a-h-mzd does this work with includePrefixmatches set to false?
Hey @Milad-Akarie. in that case there are no screens behind the current one because we have just reloaded the screen. Am I right?
@a-h-mzd You are right, so in your case there are actual a page behind active route but the transaction not working?
@Milad-Akarie Correct. Also, interactivity is lost if you try to pop using a gesture. You can check the stack trace and the video to see this.
@Milad-Akarie I can send you a minimum working project so you can see the error for yourself if this would help.
@a-h-mzd that would be great, I've noticed that you're initiating your router inside of the build method which can cause a lot of issues, remove it from the build method first then see if you still get issues.
class MyApp extends StatelessWidget {
MyApp();
final _rootRouter = RootRouter();
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: _rootRouter.config(),
);
}
I'm initiating it this way only in this example project and not in the actual project that I'm working on. And I can tell you that the issue persists.
I see, I'm waiting for minimum project that reproduces this issue.
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Flutter Test',
theme: ThemeData.light(),
routerConfig: AppRouter().config(
includePrefixMatches: true,
),
);
}
}
@RoutePage()
class Page1 extends StatelessWidget {
const Page1({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Hero(
tag: #tag,
transitionOnUserGestures: true,
child: FloatingActionButton(
heroTag: null,
onPressed: () => context.navigateTo(const Route2()),
child: const Icon(Icons.arrow_forward_ios_rounded),
),
),
),
);
}
}
@RoutePage()
class Page2 extends StatelessWidget {
const Page2({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Hero(
tag: #tag,
transitionOnUserGestures: true,
child: FloatingActionButton(
heroTag: null,
onPressed: () => context.back(),
child: const Icon(Icons.arrow_back_ios_new_rounded),
),
),
),
);
}
}
@AutoRouterConfig()
final class AppRouter extends $AppRouter {
@override
List<AutoRoute> get routes {
return <AutoRoute>[
AutoRoute(
path: '/',
page: Route1.page,
),
AutoRoute(
path: '/second',
page: Route2.page,
),
];
}
}
@a-h-mzd what does this hashtag mean? tag: #tag. this's new to me
@a-h-mzd When working for the web you should use context.router.back()
instead of router.pop()
or the shortcut context.back()
because that's the same as clicking the browser's back button, on the other hand popping routes will add duplicate entries and complicate things on the web.
also, consider using context.router.navigate
instead of context.router.push on the web so you avoid duplicate entries
shortcut: context.navigateTo(route)
try again with these suggestions and let me know what you get
@Milad-Akarie the hashtag is how you'd define a Symbol
. Since the hero tag can be anything I prefer using a hashtag to create a symbol for it.
@Milad-Akarie Thank you for the great advice. I updated the minimum project that reproduces this issue. Should I use those methods only on the web or are they safe to use also on other platforms? FYI the issue persists!
ya they're preferred to be used in Web Apps, especially the back() method, what I also did is remove the initializing of the route from the build method.
class MyApp extends StatelessWidget {
MyApp({super.key});
final router = TestAppRouter();
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Flutter Test',
theme: ThemeData.light(),
routerConfig: router.config(
includePrefixMatches: true,
),
);
}
}
I'm not getting any errors any more, everything works nicely
Are you sure? Because I still get the error.
Make sure to use gestures to go back not click on the button.
@Milad-Akarie, Is there anything else I can provide you with?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions
Commenting to prevent issue from getting closed.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions
Commenting to remove the no-issue-activity
tag.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions
Steps to reproduce:
transitionOnUserGestures
set totrue
.includePrefixMatches
totrue
Screen record
https://github.com/Milad-Akarie/auto_route_library/assets/42738288/ecb30a95-b4aa-4a96-a6bc-764dd63b4d9c
Versions:
flutter: 3.10.6 auto_route: 7.7.1 auto_route_generator: 7.2.0
Stack trace: