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 [...]

example/lib/main.dart

// Copyright (c) 2024 flutter_module_bridge authors.
// Licensed under the MIT License. See LICENSE for details.

import 'package:flutter/material.dart';
import 'package:flutter_module_bridge/flutter_module_bridge.dart';

import 'examples/method_call_example.dart';
import 'examples/event_example.dart';
import 'examples/stream_example.dart';
import 'examples/progress_example.dart';
import 'examples/error_example.dart';

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

  // Initialize the bridge with MockTransport for the example app.
  // In a real add-to-app scenario, the native side would be real.
  await NativeBridge.initialize(
    config: const BridgeConfig(
      channelName: 'example_bridge',
      handshakeEnabled: false, // MockTransport has no native to handshake with
      logPayloads: true,
    ),
    // TODO: inject MockTransport — wired in step 15
  );

  runApp(const ExampleApp());
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(final BuildContext context) {
    return MaterialApp(
      title: 'flutter_module_bridge Example',
      theme: ThemeData(useMaterial3: true),
      home: const ExampleHome(),
    );
  }
}

class ExampleHome extends StatelessWidget {
  const ExampleHome({super.key});

  @override
  Widget build(final BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('flutter_module_bridge Examples')),
      body: ListView(
        children: [
          _ExampleTile(
            title: 'Method Calls',
            subtitle: 'call<T>(), invoke(), typed responses',
            page: const MethodCallExample(),
          ),
          _ExampleTile(
            title: 'Events',
            subtitle: 'on(), once(), off(), emit()',
            page: const EventExample(),
          ),
          _ExampleTile(
            title: 'Streaming',
            subtitle: 'stream<T>() — location, sensor data',
            page: const StreamExample(),
          ),
          _ExampleTile(
            title: 'Progress',
            subtitle: 'Upload / download with progress',
            page: const ProgressExample(),
          ),
          _ExampleTile(
            title: 'Error Handling',
            subtitle: 'BridgeException hierarchy',
            page: const ErrorExample(),
          ),
        ],
      ),
    );
  }
}

class _ExampleTile extends StatelessWidget {
  const _ExampleTile({
    required this.title,
    required this.subtitle,
    required this.page,
  });

  final String title;
  final String subtitle;
  final Widget page;

  @override
  Widget build(final BuildContext context) {
    return ListTile(
      title: Text(title),
      subtitle: Text(subtitle),
      trailing: const Icon(Icons.chevron_right),
      onTap: () => Navigator.push(
        context,
        MaterialPageRoute<void>(builder: (_) => page),
      ),
    );
  }
}
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