WorkerCallbackGenerator class

Generates type-safe worker IDs and a registry map from @WorkerCallback annotations.

For a source file lib/workers.dart:

part 'workers.g.dart';

@WorkerCallback('sync_contacts')
Future<bool> syncContacts(Map<String, dynamic>? input) async => true;

@WorkerCallback('backup_photos')
Future<bool> backupPhotos(Map<String, dynamic>? input) async => true;

Generates lib/workers.g.dart:

// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'workers.dart';

abstract final class WorkerIds {
  static const String syncContacts = 'sync_contacts';
  static const String backupPhotos = 'backup_photos';
}

final Map<String, DartWorkerCallback> generatedWorkerRegistry = {
  'sync_contacts': syncContacts,
  'backup_photos': backupPhotos,
};

Constructors

WorkerCallbackGenerator()
Creates a WorkerCallbackGenerator.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

generate(LibraryReader library, BuildStep buildStep) → Future<String>
Generates Dart code for an input Dart library.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited