bd_bridge_client 0.1.0

Flutter Bridge Client.

bridge_client #

Usage #

Bridge Interface Define

import 'package:meta/meta.dart';
import 'package:bd_bridge_client/annotation.dart';
import 'package:bd_bridge_client/client.dart';

part "ui.g.dart";

@Bridge('UI')
mixin UI on BridgeModule {
  @BridgeMethod()
  Future<void> toast({String message});
}

Run Codegen

flutter packages pub run build_runner build

Generate ui.g.dart file part:

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'ui.dart';

// **************************************************************************
// BridgeGenerator
// **************************************************************************

class UIBridge extends BridgeModule with UI {
  UIBridge({BridgeClient client}) : super(client: client);
  Future<void> toast({
    String message,
  }) {
    var _$params = {
      'message': message,
    };
    var _$result = client.getData<void>('TTRUI.toast', params: _$params);
    return _$result;
  }
}

Usage in Dart

bridge.ui.toast(message: 'Send Message~');

Get In Native Side

public class ToastMethod extends BridgeMethods.PublicMethod {
    @Override
    public Single<IBridgeResult> call(IBridgeContext context, JsonObject params) {
        Toast.makeText(getApplicationContext(), params.get("message").getAsString(), Toast.LENGTH_SHORT).show();
        return BridgeResult.createSingleSuccessBridgeResult(params);
    }
}
0
likes
30
pub points
39%
popularity

Flutter Bridge Client.

Homepage

Uploader

liufengkai@bytedance.com

License

unknown (LICENSE)

More

Packages that depend on bd_bridge_client