-1

I'm using go_router and riverpod. I get a query param and I want to set it in a StateProvider. I can't do it here:

final goRouterProvider = Provider<GoRouter>((ref) {
  return GoRouter(
    routes: [
      GoRoute(
        path: '/home',
        builder: (context, state) => HomePage(

also not in initState and not in build.

Rony Tesler
  • 1,207
  • 15
  • 25
  • 1
    Please stop using StateProvider, StateNotifier, and ChangeNotifier. They lead to bad code designs. Notifier replaces all of those, but in a more scalable manner. – Randal Schwartz Aug 06 '23 at 17:45
  • Even though the docs say we can use it for simple use cases like mine? https://riverpod.dev/docs/providers/state_provider. And how would using a notifier solve my problem? – Rony Tesler Aug 06 '23 at 18:38
  • That's the old docs. See https://docs-v2.riverpod.dev/docs/why_riverpod et seq. And your Provider example is fine. I was commenting on your "next step" to involve a StateProvider, and objecting to that. – Randal Schwartz Aug 06 '23 at 23:10
  • Which example is fine? I changed my StateProvider to StateNotifierProvider. – Rony Tesler Aug 06 '23 at 23:13
  • I see a reference to StateProvider in your first paragraph, and a Provider in the code, but no reference to StateNotifierProvider. So paint me confused. – Randal Schwartz Aug 06 '23 at 23:15
  • After you said my docs are old I changed my provider to StateNotifierProvider. But that still doesn't solve the original problem. – Rony Tesler Aug 06 '23 at 23:36
  • 1
    Again, I told you to avoid StateNotifierProvider. If you're not going to listen, I'm done talking. :( – Randal Schwartz Aug 07 '23 at 02:03
  • I just misunderstood you, sorry, not familiar enough with Riverpod. So I should use the NotifierProvider that provides a Notifier? – Rony Tesler Aug 07 '23 at 11:32
  • 1
    Yes. And at this point, with this much discussion, you probably would have gotten a quicker answer on Discord or Slack. SO is ok, but sometimes, there's a lot of interaction that must go on. – Randal Schwartz Aug 07 '23 at 17:52
  • But I don't understand how this answers the question. I'll use Notifier and NotifierProvider but how do I set its value once when the screen loads? – Rony Tesler Aug 07 '23 at 20:12

0 Answers0