I have a question, regarding reading providers from inside static methods or global methods. I am using riverpod and awesome_notification packages, and I need to alter the state the app, from the action of the notification, for this, the package uses static methods inside a controller class.
class NotificationController{
...
static Future<void> onActionReceivedMethod(ReceivedAction receivedAction) async {
...//some way to access a provider, to call methods on it
}
...
}
If there is another way of doing this that I am not seeing, please let me know.
I have not been able to find a way to do this.
You can:
ref
function as a parameter.ref
field in the constructor.An additional example:
Either way, you should always have access to `Ref'.
Update:
As @OppositeDragon and @Eran Ravid pointed out, we really can't access _ref in a static method. However, if you define
_ref
in the constructor, it is possible. I think it's a terrible anti-pattern, though. Use method 1 and you will be fine.