module_bridge 1.0.1
module_bridge: ^1.0.1 copied to clipboard
Dart modular development, event communication library. Dart模块化开发,事件通信库。
Chinese Doc #
Dart modular development event communication library. #
Step1 #
1.Install FlutterModuleBridge plugin.
2.Add dependencies latest_version
dependencies:
module_bridge: ^latest_version
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')
R getUserId(Map<String, String> params) {
return R.ok(data: 1234);
}
@Url(url: '/user/getUserName', desc: 'Get user name')
Future<R> getUserName(Map<String, String> params) async {
return R.ok(data: 'azhon');
}
}
⚠️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 beR
orFuture<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() {}
}
3.Initialize the submodules in the main module
ModuleManager.add(UserModule());
Step4 #
In any module communicate through the following code
var r = await BridgeManager.instance.get('/user/getUserId');