-
I use the package flutter_secure_storage to store a jwt. And to handle if the jwt is expired I have to run asynchronous code. To redirect to the login page I need to use the redirect: of the GoRouter so it can checks everytime a new screen is displayed. The problem is that redirect: from GoRouter wants a String? and not a Future<String?> so I can't use async and await keywords otherwise I'll get my screen full of red underlined text. I tried using a ".then" callback but without success for the moment cause it doesn't await the end of the callback. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
The |
Beta Was this translation helpful? Give feedback.
-
You can use the combo of redirect + refreshListener by updating the object that you pass to refreshListener be updated with that data. I do a similar thing in the loading page example. |
Beta Was this translation helpful? Give feedback.
-
Like any async data in Flutter, you can load it and show it however you like. Here're some docs you might find useful: https://gorouter.dev/async-data |
Beta Was this translation helpful? Give feedback.
-
I found a solution and made a repo with all my code so it can help others. Edit: the widget is a FutureBuilder |
Beta Was this translation helpful? Give feedback.
I found a solution and made a repo with all my code so it can help others.
The solution I found is to forget redirect / refreshListenable and to use a widget that I wrap on every routes : the widget and the main.dart with the router
Edit: the widget is a FutureBuilder