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;

  if (!isSwitchingAtsign || (atsign ?? '').trim().isNotEmpty) {
    if ((atsign ?? '').trim().isNotEmpty) {
      await changePrimaryAtsign(atsign: atsign!);
    }
    //Check if existing an atsign => return onboard success
    final result = await showDialog(
      context: context,
      barrierDismissible: false,
      builder: (_) => AtOnboardingStartScreen(config: config),
    );
    if (result is AtOnboardingResult) {
      return result;
    } else {
      return AtOnboardingResult.cancelled();
    }
  } else {
    //Navigate user to screen to add new atsign
    final result = await Navigator.push(context,
        MaterialPageRoute(builder: (BuildContext context) {
      return AtOnboardingHomeScreen(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;
    } else {
      return AtOnboardingResult.cancelled();
    }
  }
}