@@ -63,10 +63,19 @@ class ObjCProtocolMethod<T extends Function> {
63
63
/// the wrong thread will result in a crash.
64
64
void implement (ObjCProtocolBuilder builder, T ? function) {
65
65
if (function != null ) {
66
- builder. implementMethod (_sel, _sig , _createBlock (function));
66
+ implementWithBlock (builder , _createBlock (function));
67
67
}
68
68
}
69
69
70
+ /// Implement this method on the protocol [builder] using an ObjC [block] .
71
+ ///
72
+ /// **IMPORTANT**: The [block] must have the same signature as the method,
73
+ /// but with an extra `void*` argument as the first parameter, before all the
74
+ /// method parameters. Most users should use one of the other `implement`
75
+ /// methods, which handles this signature change automatically.
76
+ void implementWithBlock (ObjCProtocolBuilder builder, ObjCBlockBase block) =>
77
+ builder.implementMethod (_sel, _sig, block);
78
+
70
79
bool get isAvailable => _signature != null ;
71
80
72
81
objc.NSMethodSignature get _sig {
@@ -100,7 +109,7 @@ class ObjCProtocolListenableMethod<T extends Function>
100
109
/// See NativeCallable.listener for more details.
101
110
void implementAsListener (ObjCProtocolBuilder builder, T ? function) {
102
111
if (function != null ) {
103
- builder. implementMethod (_sel, _sig , _createListenerBlock (function));
112
+ implementWithBlock (builder , _createListenerBlock (function));
104
113
}
105
114
}
106
115
@@ -112,7 +121,7 @@ class ObjCProtocolListenableMethod<T extends Function>
112
121
/// the method. Async functions are not supported.
113
122
void implementAsBlocking (ObjCProtocolBuilder builder, T ? function) {
114
123
if (function != null ) {
115
- builder. implementMethod (_sel, _sig , _createBlockingBlock (function));
124
+ implementWithBlock (builder , _createBlockingBlock (function));
116
125
}
117
126
}
118
127
}
0 commit comments