MethodChannelPlatformBridge constructor
MethodChannelPlatformBridge()
构造函数,初始化方法通道并设置监听器
Implementation
MethodChannelPlatformBridge() {
methodChannel = const MethodChannel(_channelName);
// 设置MethodChannel监听器来处理来自原生的数据
methodChannel.setMethodCallHandler((call) async {
if (call.method == _methodSendToFlutter) {
final String receivedName = call.arguments[_paramName] as String;
final data = call.arguments[_paramData];
LogUtils.debug(
'Received data from native: name=$receivedName, data=$data');
if (_listeners.containsKey(receivedName)) {
LogUtils.debug('Calling listener for name: $receivedName');
_listeners[receivedName]!(data);
} else {
LogUtils.warning('No listener found for name: $receivedName');
}
}
return null;
});
LogUtils.info(
'MethodChannelPlatformBridge initialized with channel: $_channelName');
}