register static method
Future<void>
register({
- required SDKEnvironment environment,
- bool autoFetch = false,
- String? baseURL,
- String? accessToken,
Register model assignment callbacks with C++
autoFetch Whether to auto-fetch models after registration.
Should be false for development mode, true for staging/production.
Implementation
static Future<void> register({
required SDKEnvironment environment,
bool autoFetch = false,
String? baseURL,
String? accessToken,
}) async {
if (_isRegistered) return;
_environment = environment;
_baseURL = baseURL;
_accessToken = accessToken;
try {
final lib = PlatformLoader.loadCommons();
// Allocate callbacks struct
_callbacksPtr = calloc<RacAssignmentCallbacksStruct>();
_callbacksPtr!.ref.httpGet =
Pointer.fromFunction<RacAssignmentHttpGetCallbackNative>(
_httpGetCallback, _exceptionalReturnInt32);
_callbacksPtr!.ref.userData = nullptr;
// Only auto-fetch in staging/production, not development
_callbacksPtr!.ref.autoFetch = autoFetch ? 1 : 0;
// Register with C++
final setCallbacks = lib.lookupFunction<
Int32 Function(Pointer<RacAssignmentCallbacksStruct>),
int Function(Pointer<RacAssignmentCallbacksStruct>)>(
'rac_model_assignment_set_callbacks');
final result = setCallbacks(_callbacksPtr!);
if (result != RacResultCode.success) {
_logger.warning('Failed to register assignment callbacks',
metadata: {'code': result});
calloc.free(_callbacksPtr!);
_callbacksPtr = null;
return;
}
_isRegistered = true;
_logger.debug(
'Model assignment callbacks registered (autoFetch: $autoFetch)');
} catch (e) {
_logger.debug('Model assignment registration error: $e');
_isRegistered = true; // Avoid retry loops
}
}