faceping.aidocs

Get started with Flutter

Build a small Flutter app that enrols your face and verifies it offline, on your own phone.

What you'll build

A face check that works in airplane mode

An app that enrols your face, verifies it live with a head-turn liveness check, and still matches with no network.

About 10 minutesAndroid phone or iPhoneFree sandbox key
0 of 7 steps doneAbout 10 minutes
FaceCheck
Look at the cameraTap Enrol my face to start.

1

Get a sandbox key#

Sign up at app.faceping.ai/signup with your email, then open Developers → Sandbox keys → Create sandbox key. It starts with fp_test_. It also works on the API for your practice list, so keep test apps within your team, and revoke the key under Developers if it leaks.

The sandbox is free and instant: up to 25 faces per device, each deleted 24 hours after it was enrolled. No card, no approval.

2

Create the project#

You need Flutter 3.24 or later and a phone with a cable: an Android phone (Android 7 or later, 64-bit) with USB debugging on, or an iPhone (iOS 15.1 or later) and a Mac with Xcode 26 or later.

flutter create --org com.example --platforms android,ios facecheck
cd facecheck
First Flutter app on this machine?

The 10 minutes assume Flutter already builds apps for your phone. If it doesn't, install Flutter for Android or iOS and run flutter doctor until it's happy (the Android SDK and Xcode take a while to download). For an iPhone, sign in to Xcode with your Apple ID (Xcode → Settings → Apple Accounts).

3

Add FacePing#

One package from pub.dev. It brings the face models, liveness checks and a camera widget with it. FacePing for Flutter is in preview, so ask for the version by name:

flutter pub add faceping:1.0.0-preview.6

On Android, FacePing needs Android 7 (API 24) or later, on a 64-bit phone. Current Flutter already uses API 24 as its minimum (minSdk = flutter.minSdkVersion in android/app/build.gradle.kts); if your project sets a lower number there, change it to 24. See pub.dev for the latest version.

The first build downloads Microsoft's ONNX Runtime and the face models. FacePing adds about 32 MB to your app per ABI: about 48 MB for an arm64 release APK of this app, against about 16 MB for an empty one. FacePing's native core is built for arm64-v8a (phones) and x86_64 (emulators), so build releases for just those:

flutter build apk --release --split-per-abi --target-platform android-arm64,android-x64   # one APK per ABI
flutter build appbundle --release                                                         # for Google Play

4

Allow the camera#

iOS asks the person before the camera turns on, and shows them your reason. Add it to ios/Runner/Info.plist, inside the <dict>:

ios/Runner/Info.plist
<key>NSCameraUsageDescription</key>
<string>FaceCheck uses the camera to verify your face.</string>

Without it, iOS stops the app the moment the camera starts. While you're in Info.plist, change CFBundleDisplayName from Facecheck to FaceCheck, the name under the app's icon. FacePing also needs iOS 15.1 or later: open ios/Runner.xcworkspace in Xcode, select the Runner project and set Minimum Deployments to 15.1.

Android: the FacePing library declares the camera permission (and INTERNET, to activate your key), and the camera widget asks the person the first time it appears. Do keep FacePing's data out of backups: FacePing encrypts its face data with a key kept in the Android Keystore, which backups don't include, so a backed-up copy could never be read on another phone (and face data shouldn't leave the device anyway). In android/app/src/main/AndroidManifest.xml, add three attributes to <application>:

android/app/src/main/AndroidManifest.xml
<application
    android:label="FaceCheck"
    android:allowBackup="false"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    ...>

allowBackup covers cloud backup; from Android 12, moving to a new phone needs the rules file too. Create it, in a new res/xml folder:

android/app/src/main/res/xml/data_extraction_rules.xml
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
    <cloud-backup>
        <exclude domain="file" path="faceping/" />
        <exclude domain="sharedpref" path="faceping.keys.xml" />
    </cloud-backup>
    <device-transfer>
        <exclude domain="file" path="faceping/" />
        <exclude domain="sharedpref" path="faceping.keys.xml" />
    </device-transfer>
</data-extraction-rules>

And the same two lines for Android 11 and earlier, so the rules hold even if backup is turned back on later:

android/app/src/main/res/xml/backup_rules.xml
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <exclude domain="file" path="faceping/" />
    <exclude domain="sharedpref" path="faceping.keys.xml" />
</full-backup-content>

5

Turn FacePing on#

Set FacePing up once, when the app starts, with your sandbox key. Replace lib/main.dart with this, and delete test/widget_test.dart (it tests the template's counter app, which is gone):

lib/main.dart
import 'package:faceping/faceping.dart';
import 'package:flutter/material.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  try {
    // Starts loading the face models in the background, so the first check is quick.
    await FacePing.init(sandboxKey: 'fp_test_…');
  } on FacePingException catch (e) {
    // A missing or malformed key: the screen says so instead of the app stopping.
    debugPrint('FacePing setup: ${e.message}');
  }
  runApp(const MaterialApp(title: 'FaceCheck', home: CheckScreen()));
}

