Skip to content

Add bridgeEvents API and typed JavaScript handler helpers (additive, cross-platform) #2793

@parkwoocheol

Description

@parkwoocheol

Is there an existing feature request for this?

  • I have searched the existing feature request

Operating System

All platforms if possible: Android, iOS, macOS, Windows, Linux, Web (same-origin constraints on Web).

Pain

Current JavaScript communication APIs are powerful, but common app flows still require repetitive low-level code:

  • Dart -> JS push-style messaging is usually done with manual evaluateJavascript.
  • JS handler payloads often require manual JSON parsing/encoding in app code.
  • Event-style communication patterns are not standardized at the controller API level.
  • Cross-platform app code becomes verbose and easier to break with custom bridge boilerplate.

This increases complexity for users who need structured, bidirectional JS communication.

Suggested solution

Add an additive high-level JS bridge layer without changing existing behavior:

  1. controller.bridgeEvents API
  • on(eventName, callback)
  • off(eventName, [callback])
  • emit(eventName, data)
  • hasListener(eventName)
  1. Typed handler helper APIs
  • addSerializedJavaScriptHandler<TRequest, TResponse>(...)
  • addJsonJavaScriptHandler<TRequest, TResponse>(...)

Design constraints:

  • No breaking changes to existing addJavaScriptHandler behavior.
  • Keep existing bridge security model and allowlist behavior unchanged.
  • Do not hardcode bridge global name; use runtime bridge name.
  • Implement for all active platform bridge initialization paths to keep API consistency.

Acceptance criteria:

  • Existing apps continue to work unchanged.
  • New APIs are fully additive.
  • Example + integration tests cover bridgeEvents and typed handler roundtrip.

Useful resources

Additional information

I can implement this in a feature branch and open a PR with:

  • platform-consistent bridge wiring
  • backward-compatibility checks
  • example coverage
  • integration tests

Self grab

  • I'm ready to work on this issue!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions