createVerificationFlow method
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,
- dynamic onVerificationError()?,
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(),
),
);
}