Skip to content
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

Typed Go_Router? #48

Open
JohnGalt1717 opened this issue May 2, 2024 · 5 comments
Open

Typed Go_Router? #48

JohnGalt1717 opened this issue May 2, 2024 · 5 comments
Labels
T: Feature Type: :tada: New Features

Comments

@JohnGalt1717
Copy link

I can't figure out from the documentation how to update this typed Go_Router route:

@immutable
class DiscoverRoute extends GoRouteData {
@OverRide
Widget build(BuildContext context, GoRouterState state) {
return DiscoverPage();
}
}

Using SwipablePageRoute doesn't return a widget, so I'm trying to figure out what I need to do here. It would be really helpful if the documentation covered this case.

Thanks!

@JohnGalt1717 JohnGalt1717 added the T: Feature Type: :tada: New Features label May 2, 2024
@Tuandiep98
Copy link

@JohnGalt1717 Just create a custom page extends SwipeablePage and throws it on GoRouter page builder like this

class SwipeablePageCustom extends SwipeablePage<void> {
  SwipeablePageCustom({
    required LocalKey key,
    required Widget child,
  }) : super(
          key: key,
          canOnlySwipeFromEdge: true,
          transitionDuration: const Duration(milliseconds: 350),
          reverseTransitionDuration: const Duration(milliseconds: 350),
          builder: (BuildContext context) => MaxWidthBox(
            maxWidth: 1200,
            background: Container(color: Theme.of(context).colorScheme.surface),
            child: child,
          ),
        );
}

GoRoute(
                        name: childrendashboard,
                        path: 'dashboard',
                        pageBuilder:
                            (BuildContext context, GoRouterState state) {
                          return SwipeablePageCustom(
                            key: UniqueKey(),
                            child: DashboardScreen(
                                room: state.extra as RoomModel?),
                          );
                        },`

@JonasWanke
Copy link
Owner

Sorry for the delay! I added a go_router_builder version in the example: 6fca6b8 (based on https://pub.dev/documentation/go_router_builder/latest/#transition-override). Unfortunately, I get a failed assertion when dragging a page away (not when using the back button), which doesn't happen with the normal go_router:

════════ Exception caught by scheduler library ═════════════════════════════════
The following assertion was thrown during a scheduler callback:
'package:flutter/src/widgets/heroes.dart': Failed assertion: line 747 pos 14: 'manifest.fromHero != newManifest.fromHero': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack:
#2      _HeroFlight.divert (package:flutter/src/widgets/heroes.dart:747:14)
heroes.dart:747
#3      HeroController._startHeroTransition (package:flutter/src/widgets/heroes.dart:1002:26)
heroes.dart:1002
#4      HeroController._maybeStartHeroTransition.<anonymous closure> (package:flutter/src/widgets/heroes.dart:926:9)
heroes.dart:926
#5      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1392:15)
binding.dart:1392
#6      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1326:11)
binding.dart:1326
#7      SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1171:5)
binding.dart:1171
#8      _invoke (dart:ui/hooks.dart:312:13)
hooks.dart:312
#9      PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
platform_dispatcher.dart:419
#10     _drawFrame (dart:ui/hooks.dart:283:31)
hooks.dart:283
(elided 2 frames from class _AssertionError)
════════════════════════════════════════════════════════════════════════════════

I haven't been able to pinpoint where the difference lies between the two, and won't have time to debug it in more detail until at least the week after next. Feel free to give it a try, maybe you have an idea to fix the bug – I'm using go_router_builder for the first time today

@Tuandiep98
Copy link

@JonasWanke I'm also faced that after upgrade version flutter higher than 3.16.9, looks like the new flutter makes some changes about that, you can downgrade flutter and retry, hope it helps.

@JonasWanke
Copy link
Owner

@Tuandiep98 Did you have that error with go_router_builder or even without it? Unfortunately, with Flutter's breaking change (see #52), the new version of this package only supports Flutter 3.22 and newer, so the workaround (older Flutter version) only works with older versions of this package

@Tuandiep98
Copy link

@JonasWanke I'm just using page builder like code attached above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: Feature Type: :tada: New Features
Projects
None yet
Development

No branches or pull requests

3 participants