Examples
Basic implementation
import 'package:flutter/material.dart';
import 'package:azakaw_kyc_flutter/azakaw_kyc_flutter.dart';
class HomePage extends StatelessWidget {
const HomePage({super.key});
Future<void> _startKyc(BuildContext context) async {
final result = await AzakawKyc.start(
context: context,
config: AzakawKycConfig(
sessionId: 'your-session-id',
region: AzakawRegion.uae,
environment: AzakawEnvironment.sandbox,
),
);
debugPrint('KYC ${result.status.name}');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('KYC Example')),
body: Center(
child: ElevatedButton(
onPressed: () => _startKyc(context),
child: const Text('Start KYC'),
),
),
);
}
}
Complete integration
Creating the session server-side, then running the flow and acting on the outcome.
import 'dart:convert';
import 'package:azakaw_kyc_flutter/azakaw_kyc_flutter.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class KycPage extends StatefulWidget {
const KycPage({super.key});
@override
State<KycPage> createState() => _KycPageState();
}
class _KycPageState extends State<KycPage> {
bool _isLoading = false;
/// Ask *your* backend for a session id. Never ship the app id/secret in
/// the app — the exchange belongs on your server.
///
/// Returns null on any failure: a network error, a timeout and a malformed
/// body all mean the same thing to the caller.
Future<String?> _fetchSessionId() async {
try {
final response = await http
.post(
Uri.parse('https://your-backend.example.com/azakaw/session'),
headers: {'Content-Type': 'application/json'},
)
.timeout(const Duration(seconds: 15));
if (response.statusCode != 200) return null;
return (jsonDecode(response.body) as Map<String, dynamic>)['sessionId']
as String?;
} catch (error) {
debugPrint('Could not create a session: $error');
return null;
}
}
Future<void> _startKyc() async {
setState(() => _isLoading = true);
final String? sessionId;
try {
sessionId = await _fetchSessionId();
} finally {
if (mounted) setState(() => _isLoading = false);
}
if (!mounted) return;
if (sessionId == null) {
_notify('Could not start verification. Please try again.');
return;
}
final result = await AzakawKyc.start(
context: context,
config: AzakawKycConfig(
sessionId: sessionId,
region: AzakawRegion.uae,
environment: AzakawEnvironment.production,
hideSidebar: true,
hideOnboardingSections: true,
),
onError: (error) => debugPrint('Azakaw error: $error'),
);
if (!mounted) return;
switch (result.status) {
case AzakawKycStatus.completed:
// Confirm server-side before treating the user as verified.
await _confirmWithBackend(result.sessionId);
// The earlier `mounted` check does not survive this await.
if (!mounted) return;
_notify('Verification submitted.');
case AzakawKycStatus.cancelled:
_notify('Verification cancelled.');
case AzakawKycStatus.failed:
_notify('Verification unavailable: ${result.error?.message}');
}
}
Future<void> _confirmWithBackend(String sessionId) async {
// Your backend checks the session's real state against the Azakaw API.
}
void _notify(String message) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(message)));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('KYC Integration')),
body: Center(
child: _isLoading
? const CircularProgressIndicator()
: ElevatedButton(
onPressed: _startKyc,
child: const Text('Start KYC'),
),
),
);
}
}
Switching region and environment
// UAE sandbox.
AzakawKycConfig(
sessionId: sessionId,
region: AzakawRegion.uae,
environment: AzakawEnvironment.sandbox,
);
// Kuwait sandbox — note the hosts are kuwait-stg*, not sandbox*.
AzakawKycConfig(
sessionId: sessionId,
region: AzakawRegion.kuwait,
environment: AzakawEnvironment.sandbox,
);
// KSA production (KSA has no sandbox).
AzakawKycConfig(
sessionId: sessionId,
region: AzakawRegion.ksa,
environment: AzakawEnvironment.production,
);
// Qatar production, in Arabic.
AzakawKycConfig(
sessionId: sessionId,
region: AzakawRegion.qatar,
environment: AzakawEnvironment.production,
language: AzakawLanguage.ar,
);
Check a pairing before relying on it:
AzakawRegion.kuwait.hasSandbox; // true
AzakawRegion.ksa.subdomainFor(AzakawEnvironment.sandbox); // null
config.isUnavailableCombination; // same check
Runnable example app
The package ships an example/ app with a session-id field, region and
environment pickers, the layout and language toggles, and a live view of the
resolved hosts.
cd example
flutter pub get
flutter run
Run it on a physical device — camera capture does not work in a simulator.
For more specific use cases or customization options, please contact our support team.