dart_web_plugin_base 0.0.2 copy "dart_web_plugin_base: ^0.0.2" to clipboard
dart_web_plugin_base: ^0.0.2 copied to clipboard

Platformweb

Dart web plugin base - Make calls from dart to js and vice-versa.

dart_web_plugin_base #

Test Lint

This plugin makes your development easy when you call functions between dart and js.

How does it works? #

The plugin uses a simple approach by setting a simple Js on the assets.

1- Sent data from dart to js.

/**
 * This method is used to send data from dart side to Js.
 * @param - args.methodTarget(required): The method will be called on the js side.
 * @param - args.arguments(optional): The generic object with the data to get on the js side.
 * @param - args.file(optional): The file like txt or pdf to get on the js side.
 */
window.jsInvokeMethod = async (args) => {
  let result;
  const methodTarget = args.methodTarget;

  switch (methodTarget) {
    case 'getClient': {
    // result = <getClient implementation>
      break;
    }
    case 'getProduct': {
      // result = <getProduct implementation>
      break;
    }
  }
  return result;
};

2- Sent data from js to dart.

/**
 * This method is used to send data from js side to dart.
 * @param - args.methodTarget(required): The method will be called on the dart side.
 * @param - args.arguments(optional): The generic object with the data to get on the dart side.
 * @param - args.file(optional): The file like txt or pdf to get on the dart side.
 */
window.jsSendMessageToDart({
  methodTarget: 'uploadContract',
  arguments: { id: 13211 },
  file: File([], 'contract.pdf', { type: 'application/pdf' }),
});

Requirements #

You need to add a js file on assets and then add this js on index.html as well. See the example for more details.

1
likes
130
points
110
downloads

Publisher

unverified uploader

Weekly Downloads

Dart web plugin base - Make calls from dart to js and vice-versa.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, js, plugin_platform_interface, universal_html

More

Packages that depend on dart_web_plugin_base