Search code examples
flutterflutter-provider

How can I differentiate between Providers that provide the same class


I have four providers, that all provide the Instances of Challenge class, to the same Widget. They are different challenges, but I don't know how to differentiate between the providers, so i wondered, if it's possible to give names to the providers.


Solution

  • Actually, you can't, this is the biggest drawback of provider, you can use riverpod instead, it's from the same author, but it has some advantages over a normal provider.

    this is what the author of both provider and riverpod sais.

    It makes the provider pattern more flexible, which allows supporting commonly requested features like: Being able to have multiple providers of the same type.