Skip to main content

Flutter Demo App

This example demonstrates a basic integration of attestid_sdk into a Flutter application.

It includes:

  • SDK initialization
  • Backend token retrieval
  • Verification flow
  • Result handling

Use this project as a reference alongside the Flutter SDK integration guide.


Requirements​

ToolMinimum version
Flutter3.22.0
Dart3.4.0
AndroidAPI 24 (Android 7.0)
flutter doctor

App code​

import 'dart:convert';
import 'package:attestid_sdk/attestid.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:http/http.dart' as http;

Future<void> main() async {
await dotenv.load(fileName: '.env');
await AttestIDApp.run(
apiUrl: dotenv.env['ATTESTID_API_URL'] ?? '',

getSdkToken: (userId) async {
final res = await http.post(
Uri.parse('${dotenv.env['MY_BACKEND_URL']}/attestid-session'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'userId': userId}),
);
return SdkSessionResponse.fromJson(jsonDecode(res.body) as Map<String, dynamic>);
},
sandbox: true,
);
}

AttestIDApp.run() initializes the SDK and displays the default verification interface.

Applications that require custom navigation or UI can integrate the lower-level widgets described in the Flutter SDK guide.​

Example backend implementation​

The following example demonstrates a minimal Node.js implementation that exchanges API credentials for an SDK token.

Use the same authentication flow in your production backend.

// server/attestid-session-proxy.js
const fs = require('fs');
const http = require('http');
const https = require('https');
const { URL } = require('url');

const ATTESTID_API_URL = process.env.ATTESTID_API_URL || 'https://api.attestid.brimsage.co.ls';
const ATTESTID_API_KEY = process.env.ATTESTID_API_KEY || '';
const ATTESTID_ACCESS_KEY_ID = process.env.ATTESTID_ACCESS_KEY_ID || '';
// Client certificate issued in the dashboard (Client Certificates). AttestID
// rejects every API-key request without one (mutual TLS).
const CLIENT_CERT_FILE = process.env.ATTESTID_CLIENT_CERT_FILE || './client.crt';
const CLIENT_KEY_FILE = process.env.ATTESTID_CLIENT_KEY_FILE || './client.key';
const PORT = Number(process.env.PORT || 8080);

const server = http.createServer((req, res) => {
if (req.method !== 'POST' || req.url !== '/attestid-session') {
res.writeHead(404).end('Not found');
return;
}

let body = '';
req.on('data', (chunk) => { body += chunk; });
req.on('end', () => {
const { userId } = JSON.parse(body || '{}');
const target = new URL('/v1/kyc/session', ATTESTID_API_URL);
const client = target.protocol === 'https:' ? https : http;
const payload = JSON.stringify({ user_id: userId });

const upstream = client.request(
target,
{
method: 'POST',
cert: fs.readFileSync(CLIENT_CERT_FILE),
key: fs.readFileSync(CLIENT_KEY_FILE),
headers: {
'X-API-Key': ATTESTID_API_KEY,
'X-Access-Key-Id': ATTESTID_ACCESS_KEY_ID,
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(payload),
},
},
(upstreamRes) => {
res.writeHead(upstreamRes.statusCode, { 'Content-Type': 'application/json' });
upstreamRes.pipe(res);
},
);
upstream.write(payload);
upstream.end();
});
});

server.listen(PORT, () => console.log(`listening on http://localhost:${PORT}`));

Environment variables​

Flutter application​

ATTESTID_API_URL=https://api.attestid.brimsage.co.ls
MY_BACKEND_URL=http://localhost:8080

Backend​

ATTESTID_API_URL=https://api.attestid.brimsage.co.ls
ATTESTID_ACCESS_KEY_ID=ak_live_your_access_key_id_here
ATTESTID_API_KEY=sk_live_your_key_here
ATTESTID_CLIENT_CERT_FILE=./client.crt
ATTESTID_CLIENT_KEY_FILE=./client.key

Get these credentials by registering your company first: see Creating a Company & Getting Your Keys.


Running​

Running on Android​

A physical Android device is recommended when testing document capture and face liveness.

adb reverse tcp:8080 tcp:8080
flutter run

adb reverse maps localhost:8080 on the device to your development machine, so MY_BACKEND_URL=http://localhost:8080 in .env works without any IP changes. If you skip the port forward, use your machine's LAN IP instead (e.g. http://192.168.1.x:8080).

Android emulator​

flutter emulators
flutter emulators --launch <emulator_id>
flutter run # use http://10.0.2.2:8080 for your local backend, not localhost

Configure the emulator to use a physical webcam for the front camera and back camera.

Document capture works with the default camera configuration. Face liveness requires a live camera feed.

iOS Simulator​

open -a Simulator
flutter run -d ios

The iOS Simulator does not support the camerause a physical iPhone for camera and liveness testing.

Chrome (web)​

flutter run -d chrome

Building for production​

flutter build apk --release # Android APK
flutter build appbundle --release # Android App Bundle (Play Store)
flutter build ios --release # iOS (requires macOS + Xcode)
flutter build web # Web

Integration checklist​

  • SDK initializes successfully.
  • SDK token retrieval completes successfully.
  • Document capture completes.
  • Face liveness completes.
  • Verification results are returned.
  • Backend implements /attestid-session.