1

I want to pass data from flutter to webview

My data is defined like this,

var data = {
   "id": "hweqetwyqte"
};

I am passing data like below in webview,

webViewController.evaluateJavascript('''
 t._selectItem($data); // this is not working --> I want this to work
 t._selectItem({"id": "hweqetwyqte"}); // this is working
''');

Any help would be appreciated!!

Suraj Gupta
  • 437
  • 8
  • 19

1 Answers1

-1

Try

t._selectItem({"id": "${data['id']}}"})
Huthaifa Muayyad
  • 11,321
  • 3
  • 17
  • 49
  • What do you get when you print data.tostring? – Huthaifa Muayyad May 05 '21 at 17:01
  • `this._controller.evaluateJavascript(''' twod._selectPlaces(jsonEncode($data)); ''');` this also doesnt work – Suraj Gupta May 05 '21 at 18:17
  • What do you mean not working, it's near impossible debugging errors without the error. – Huthaifa Muayyad May 05 '21 at 18:19
  • `Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript, JavaScript string was: ' t._selectItem(jsonEncode({id: 'dfs'fs',}) `. jsonEncode is going as a strring This is what i get when i print – Suraj Gupta May 05 '21 at 18:22
  • i have object with lot more keys, how can we do that? – Suraj Gupta May 05 '21 at 18:28
  • But that worked, correct? The error is important. The problem is because your javascript needs the "" quotation marks. The previous methods didn't pass those marks to the webview, and that's why using $data inside the decorating qoutations worked. Try a variable called: `String data2 = data.toString()`, and in your webview, use `$data2`. Still, the more info you share is better. But replying with `it doesn't work`< doesn't really help on Stackoverflow. – Huthaifa Muayyad May 05 '21 at 18:32
  • Thanks, but it didnt worked and as you said using string also not working, Getting `Failed evaluating JavaScript, JavaScript string was: ' ` – Suraj Gupta May 05 '21 at 18:40