identify_africa_sdk 0.1.0
identify_africa_sdk: ^0.1.0 copied to clipboard
Flutter SDK for Identify Africa's KYC and identity verification services
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:identify_africa_sdk/identify_africa_sdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Identify Africa SDK Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Identify Africa SDK Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final _formKey = GlobalKey<FormState>();
final _idController = TextEditingController();
bool _isLoading = false;
String _result = '';
// Initialize the SDK
final _identifyAfrica = IdentifyAfrica(
username: 'YOUR_API_USERNAME',
apiSecret: 'YOUR_API_SECRET',
baseUrl: 'https://partner.identifyafrica.io',
);
Future<void> _verifyId() async {
if (!_formKey.currentState!.validate()) {
return;
}
setState(() {
_isLoading = true;
_result = '';
});
try {
final response = await _identifyAfrica.idVerification.verifyNationalId(
_idController.text,
);
setState(() {
if (response.success) {
final data = response.data;
_result = 'Verification successful!\n\n'
'First Name: ${data?.firstName}\n'
'Last Name: ${data?.lastName}\n'
'Other Name: ${data?.otherName}\n'
'Full Name: ${data?.name}\n'
'Gender: ${data?.gender}\n'
'Date of Birth: ${data?.dob}\n'
'Citizenship: ${data?.citizenship}\n'
'ID Number: ${data?.idNumber}\n'
'Serial Number: ${data?.serialNo}\n'
'Valid: ${data?.valid}';
} else {
_result = 'Verification failed: ${response.message}';
}
});
} catch (e) {
setState(() {
_result = 'Error: $e';
});
} finally {
setState(() {
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextFormField(
controller: _idController,
decoration: const InputDecoration(
labelText: 'National ID Number',
hintText: 'Enter ID number to verify',
),
keyboardType: TextInputType.number,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter an ID number';
}
if (!RegExp(r'^[0-9]+$').hasMatch(value)) {
return 'ID number should contain only digits';
}
return null;
},
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _isLoading ? null : _verifyId,
child: _isLoading
? const CircularProgressIndicator(color: Colors.white)
: const Text('Verify National ID'),
),
const SizedBox(height: 20),
if (_result.isNotEmpty)
Expanded(
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(8),
),
child: SingleChildScrollView(
child: Text(_result),
),
),
),
],
),
),
),
);
}
}