To keep the key out of your code, read it with const String.fromEnvironment('FACEPING_SANDBOX_KEY') and pass --dart-define=FACEPING_SANDBOX_KEY=fp_test_... to flutter run, as the starter app does.

6

Add the screen#

A camera and two buttons: one enrols your face on the phone, the other verifies it. Add this to the end of lib/main.dart.

lib/main.dart
class CheckScreen extends StatefulWidget {
  const CheckScreen({super.key});

  @override
  State<CheckScreen> createState() => _CheckScreenState();
}

class _CheckScreenState extends State<CheckScreen> {
  final camera = FacePingCameraController();
  String status = '';

  Future<void> enroll() => act(() async {
        final photo = await camera.capture();
        final result = await FacePing.current.enroll('me', photo);
        show(result.isEnrolled ? 'Enrolled. Now tap Verify.' : 'Try again: ${result.outcome.name}');
      });

  Future<void> verify() => act(() async {
        // A live check: matches your face, then asks you to turn your head (liveness).
        final result = await FacePing.current.verifyLive('me', camera);
        final time = (result.elapsed.inMilliseconds / 1000).toStringAsFixed(2);
        show(result.isMatch ? 'Match · $time s' : 'Try again: ${result.outcome.name}');
      });

  Future<void> act(Future<void> Function() action) async {
    try {
      await action();
    } on FacePingException catch (e) {
      // For example no connection on the very first run (the sandbox key is activated once), or no camera.
      show(e.message);
    } on StateError {
      // FacePing.init failed in main(), for example a mistyped key.
      show("FacePing isn't set up: check the sandbox key in main().");
    }
  }

  void show(String text) {
    if (mounted) setState(() => status = text);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: ListView(
          padding: const EdgeInsets.all(24),
          children: [
            SizedBox(height: 420, child: FaceCamera(controller: camera, onCameraFailed: show)),
            const SizedBox(height: 16),
            OutlinedButton(onPressed: enroll, child: const Text('Enrol my face')),
            const SizedBox(height: 8),
            FilledButton(onPressed: verify, child: const Text('Verify')),
            const SizedBox(height: 16),
            Text(status, textAlign: TextAlign.center, style: const TextStyle(fontSize: 18)),
          ],
        ),
      ),
    );
  }
}

7

Run it on your phone#

Plug your phone in and run:

flutter run

A debug build is fine: the FacePing core inside the SDK is already compiled for speed, whichever build you run. On an iPhone, set your team first: in Xcode, select the Runner target, open Signing & Capabilities and pick your Team. The first time, turn on Developer Mode on the iPhone (Settings → Privacy & Security → Developer Mode). The first iOS build fetches the FacePing Swift package from GitHub.

The first run needs a connection, to activate your sandbox key. Tap Enrol my face, then Verify: you should see Match. Use a phone: the iOS simulator has no front camera, and an Android emulator only has one if you map your computer's webcam to it in the emulator's camera settings, which is slower and less reliable for the liveness check.

Now switch on airplane mode and tap Verify again. Still a match: the check ran entirely on your phone.

You've built a face check that works offline#

Next, make it real: verify the people in your app (members, visitors or people with tickets), and apply to go live when you're ready.

Try a check-in device on your practice list#

