Docs › Recipes
Flutter (Dart)
The ScreenlyyID Flutter example is the reference for a Flutter app that runs on iOS and Android. It mirrors the iOS and Android examples and has the same two parts, and the split matters:
backend/: a small Node server that holds the API key and theCorrelationIdand makes every ScreenlyyID call. You can swap it for your own server, for instance the Express or FastAPI recipes, which have the same two routes.lib/: the Flutter app. It contains no API key. It asks the back end to create a verification, asks for camera permission, opens thewebEnrolmentUrlin aWebViewWidget, listens forIDV_SESSION_COMPLETEandERROR, then asks the back end for the result.
Follow the steps and the camera-permission notes on the Mobile app page. The example's README explains how to run both parts on a simulator, an emulator or a real phone.
The details that matter in Flutter#
These are the usual reasons capture "does nothing" in a Flutter WebView:
- Answer the page's camera request. The capture page asks the WebView for the camera, and the WebView only provides it if you handle
onPermissionRequestwhen you create theWebViewController. Holding the camera permission in your app is not enough. Grant it only if the app holds the permission. - Forward the page's events yourself. The hosted page sends
IDV_SESSION_COMPLETEandERRORwithwindow.parent.postMessage, and a WebView has no outer page to receive them. Register a JavaScript channel withaddJavaScriptChannel, then inject amessagelistener that calls it when the page has loaded. - Platform settings. On iOS, create the controller with
allowsInlineMediaPlayback: trueso the camera preview plays inside the page, and addNSCameraUsageDescriptiontoInfo.plist. On Android, declareCAMERAin the manifest and setcompileSdkto 37 (permission_handlerneeds it). With CocoaPods rather than Swift Package Manager, also addPERMISSION_CAMERA=1to the Podfile'sGCC_PREPROCESSOR_DEFINITIONS, or the iOS camera permission is always denied.
The pieces to copy#
| What | File in the example |
|---|---|
Ask the back end for a session and for the result (the http package) | lib/backend.dart |
| Ask for camera permission before loading the page, send the user to Settings if it was denied for good | lib/home_screen.dart |
WebViewController setup, the camera grant, the event channel, and only loading ScreenlyyID pages | lib/verification_screen.dart |
One request for the result after IDV_SESSION_COMPLETE | lib/result_screen.dart |
| Android manifest permissions and the demo-only HTTP allowance for the local back end | android/app/src/main/AndroidManifest.xml, android/app/src/main/res/xml/network_security_config.xml |
| iOS camera usage text and the demo-only local-network allowance | ios/Runner/Info.plist |
| The server routes | backend/server.mjs |
Run it#
- Create a
test_API key in the dashboard under Integrations. - Start the back end:
cd backend && SCREENLYYID_API_KEY=test_... node server.mjs. - Run the app with
flutter pub getthenflutter run. The Android emulator reaches the back end athttp://10.0.2.2:3000and the iOS simulator athttp://localhost:3000(both are the defaults). On a real phone, pass your computer's address:flutter run --dart-define=BACKEND_URL=http://192.168.1.20:3000.
The camera needs a real device on iOS. Plain HTTP to the local back end is allowed for the demo only: a real back end uses HTTPS, so remove the Android network_security_config.xml and the iOS NSAllowsLocalNetworking setting.