onMessageReceived static method

Future<void> Function(JavaScriptMessage) onMessageReceived(
  1. WebViewController controller
)

Returns a callback ready to plug into controller.addJavaScriptChannel(BRIDGE_NAME, onMessageReceived: …). Each incoming message is routed through the FlareLane bridge core; if the core returns a JS string (e.g. the syncDeviceData response), it is evaluated back into the webview via the controller.

Implementation

static Future<void> Function(JavaScriptMessage) onMessageReceived(
    WebViewController controller) {
  return (JavaScriptMessage message) async {
    final String? js = await BridgeCore.handle(message.message);
    if (js != null) {
      await controller.runJavaScript(js);
    }
  };
}