1

I have a Javascript file that I'm calling in my Flutter Webview Plugin.

I am trying to return the callback in the console after the onReward method is called. This is the code of my js file:

<html>
<head>
 <meta charset='utf-8'>
 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
 <meta http-equiv='X-UA-Compatible' content='IE=edge'>
 <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="https://s3.amazonaws.com/cdn.theoremreach/v3/theorem_reach.min.js"></script>
</head>
<body>
 <iframe src="https://theoremreach.com/respondent_entry/direct?api_key=845783b32b8bef12f1b55a36a8be&user_id=12345"></iframe>
 <script type="text/javascript">
var theoremReachConfig = {
apiKey: "",
userId: "12345",
onRewardCenterOpened: onRewardCenterOpened,
onReward: onReward,
onRewardCenterClosed: onRewardCenterClosed
};

var TR = new TheoremReach(theoremReachConfig);

function onRewardCenterOpened(){
console.log("onRewardCenterOpened");

}

function onReward(data){
console.log("onReward: " + data.earnedThisSession);
}

function onRewardCenterClosed(){
console.log("onRewardCenterClosed");
}

if (TR.isSurveyAvailable()) {
TR.showRewardCenter();
}

</script>
</body>
</html>

And this is how I'm calling it in my Dart file:

...
  Widget build(BuildContext context) {
    return Scaffold(
       appBar: AppBar(title: Text("Reward earned"), actions: [
         Text("$reward"),
         ]),
        body: WebViewPlus(
      javascriptMode: JavascriptMode.unrestricted,
      onWebViewCreated: (controller) {
        controller.loadAsset(
          'assets/tr.html',
        );
      },
    ));
  }

When I complete a survey I get the following message in my console:

I/chromium( 3560): [INFO:CONSOLE(28)] "onReward: 2", source: http://localhost:56537/assets/tr.html (28)

I want to scan this console message and just add the value of the reward, i.e. 2, in my existing page and display it in the appBar.

6
  • Check this answer. Commented Jun 30, 2020 at 13:50
  • is there a way to read the console message for the output? LIke I want to add the console message 'onReward:2' in my dart code @SamiHaddad Commented Jul 1, 2020 at 13:07
  • You can send the data using postMessage: postMessage(data.earnedThisSession) and read it with onMessageReceived and manipulate it in your dart code. Commented Jul 1, 2020 at 13:26
  • How do I read the data with onMessageReceived ?@SamiHaddad Commented Jul 2, 2020 at 12:27
  • Check the answer I linked above. Commented Jul 2, 2020 at 17:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.