csells / go_router

The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
https://gorouter.dev
441 stars 96 forks source link

[feature request] Future redirect #283

Closed ferraridamiano closed 2 years ago

ferraridamiano commented 2 years ago

In my app I need to fetch some data from the storage/network and depending on the result of this data I would like to redirect the user to a different page. In the meantime I would like to show a splashscreen. At the moment I think I cannot do it with this package. A workaround could be to pass the Future object to the splash screen and when the result is ready the splashScreen redirect the user to a different page. A nicer code could be something like this:

final _router = GoRouter(
    routes: [
        GoRoute(
            path: '/',
            futureRedirect: FutureRedirect(
                future: _myFutureData,
                initialPage: const SplashScreen(),
                redirect: '/page/${_myFutureData}',
            ),
        ),
    ],
);

I hope that this feature request makes sense. Anyway thank you for your work!

csells commented 2 years ago

Check out these docs: https://gorouter.dev/redirection

And check out this sample: https://github.com/csells/go_router/blob/main/go_router/example/lib/loading_page.dart

ferraridamiano commented 2 years ago

Thank you! It is exactly what I need