launch static method

Future<void> launch(
  1. BuildContext context, {
  2. String? token,
  3. required String mobileNumber,
  4. ThemeData? theme,
  5. String? redirectUrl,
  6. String? otpRef,
  7. String? reqId,
  8. String? sharesReqId,
  9. List<SdkJourney>? allowedJourneys,
  10. String environment = 'prod',
})

Launch the LAMF SDK journey directly. The context is the BuildContext from the host application.

Implementation

static Future<void> launch(
  BuildContext context, {
  String? token,
  required String mobileNumber,
  ThemeData? theme,
  String? redirectUrl,
  String? otpRef,
  String? reqId,
  String? sharesReqId,
  List<SdkJourney>? allowedJourneys,
  String environment = 'prod', // Default to prod
}) async {
  // 1. Initialize environment and preferences if not done yet
  if (!_isInitialized) {
    WidgetsFlutterBinding.ensureInitialized();
    // Override the compile-time flavor with the explicit environment
    switch (environment.toLowerCase()) {
      case 'local':
        FlavorConfig.flavor = Flavor.local;
        FlavorConfig.baseUrl = 'http://localhost:4000/';
        FlavorConfig.redirectUrl = redirectUrl ?? 'http://localhost:62917';
        FlavorConfig.socketUrl = 'wss://socket-dev.valuenable.in';
        break;
      case 'dev':
        FlavorConfig.flavor = Flavor.dev;
        FlavorConfig.baseUrl = 'https://api-dev.valuenable.in/lamf/';
        FlavorConfig.redirectUrl =
            redirectUrl ?? 'https://dev-las.sliqfin.com';
        FlavorConfig.socketUrl = 'wss://socket-dev.valuenable.in';
        break;
      case 'uat':
        FlavorConfig.flavor = Flavor.uat;
        FlavorConfig.baseUrl = 'https://api-uat.valuenable.in/lamf/';
        FlavorConfig.redirectUrl =
            redirectUrl ?? 'https://uat-las.sliqfin.com';
        FlavorConfig.socketUrl = 'wss://socket-uat.valuenable.in';
        break;
      default:
        FlavorConfig.flavor = Flavor.prod;
        FlavorConfig.baseUrl = 'https://api.valuenable.in/lamf/';
        FlavorConfig.redirectUrl = redirectUrl ?? 'https://las.sliqfin.com';
        FlavorConfig.socketUrl = 'wss://socket-prod.valuenable.in';
        break;
    }

    await Pref.initPreference();
    await initDependencies();
    _isInitialized = true;
  }

  // 2. Persist the auth token and mobile number internally for SDK's API calls
  if (token != null && token.isNotEmpty) {
    await Pref.setValue(KV.token, token);
    await Pref.setValue(KV.isLogin, true);
  } else {
    await Pref.setValue(KV.isLogin, false);
    await Pref.setValue(KV.isWalkthrough, false); // Bypass welcome screen
  }
  await Pref.preference.setString("mobile_number", mobileNumber);
  await Pref.setValue(KV.isSdk, true);

  if (otpRef != null) {
    await Pref.preference.setString("sdk_otp_ref", otpRef);
  } else {
    await Pref.preference.remove("sdk_otp_ref");
  }

  if (reqId != null && reqId.isNotEmpty) {
    await Pref.setValue(KV.reqId, reqId);
    if (GetIt.I.isRegistered<AppStateProvider>()) {
      GetIt.I<AppStateProvider>().setReqId(reqId);
    }
  } else {
    await Pref.preference.remove(KV.reqId.name);
    if (GetIt.I.isRegistered<AppStateProvider>()) {
      GetIt.I<AppStateProvider>().setReqId('');
    }
  }

  if (sharesReqId != null && sharesReqId.isNotEmpty) {
    await Pref.setValue(KV.sharesReqId, sharesReqId);
  } else {
    await Pref.preference.remove(KV.sharesReqId.name);
  }

  if (allowedJourneys != null && allowedJourneys.isNotEmpty) {
    await Pref.preference.setStringList(
      'sdk_allowed_journeys',
      allowedJourneys.map((e) => e.name).toList(),
    );
  } else {
    await Pref.preference.remove('sdk_allowed_journeys');
  }

  // 3. Launch the SDK App as a new route in the parent app
  if (context.mounted) {
    Navigator.of(
      context,
    ).push(MaterialPageRoute(builder: (_) => SliqApp(injectedTheme: theme)));
  }
}