JavaClassUniCallback constructor

JavaClassUniCallback(
  1. String methodName,
  2. String paramName,
  3. AstType paramGeneric, {
  4. int depth = 0,
  5. String javaUniAPIPrefix = '',
})

Implementation

JavaClassUniCallback(
    String methodName, String paramName, AstType paramGeneric,
    {int depth = 0, String javaUniAPIPrefix = ''})
    : super(
          depth: depth,
          className: getName(methodName, paramName),
          privateFields: [
            Variable(AstCustomType('BinaryMessenger'), 'messenger'),
          ],
          parentClass: '${javaUniAPIPrefix}$typeUniCallback',
          injectedJavaCodes: (depth) => [
                JavaFunction(
                    functionName: getName(methodName, paramName),
                    depth: depth,
                    isConstruct: true,
                    isPublic: true,
                    body: (depth) => [
                          OneLine(
                              depth: depth + 1,
                              body: 'super(callbackName, disposeDelegate);'),
                          OneLine(
                              depth: depth + 1,
                              body: 'this.messenger = messenger;')
                        ],
                    params: [
                      Variable(AstCustomType('BinaryMessenger'), 'messenger'),
                      Variable(AstString(), 'callbackName'),
                      Variable(
                          AstCustomType('${javaUniAPIPrefix}UniCallbackDispose'),
                          'disposeDelegate')
                    ]),
                EmptyLine(),
                JavaFunction(
                    depth: depth,
                    functionName: 'onEvent',
                    isPublic: true,
                    params: paramGeneric.realType() is AstVoid
                        ? const []
                        : [Variable(paramGeneric, 'event')],
                    body: (depth) => [
                          OneLine(
                              depth: depth + 1,
                              body:
                                  'Map<String, Object> message = new HashMap<>();'),
                          OneLine(
                              depth: depth + 1,
                              body:
                                  'message.put("callbackName", callbackName);'),
                          OneLine(
                              depth: depth + 1,
                              body:
                                  'message.put("data", ${paramGeneric is AstCustomType ? 'event.toMap()' : paramGeneric is AstVoid ? '""' : 'event'});'),
                          OneLine(
                              depth: depth + 1,
                              body:
                                  'new BasicMessageChannel<>(messenger, "$channelPrefix.UniCallbackManager.callback_channel${javaUniAPIPrefix.suffix()}", StandardMessageCodec.INSTANCE).send(message);'), // fixme 这里 channel 有问题
                        ])
              ]) {
  registerCustomType(typeUniCallback);
}