Skip to content
pubscout

dsbridge_flutter

1.2.0, released 2 years ago by an unverified publisher

A Flutter plugin that enables synchronous and asynchronous JavaScript‑Dart communication via a WebView bridge.

WASM-ready
$ flutter pub add dsbridge_flutter
Source repository

What it does

It wraps webview_flutter and adds a JavaScript bridge allowing Dart code to expose functions to JavaScript and call JavaScript functions. Supports sync, async, progress callbacks, namespaces and debug mode.

AI-written summary of version 1.2.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need tight two‑way interaction between a WebView's JavaScript and Flutter code
  • You want to reuse existing dsbridge.js code without rewriting it
  • You require progress callbacks or modal dialogs from JavaScript

Skip it when

  • You only need to display static web content without native interaction
  • You prefer a pure Dart‑only solution without a WebView

Strengths

  • Full‑duplex bridge with sync and async calls
  • Namespace support for large API sets
  • Progress callbacks and built‑in JavaScript dialogs

Weaknesses

  • Depends on webview_flutter, so inherits its platform limitations
  • Adds extra layer of complexity compared to direct JavaScript injection

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
2
import 'package:dsbridge_flutter/dsbridge_flutter.dart';

class JsApi extends JavaScriptNamespaceInterface {
  @override
  void register() {
    registerFunction(testSyn);
    registerFunction(testAsyn);
  }
  String testSyn(dynamic msg) => "$msg[syn call]";
  void testAsyn(dynamic msg, CompletionHandler handler) => handler.complete("$msg [ asyn call]");
}

void main() async {
  final controller = DWebViewController();
  controller.addJavaScriptObject(JsApi());
  // load your page, then you can call JS functions:
  controller.callHandler('addValue', args: [3,4], handler: (ret) => print(ret));
}

Alternatives

Packages that do the same job and could replace dsbridge_flutter.

Works with

Packages commonly used together with dsbridge_flutter: ones it builds on, ones built on it, and its own family.