This is the ticketing flow, end to end, in the sandbox: a person enrols through your server or an enrolment link, and a check-in device verifies them offline.

  1. Create your practice list, if your account doesn't have one: New list in the dashboard asks for everything it needs, or use quickstart steps 1 and 2 (create the list, then set its widget details: enrolment links need them). Then enrol someone on it with your sandbox key: open an enrolment link (quickstart step 3; links last 30 minutes unless you pass validForHours), or enrol a selfie from your server with the copy-paste request in Enrol someone from your server. Note their personId, for example ACME-000123 (if your team shares the practice list, pick your own).
  2. Add a check-in device: the list's Devices tab in the dashboard, or POST /v1/lists/{listId}/devices. Copy the fpd_ device token: it's shown once.
  3. Check the token works before you build: curl https://api-eu.faceping.ai/v1/device -H "X-Device-Token: fpd_…" returns the list's name and peopleEnrolled. It doesn't download any faces or count as a sync.
  4. Make a device build that sits next to your sandbox app: copy the project folder, and give the copy its own Android applicationId (in android/app/build.gradle.kts) and iOS bundle identifier, for example com.yourcompany.facecheck.device, and its own name (android:label, and Display Name in Xcode), for example FaceCheck Device.
  5. Replace the copy's lib/main.dart. It sets FacePing up with a device token passed at build time (--dart-define=FACEPING_DEVICE_TOKEN=fpd_…, so it stays out of your code), verifies the person you enrolled, syncs when the screen opens and shows every later sync. People enrol on the server, not in the app (enroll throws FacePingInvalidOperationException on a device), so there's no enrol button:
lib/main.dart (device build)
import 'dart:async';

import 'package:faceping/faceping.dart';
import 'package:flutter/material.dart';

const deviceToken = String.fromEnvironment('FACEPING_DEVICE_TOKEN');
const personId = 'ACME-000123'; // the person you enrolled

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  try {
    await FacePing.init(deviceToken: deviceToken);
  } on FacePingException catch (e) {
    // No token passed, or a mistyped one: the screen says so instead of the app stopping.
    debugPrint('FacePing setup: ${e.message}');
  }
  runApp(const MaterialApp(title: 'FaceCheck Device', home: CheckScreen()));
}

class CheckScreen extends StatefulWidget {
  const CheckScreen({super.key});

  @override
  State<CheckScreen> createState() => _CheckScreenState();
}

class _CheckScreenState extends State<CheckScreen> {
  final camera = FacePingCameraController();
  StreamSubscription<SyncResult>? syncs;
  String status = '';

  @override
  void initState() {
    super.initState();
    // Sync now, then show every later sync (FacePing syncs again every few minutes).
    syncs = FacePing.currentOrNull?.synced.listen(showSync);
    act(() async => showSync(await FacePing.current.sync()));
  }

  @override
  void dispose() {
    syncs?.cancel();
    super.dispose();
  }

  void showSync(SyncResult r) => show('${r.enrolled} people synced (${r.status.name})');

  Future<void> verify() => act(() async {
        final result = await FacePing.current.verifyLive(personId, camera);
        final time = (result.elapsed.inMilliseconds / 1000).toStringAsFixed(2);
        show(switch (result.outcome) {
          VerifyOutcome.match => 'Match · $time s',
          VerifyOutcome.notEnrolled => "$personId isn't on this device yet: enrol them, then wait for the next sync.",
          _ => 'Try again: ${result.outcome.name}',
        });
      });

  Future<void> act(Future<void> Function() action) async {
    try {
      await action();
    } on FacePingException catch (e) {
      show(e.message);
    } on StateError {
      // FacePing.init failed in main(), for example no token passed.
      show("FacePing isn't set up: pass the device token with --dart-define=FACEPING_DEVICE_TOKEN=fpd_…");
    }
  }

  void show(String text) {
    if (mounted) setState(() => status = text);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: ListView(
          padding: const EdgeInsets.all(24),
          children: [
            SizedBox(height: 420, child: FaceCamera(controller: camera, onCameraFailed: show)),
            const SizedBox(height: 16),
            FilledButton(onPressed: verify, child: const Text('Verify')),
            const SizedBox(height: 16),
            Text(status, textAlign: TextAlign.center, style: const TextStyle(fontSize: 18)),
          ],
        ),
      ),
    );
  }
}
  1. Run the device build with flutter run --release --dart-define=FACEPING_DEVICE_TOKEN=fpd_…. It downloads the list's faces at start-up and every few minutes after; the status line shows how many people synced and the sync status, and updates with each sync. revoked means the token was revoked, mistyped or its list deleted, and the device wipes its faces. Then tap Verify, with no network if you like.

Each face stays on the device no longer than its 24 hours on the practice list. See Devices and offline sync.

If you switch one install from the sandbox key to a device token instead, the two sets of faces stay apart: the app sees only the people synced from the device's list, and your sandbox faces come back (if they're under 24 hours old) when you switch back. Uninstalling removes both.

The finished app runs as a check-in device too: flutter run --release --dart-define=FACEPING_DEVICE_TOKEN=fpd_… --dart-define=FACEPING_PERSON_ID=ACME-000123.