flutter_module_bridge 0.1.2 copy "flutter_module_bridge: ^0.1.2" to clipboard
flutter_module_bridge: ^0.1.2 copied to clipboard

A production-grade, bidirectional communication bridge between Flutter modules and native Android/iOS applications. Designed with a protocol-first architecture, strong typing, interceptors, capability [...]

flutter_module_bridge #

A production-grade, bidirectional communication bridge between Flutter modules and native Android/iOS applications.

pub.dev License: MIT Flutter


Features #

  • Protocol-first — Every message is a versioned BridgeEnvelope
  • Typed APIcall<LoginResponse>("auth.login", request)
  • Capability negotiation — Handshake, version agreement, method discovery
  • Namespace supportbridge.namespace("auth").call("login")
  • Eventson(), once(), off(), emit()
  • Streams — Continuous native data (location, sensors, Bluetooth)
  • Progress — Upload/download progress with onProgress callback
  • CancellationBridgeCancellationToken with native signal
  • Queue — Requests submitted before init are automatically flushed
  • Connection statesdisconnected → connecting → handshaking → ready
  • Metrics — EMA response time, error rates, active request count
  • PluginsHeartbeatPlugin, ReconnectionPlugin, custom plugins
  • MiddlewareLoggingMiddleware, RetryMiddleware, custom middleware
  • Interceptors — Auth injection, encryption, analytics
  • MockTransport — Full test coverage without a native host
  • Multi-engine — Multiple named instances for FlutterEngineGroup

Quick Start #

1. Initialize #

import 'package:flutter_module_bridge/flutter_module_bridge.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await NativeBridge.initialize(
    config: BridgeConfig(channelName: 'app_bridge'),
  );

  runApp(const MyApp());
}

2. Register Types #

NativeBridge.registerType<LoginResponse>(
  fromJson: LoginResponse.fromJson,
  toJson: (r) => r.toJson(),
);

3. Call Native #

final user = await NativeBridge.call<LoginResponse>(
  'auth.login',
  LoginRequest(email: 'user@example.com', password: '...'),
);

4. Listen to Events #

final sub = NativeBridge.on<UserEvent>('userUpdated', (event) {
  print('User updated: ${event.name}');
});

// Cancel when done
sub.cancel();

5. Stream Data #

NativeBridge.stream<LocationEvent>('location').listen((loc) {
  print('${loc.lat}, ${loc.lng}');
});

Native Setup #

Android (Kotlin) #

// In your Activity or Application
val bridge = FlutterModuleBridgePlugin.getBridge(flutterEngine)

bridge?.namespace("auth")
    ?.register<LoginRequest, LoginResponse>("login") { request, _, _ ->
        authService.login(request.email, request.password)
    }

iOS (Swift) #

// In your AppDelegate or FlutterViewController subclass
guard let bridge = FlutterModuleBridgePlugin.getBridge(for: flutterEngine) else { return }

bridge.namespace("auth")
    .register("login", LoginRequest.self, LoginResponse.self) { request, _, _ in
        try await authService.login(email: request.email, password: request.password)
    }

Documentation #


License #

MIT — see LICENSE.

0
likes
120
points
138
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A production-grade, bidirectional communication bridge between Flutter modules and native Android/iOS applications. Designed with a protocol-first architecture, strong typing, interceptors, capability negotiation, and a pluggable ecosystem.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, logging, meta, plugin_platform_interface, uuid

More

Packages that depend on flutter_module_bridge

Packages that implement flutter_module_bridge