createVerificationFlow method

Future<Widget> createVerificationFlow({
  1. required BuildContext context,
  2. required String apiKey,
  3. required String kycLevel,
  4. String? firstName,
  5. String? lastName,
  6. String? uniqueId,
  7. String? phoneNumber,
  8. String? email,
  9. bool ageVerification = false,
  10. required bool showCompletionView,
  11. required VoidCallback completion,
  12. VoidCallback? onVerificationCompleted,
  13. VoidCallback? onVerificationCancelled,
  14. dynamic onVerificationError(
    1. String
    )?,
})

Creates a verification flow widget that can be presented in your app

Implementation

Future<Widget> createVerificationFlow({
  required BuildContext context,
  required String apiKey,
  required String kycLevel,
  String? firstName,
  String? lastName,
  String? uniqueId,
  String? phoneNumber,
  String? email,
  bool ageVerification = false,
  required bool showCompletionView,
  required VoidCallback completion,
  VoidCallback? onVerificationCompleted,
  VoidCallback? onVerificationCancelled,
  Function(String)? onVerificationError,
}) async {
  // Handle age verification flow
  if (ageVerification) {
    // Set the API key for age verification
    ApiClient.shared.apiKey = apiKey;

    // Create a provider container for age verification
    _container = ProviderContainer(
      overrides: [
        navigationContextProvider.overrideWithValue(context),
      ],
    );

    return UncontrolledProviderScope(
      container: _container!,
      child: Theme(
        data: Theme.of(context).copyWith(
          scaffoldBackgroundColor: Colors.white,
          appBarTheme: const AppBarTheme(
            backgroundColor: Colors.white,
            foregroundColor: Colors.black,
            elevation: 0,
            surfaceTintColor: Colors.transparent,
            shadowColor: Colors.transparent,
          ),
        ),
        child: AgeVerificationView(
          uniqueId: uniqueId ?? "",
          onCompletion: () {
            onVerificationCompleted?.call();
            completion();
          },
        ),
      ),
    );
  }

  // Handle regular verification flow
  // Extract theme data before async operations
  final themeData = Theme.of(context).copyWith(
    scaffoldBackgroundColor: Colors.white,
    appBarTheme: const AppBarTheme(
      backgroundColor: Colors.white,
      foregroundColor: Colors.black,
      elevation: 0,
      surfaceTintColor: Colors.transparent,
      shadowColor: Colors.transparent,
    ),
  );

  // Create a provider container with the navigation context
  _container = ProviderContainer(
    overrides: [
      navigationContextProvider.overrideWithValue(context),
    ],
  );

  try {
    // Use the new combined method to initialize and establish session
    await _container!.read(verificationStateProvider.notifier).initializeAndEstablishSession(
      apiKey: apiKey,
      kycLevel: kycLevel,
      firstName: firstName,
      lastName: lastName,
      uniqueId: uniqueId,
      phoneNumber: phoneNumber,
      email: email,
      showCompletionView: showCompletionView,
      completion: completion,
      onCompleted: onVerificationCompleted,
      onCancelled: onVerificationCancelled,
      onError: onVerificationError,
      context: context,
    );
  } catch (error) {
    _container!.read(verificationStateProvider.notifier).reportError(
      error.toString(),
    );
  }

  return UncontrolledProviderScope(
    container: _container!,
    child: Theme(
      data: themeData,
      child: const VerificationFlowView(),
    ),
  );
}