Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

flutter wrapper instead? #4

Open
stagfoo opened this issue Dec 27, 2022 · 2 comments
Open

flutter wrapper instead? #4

stagfoo opened this issue Dec 27, 2022 · 2 comments

Comments

@stagfoo
Copy link
Owner

stagfoo commented Dec 27, 2022

Here is an example of communication from Javascript code to flutter.

In Flutter build your WebView like :

WebView(
              initialUrl: url,
              javascriptMode: JavascriptMode.unrestricted,
              javascriptChannels: Set.from([
                JavascriptChannel(
                    name: 'Print',
                    onMessageReceived: (JavascriptMessage message) {
                      //This is where you receive message from 
                      //javascript code and handle in Flutter/Dart
                      //like here, the message is just being printed
                      //in Run/LogCat window of android studio
                      print(message.message);
                    })
              ]),
              onWebViewCreated: (WebViewController w) {
                webViewController = w;
              },
            )

and in Your HTMLfile:

<script type='text/javascript'>
    Print.postMessage('Hello World being called from Javascript code');
</script>
@stagfoo
Copy link
Owner Author

stagfoo commented Dec 27, 2022

@stagfoo
Copy link
Owner Author

stagfoo commented Dec 27, 2022

flutter getx

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant