JavaClassUniCallback constructor

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

Implementation

JavaClassUniCallback(
    String methodName, String paramName, AstType paramGeneric,
    {int depth = 0, String channelSuffix = ''})
    : super(
          depth: depth,
          className: getName(methodName, paramName),
          privateFields: [
            Variable(AstCustomType('BinaryMessenger'), 'messenger'),
          ],
          publicFields: [
            Variable(AstString(), 'callbackName'),
          ],
          injectedJavaCodes: (depth) => [
                JavaFunction(
                    functionName: getName(methodName, paramName),
                    depth: depth,
                    isConstruct: true,
                    isPublic: true,
                    body: (depth) => [
                          OneLine(
                              depth: depth + 1,
                              body: 'this.messenger = messenger;'),
                          OneLine(
                              depth: depth + 1,
                              body: 'this.callbackName = callbackName;')
                        ],
                    params: [
                      Variable(AstCustomType('BinaryMessenger'), 'messenger'),
                      Variable(AstString(), 'callbackName')
                    ]),
                EmptyLine(),
                JavaFunction(
                    depth: depth,
                    functionName: 'onEvent',
                    isPublic: true,
                    params: [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()' : 'event'});'),
                          OneLine(
                              depth: depth + 1,
                              body:
                                  'new BasicMessageChannel<>(messenger, "$channelPrefix.UniCallbackManager.callback_channel$channelSuffix", StandardMessageCodec.INSTANCE).send(message);'), // fixme 这里 channel 有问题
                        ])
              ]) {
  registerCustomType(typeUniCallback);
}