onInitialize method

  1. @override
bool onInitialize()
override

Called by initialize. Returns true if successfully initialized.

If false, the executor stays in ExecutorState.Created. This is a synchronous method and must be light-weight.

Implementation

@override
bool onInitialize() {
  super.onInitialize();
  if (beaconRegions.isEmpty) {
    warning('$runtimeType - No beacon regions specified for monitoring. Will not start monitoring.');
    return false;
  }

  try {
    info('$runtimeType - Initializing iBeacon scanning...');
    flutterBeacon.initializeScanning.then(
      (_) {
        info('$runtimeType - Initialized.');
        return true;
      },
      onError: (Object error) {
        warning('$runtimeType - Error while initializing scanner - $error');
        return false;
      },
    );
  } catch (error) {
    warning('$runtimeType - Error while initializing scanner - $error');
    return false;
  }
  return true;
}