Tuesday, 4 April 2023

LegacyJavaScriptObject when passing object from Dart to JavaScript

I am trying to write a flutter web plugin for FreshChat sdk. I didn't get far at all because I am struggling with passing parameters properly. I have this code:

@JS()
library freshchat_sdk;

import 'package:js/js.dart';

@JS('window.fcWidget.open')
external void open();

@JS('window.fcWidget.user.setProperties')
external Future<void> setProperties(dynamic properties);

and when I call setProperties from dart side and pass Map<String, dynamic> as a parameter (or actually any other object like string etc) I get the following error:

Error: PlatformException(error, Invalid argument: Instance of 'LegacyJavaScriptObject', null, null)

This is an example from FreshChat Javascript documentation on how to invoke setProperties:

<script>
window.fcWidget.user.setProperties({
  firstName: <fname>,
  lastName: <lname>,
  email: <email>,
  phone: <phone>,
  phoneCountry: <country_code>,
  "plan": "Estate",
  "status": "Active",
  "Last Payment": "12th August"
});
</script>

My question is how do I write and invoke this interop correctly?



from LegacyJavaScriptObject when passing object from Dart to JavaScript

No comments:

Post a Comment