JaspervanRiet / duck_router

A Flutter router with intents
MIT License
4 stars 3 forks source link

feat: expose GlobalKey in StatefulLocation #21

Closed DelcoigneYves closed 2 months ago

DelcoigneYves commented 2 months ago

Description

Partial fix for #11 , so we can access the GlobalKey used in a StatefulLocation's DuckShell when wanting to override this in the pageBuilder property.

Related Issues

11

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

JaspervanRiet commented 2 months ago

Two questions:

Thanks!

DelcoigneYves commented 2 months ago

Certainly!

One of the cases is shown in my example project, where I wanted to create a StatefulLocation with a custom animation. We need to override the pageBuilder for this, and make sure to add the DuckShell in its implementation.

JaspervanRiet commented 2 months ago

I see what's up. You want to wrap stateful location in a Page, but it only supports wrapping in a Widget. So what you do is you grab the pageBuilder all the way on the core Location. It basically means you need to re-implement StatefulLocation all over again, but now _key is private.

Are you able to do the following?

  @override
  LocationPageBuilder? get pageBuilder => (context) => ModalPage(
        name: path,
        child: builder(context),
      );

It's complex, but now you've got a Page wrapping the "normal" stateful location builder, including key, and then you've got a childBuilder with your wrapping page as well as all the child locations.

DelcoigneYves commented 2 months ago

Yes this works, thank you! Looks a lot nicer than before as well, not having to know the intrinsics of the StatefulLocation. I'll close this one.