Making a Dart function callable from JavaScript
I’m trying to integrate a flutter module into a PWA application. I would like to access one Dart function from PWA using JS after the flutter web build is taken for integration. Used the following official package to call JavaScript APIs from Dart code, or vice versa.
flutter package – https://pub.dev/packages/js#making-a-dart-function-callable-from-javascript
following is the sample JS used for accessing a sample dart function, here I’m loading the main.dart.js which generated with
flutter build web
from flutter module
<script src="./main.dart.js"></script>
<script type="text/javascript">
function callMethodFromFlutter() {
window.functionName();
}
</script>
but getting the following errors with window and without window object
window.functionName is not a function
functionName is not defined
Any idea what’s wrong here? or any other alternative way for communication between a flutter module and PWA just like platform channels used for android/iOS.
I have seen similar questions but no proper solution on StackOverflow.