onboard static method

Future<AtOnboardingResult> onboard({
  1. required BuildContext context,
  2. required AtOnboardingConfig config,
  3. bool isSwitchingAtsign = false,
  4. String? atsign,
})

Using this function to get onboard atsing.

@param context The build context. @param config The config for the onboard @param isSwitchingAtsign True - alway show UI for add new atsign. False - check onboard if existing atsing. Default is false @param atsign The atsign name when change the primary atsign.

Return AtOnboardingResult

Implementation

static Future<AtOnboardingResult> onboard({
  required BuildContext context,
  required AtOnboardingConfig config,
  bool isSwitchingAtsign = false,
  String? atsign,
}) async {
  AtOnboardingConstants.setApiKey(config.appAPIKey ??
      (AtOnboardingConstants.rootEnvironment.apikey ?? ''));
  AtOnboardingConstants.rootDomain =
      config.domain ?? AtOnboardingConstants.rootEnvironment.domain;

  /// Initial Setup
  await _initialSetup(context);

  /// user sharing is not supported on Android, iOS and Linux.
  if (Platform.isAndroid || Platform.isIOS || Platform.isLinux) {
    config.showPopupSharedStorage = false;
  }

  if (config.theme == null) {
    final defaultConfig = config.copyWith(
      theme: AtOnboardingTheme(),
    );
    config = defaultConfig;
  }

  if (!isSwitchingAtsign || (atsign ?? '').trim().isNotEmpty) {
    if ((atsign ?? '').trim().isNotEmpty) {
      await changePrimaryAtsign(atsign: atsign!);
    }

    //Check if existing an atsign => return onboard success
    // ignore: use_build_context_synchronously
    AtOnboardingResult? result;
    if (context.mounted) {
      result = await showDialog(
        context: context,
        barrierDismissible: false,
        builder: (_) => AtOnboardingStartScreen(
          config: config,
        ),
      );
    }

    if (result is AtOnboardingResult) {
      return result;
    }

    return AtOnboardingResult.cancelled();
  }

  if (context.mounted) {
    final result = await Navigator.push(
      context,
      MaterialPageRoute(
        builder: (BuildContext context) {
          return AtOnboardingIntroScreen(
            config: config,
          );
        },
      ),
    );

    if (result is AtOnboardingResult) {
      //Update primary atsign after onboard success
      if (result.status == AtOnboardingResultStatus.success &&
          result.atsign != null) {
        await changePrimaryAtsign(atsign: result.atsign!);
      }
      return result;
    }
  }

  return AtOnboardingResult.cancelled();
}