d-markey / squadron_builder

Dart code generator for Squadron workers. Implement your worker service and let squadron_builder bridge the gap with Web Workers and Isolates!
https://pub.dev/packages/squadron_builder
MIT License
15 stars 3 forks source link

The argument type 'ByteBuffer Function(dynamic)' can't be assigned to the parameter type 'ByteData Function(dynamic)? #21

Closed sabin26 closed 1 week ago

sabin26 commented 1 week ago

Code:

@SquadronMethod()
  FutureOr<ByteBuffer?> toPDF(
    final List<int> bytes, {
    final String? title,
    final bool isLandscape = true,
    final List<String>? columns,
    final Map<int, double>? columnWidths,
    final ByteData? fontData,
    final Map<int, ByteData>? titleFonts,
    final Map<int, ByteData>? dataFonts,
  }) async {
   ...
}

Then I did the following:

  1. dart run build_runner clean
  2. dart run build_runner build

The build_runner step completes successfully but I get an error on compilation (when launching the app)

Error

lib/dependencies/export/export_service.worker.g.dart(113,71): error GC2F972A8: The argument type 'ByteBuffer Function(dynamic)' can't be assigned to the parameter type 'ByteData Function(dynamic)?'

Generated Code:

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'export_service.dart';

// **************************************************************************
// Generator: WorkerGenerator 6.0.7
// **************************************************************************

/// WorkerService class for ExportService
class _$ExportServiceWorkerService extends ExportService
    implements WorkerService {
  _$ExportServiceWorkerService() : super();

  @override
  late final Map<int, CommandHandler> operations =
      Map.unmodifiable(<int, CommandHandler>{
    _$toCSVId: ($) => toCSV(_$X.$1($.args[0])),
    _$toExcelId: ($) => toExcel(_$X.$1($.args[0])),
    _$toPDFId: ($) => toPDF(_$X.$1($.args[0]),
        title: _$X.$3($.args[1]),
        isLandscape: _$X.$4($.args[2]),
        columns: _$X.$6($.args[3]),
        columnWidths: _$X.$9($.args[4]),
        fontData: _$X.$11($.args[5]),
        titleFonts: _$X.$13($.args[6]),
        dataFonts: _$X.$13($.args[7])),
  });

  static const int _$toCSVId = 1;
  static const int _$toExcelId = 2;
  static const int _$toPDFId = 3;
}

/// Service initializer for ExportService
WorkerService $ExportServiceInitializer(WorkerRequest $$) =>
    _$ExportServiceWorkerService();

/// Worker for ExportService
base class ExportServiceWorker extends Worker implements ExportService {
  ExportServiceWorker(
      {PlatformThreadHook? threadHook, ExceptionManager? exceptionManager})
      : super($ExportServiceActivator(Squadron.platformType));

  ExportServiceWorker.vm(
      {PlatformThreadHook? threadHook, ExceptionManager? exceptionManager})
      : super($ExportServiceActivator(SquadronPlatformType.vm));

  ExportServiceWorker.js(
      {PlatformThreadHook? threadHook, ExceptionManager? exceptionManager})
      : super($ExportServiceActivator(SquadronPlatformType.js),
            threadHook: threadHook, exceptionManager: exceptionManager);

  ExportServiceWorker.wasm(
      {PlatformThreadHook? threadHook, ExceptionManager? exceptionManager})
      : super($ExportServiceActivator(SquadronPlatformType.wasm));

  @override
  Future<ByteBuffer?> toCSV(List<int> bytes) =>
      send(_$ExportServiceWorkerService._$toCSVId, args: [_$X.$14(bytes)])
          .then(_$X.$16);

  @override
  Future<ByteBuffer?> toExcel(List<int> bytes) =>
      send(_$ExportServiceWorkerService._$toExcelId, args: [_$X.$14(bytes)])
          .then(_$X.$16);

  @override
  Future<ByteBuffer?> toPDF(List<int> bytes,
          {String? title,
          bool isLandscape = true,
          List<String>? columns,
          Map<int, double>? columnWidths,
          ByteData? fontData,
          Map<int, ByteData>? titleFonts,
          Map<int, ByteData>? dataFonts}) =>
      send(_$ExportServiceWorkerService._$toPDFId, args: [
        _$X.$14(bytes),
        title,
        isLandscape,
        _$X.$17(columns),
        _$X.$19(columnWidths),
        _$X.$21(fontData),
        _$X.$23(titleFonts),
        _$X.$23(dataFonts)
      ]).then(_$X.$16);
}

sealed class _$X {
  static final $0 = Squadron.converter.value<int>();
  static final $1 = Squadron.converter.list<int>(_$X.$0);
  static final $2 = Squadron.converter.value<String>();
  static final $3 = Squadron.converter.nullable($2);
  static final $4 = Squadron.converter.value<bool>();
  static final $5 = Squadron.converter.list<String>(_$X.$2);
  static final $6 = Squadron.converter.nullable($5);
  static final $7 = Squadron.converter.value<double>();
  static final $8 =
      Squadron.converter.map<int, double>(kcast: _$X.$0, vcast: _$X.$7);
  static final $9 = Squadron.converter.nullable($8);
  static final $10 = Squadron.converter.typedData<ByteData>();
  static final $11 = Squadron.converter.nullable($10);
  static final $12 =
      Squadron.converter.map<int, ByteData>(kcast: _$X.$0, vcast: _$X.$10);
  static final $13 = Squadron.converter.nullable($12);
  static final $14 = Squadron.converter.list();
  static final $15 = Squadron.converter.value<ByteBuffer>();
  static final $16 = Squadron.converter.nullable($15);
  static final $17 = Squadron.converter.nullable($14);
  static final $18 = Squadron.converter.map<int, double>();
  static final $19 = Squadron.converter.nullable($18);
  static final $20 = (($) => ($ as ByteData).buffer);
  static final $21 = Squadron.converter.nullable($20);
  static final $22 = Squadron.converter.map<int, ByteData>(vcast: _$X.$20);
  static final $23 = Squadron.converter.nullable($22);
}

Versions: squadron: ^6.0.4 squadron_builder: ^6.0.8

d-markey commented 1 week ago

This one was a bug :-) fixed with squadron 6.1 + squadron_builder 6.1.