I have a Flutter application that uses Provider for state management.
Recently I have the need to embed my Flutter application in an iFrame and call a dart function using javascript.
Typically to do this you would setProperty(window, ‘update’, allowInterop(Controller.update));
The issue I am having is that the allowInterop function requires that the function provided is a function or static method in a class. But since my function is within a class that extends ChangeNotifier I can’t simply just make the class I want to use static. This is because the class within my Provider calls notifyListeners() which can’t be called from a static method.
How can I call my Provider method using Javascript in Flutter?
I tried creating a global class with static methods but this means that none of my data that is listening to changes would update.
I tried removing the requirement for Provider but then state management becomes significantly harder.
Jose Alba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.