bootstrap method

Future<void> bootstrap()

Implementation

Future<void> bootstrap() async {
  state = state.copyWith(
    isLoading: true,
    clearError: true,
    statusMessage: 'Starting...',
  );

  final activationKey = EzyLiteRuntimeConfig.activationKey;
  final employeePin = EzyLiteRuntimeConfig.employeePin;
  final trolleyNo = EzyLiteRuntimeConfig.trolleyNo;

  final shouldActivate =
      !_repo.isDeviceActivated() || EzyLiteSession.isPluginMode;

  if (shouldActivate) {
    state = state.copyWith(statusMessage: 'Activating device...');
    final activation = await _repo.activateDevice(activationKey, trolleyNo);
    switch (activation) {
      case NetworkSuccess():
        break;
      case NetworkError():
        state = state.copyWith(
          isLoading: false,
          error: activation.message,
          statusMessage: 'Activation failed',
        );
        return;
    }
  }

  state = state.copyWith(statusMessage: 'Signing in...');
  final login = await _repo.login(employeePin);
  switch (login) {
    case NetworkSuccess():
      state = state.copyWith(
        isLoading: false,
        isSuccess: true,
        statusMessage: 'Ready',
      );
    case NetworkError():
      state = state.copyWith(
        isLoading: false,
        error: login.message,
        statusMessage: 'Login failed',
      );
  }
}