registerMethod method
Register a method handler
@param method Method name @param handler Function to handle the method call
Implementation
void registerMethod(
String method,
Future<dynamic> Function(dynamic) handler,
) {
print('Registering method handler for: $method');
on('method:$method', (dynamic params, Function respond) async {
print('Method $method called with params: $params');
try {
final result = await handler(params);
print('Method $method completed with result: $result');
respond(result);
} catch (error) {
print('Error handling method $method: $error');
respond({
'error': {'message': error.toString()},
});
}
});
}