module_bridge

Last updated:

0 purchases

module_bridge Image
module_bridge Images
Add to Cart

Description:

module bridge

Chinese Doc #
Dart modular development event communication library. #

Step1 #
1.Install FlutterModuleBridge plugin.
2.Add dependencies latest_version
dependencies:
module_bridge: ^latest_version
copied to clipboard
Step2 #
Create a communication template in the module /lib directory
import 'package:module_bridge/module_bridge.dart';

class UserBridge with Bridge {

@Url(url: '/user/getUserId', desc: 'Get UserId')
Future<R<int>> getUserId(Map<String, String> params) {
return R.ok(data: 1234);
}

@Url(url: '/user/getUserName', desc: 'Get user name')
Future<R<String>> getUserName(Map<String, String> params) async {
return R.ok(data: 'azhon');
}
}
copied to clipboard
⚠️Notice

A dart file can only have one class
The class must be with Bridge
The method must be annotated with @Url
The method parameter must be Map<String, String>, and the return value must be R or Future<R> type

Step3 #
1.Use FlutterModuleBridge plugin generate class
2.Create a Module in a submodule and register events in the register()
class UserModule extends BaseModule {
@override
void register() {
BridgeManager.instance.register(UserModuleBridge().bridges);
}

@override
void unregister() {}
}
copied to clipboard
3.Initialize the submodules in the main module
ModuleManager.add(UserModule());
copied to clipboard
Step4 #

In any module communicate through the following code

var r = await BridgeManager.instance.get<int>('/user/getUserId');
copied to clipboard

Or use in build method

BridgeBuilder<int>(
bridge: '/user/getUserId',
builder: (_, data) {
/// data maybe equal null
return Text('use BridgeBuilder get data:$data');
},
),
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.