bd_bridge_client 0.1.0
bd_bridge_client: ^0.1.0 copied to clipboard

Flutter Bridge Client.

example/lib/main.dart

import 'package:bd_bridge_client/client.dart';
import 'package:bridge_client_example/api/call_standard.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'api/ui.dart';

class MyBridge {
  final client = BridgeClient();

  UIBridge get ui => _ui;
  UIBridge _ui;

  CallStandard _callStandard;
  CallStandard get standard => _callStandard;

  MyBridge() {
    _ui = new UIBridge(client: client);
    _callStandard = new CallStandardBridge(client: client);
  }
}

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final MyBridge bridge = MyBridge();
//  MethodChannel channel = new MethodChannel('com.bytedance.hybrid.bridge-flutter');

  @override
  void initState() {
    super.initState();
    bridge.client.on("test", (params) {
      print('test');
      print(params);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: new Column(
            children: <Widget>[
              FlatButton(
                onPressed: () async {
                  print(await bridge.ui.toast(message: 'Send Message'));
                  print(await bridge.standard.toast(message: [1, 2, 3, 4, 5]));
                },
//                onPressed: () => channel.invokeMethod("fuck"),
                child: Text("Click Send Toast"),
              )
            ],
          ),
        ),
      ),
    );
  }
}