get_verified 0.0.4
get_verified: ^0.0.4 copied to clipboard
This package will have the solution for destroying scalping
example/lib/main.dart
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:example/configuration_list.dart';
import 'package:example/doc.dart';
import 'package:example/firebase_options.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_verified/get_verified.dart';
import 'package:get_verified/manager/deep_link_manager.dart';
import 'package:get_verified/screen/get_verified/get_verified_upload_screen.dart';
import 'package:get_verified/screen/onboarding/onboarding_screen.dart';
import 'package:http/io_client.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
DeepLinkManager.instance.init();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
// Load Regula license
final license = await rootBundle.load('assets/regula.license');
// Get available SDK configurations
// Options: 'Standard', 'Minimal', 'Dark Mode (Brand)', 'Custom Registration', 'Defaults (No Custom UI)'
final scenarios = ConfigurationList.getScenarios(license);
var selectedConfig = scenarios['Standard']!;
// Inject the reprocess callback into the config
selectedConfig = selectedConfig.copyWith(onReprocess: _handleReprocess);
// Initialize the SDK
final result = await GetVerified.instance.initialize(config: selectedConfig);
if (result.isFailure) {
debugPrint('SDK Initialization failed: ${result.error?.message}');
}
runApp(const MyApp());
}
/// Handles the reprocess API call with retry logic.
Future<bool> _handleReprocess(
String docTransactionId,
String? faceLivenessTransactionId,
) async {
final urlString = Urls.reprocessUrl.replaceAll(
'{doc_transaction_id}',
docTransactionId,
);
const maxRetries = 3;
for (int attempt = 1; attempt <= maxRetries; attempt++) {
try {
final uri = Uri.parse(urlString.trim());
final body = jsonEncode({
'faceLivenessTransactionId': faceLivenessTransactionId,
});
final httpClient = HttpClient();
final ioClient = IOClient(httpClient);
final response = await ioClient.post(
uri,
headers: {'Content-Type': 'application/json'},
body: body,
);
ioClient.close();
if (response.statusCode == 200) {
debugPrint('Reprocess success');
return true;
} else {
debugPrint('Reprocess failed with status: ${response.statusCode}');
return false;
}
} catch (e) {
debugPrint('Reprocess attempt $attempt failed: $e');
if (attempt < maxRetries) {
await Future.delayed(Duration(milliseconds: 500 * attempt));
}
}
}
return false;
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final GlobalKey<NavigatorState> _navigatorKey = GlobalKey<NavigatorState>();
StreamSubscription<DeepLinkAction>? _deepLinkSubscription;
@override
void initState() {
super.initState();
_setupDeepLinkListener();
}
void _setupDeepLinkListener() {
_deepLinkSubscription = DeepLinkManager.instance.actionStream.listen((action) {
if (action.type == DeepLinkType.verify) {
_navigatorKey.currentState?.pushAndRemoveUntil(
MaterialPageRoute(
builder: (context) => OnboardingScreen(onVerificationStart: () {}),
),
(route) => false,
);
}
});
}
@override
void dispose() {
_deepLinkSubscription?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: _navigatorKey,
title: 'Get Verified Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const ExampleHome(),
);
}
}
class ExampleHome extends StatelessWidget {
const ExampleHome({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Get Verified Example')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => _navigateToOnboarding(context),
child: const Text('Start Onboarding Flow'),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () => _navigateToUpload(context),
child: const Text('Upload Verification Image'),
),
],
),
),
);
}
void _navigateToOnboarding(BuildContext context) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => OnboardingScreen(onVerificationStart: () {}),
),
);
}
void _navigateToUpload(BuildContext context) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const GetVerifiedUploadScreen(),
),
);
}
}