bd_bridge_client 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new24

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.1.0 #

  • Support Bridge, BridgeMethod Annotation CodeGen.
  • Support Bridge Client Trans to Native.
  • Support UserDesign Params use in override.
  • Support Params, Result Processor
  • Support Complex Code.

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"),
              )
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  bd_bridge_client: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:bd_bridge_client/annotation.dart';
import 'package:bd_bridge_client/builder.dart';
import 'package:bd_bridge_client/client.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
37
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
30
Overall:
Weighted score of the above. [more]
24
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis issues and suggestions

Fix dependencies in pubspec.yaml.

Running flutter pub upgrade failed with the following output:

ERR: Because bd_bridge_client depends on ln_emitter any which doesn't exist (could not find package ln_emitter at https://pub.dartlang.org), version solving failed.

Health suggestions

Format lib/src/client.dart.

Run flutter format to format lib/src/client.dart.

Format lib/src/generator.dart.

Run flutter format to format lib/src/generator.dart.

Maintenance issues and suggestions

No valid SDK. (-20 points)

The analysis could not detect a valid SDK that can use this package.

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://code.byted.org/bd-flutter-plugins/bd-bridge-client was unreachable.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0