A flutter package for IOS and Android to secure all or part of your app under face detection.
- Widget will lock screen when a face is not detected looking at phone
- A snapshot of the face which unlocked the screen can be accessed via a callback function.
First, this package used google Mk kit for face detection. So you have to connect your project to a firebase project and past the
google-services.json file in the
android/app/ directory in your flutter project.
Second, add camera as a dependency in your
- This package uses the camera for face detection. So make sure you request for camera permission.
Add two rows to the
one with the key Privacy - Camera Usage Description and a usage description. and one with the key Privacy - Microphone Usage Description and a usage description. If editing Info.plist as text, add:
<key>NSCameraUsageDescription</key> <string>your usage description here</string> <key>NSMicrophoneUsageDescription</key> <string>your usage description here</string>
Change the minimum Android SDK version to 21 (or higher) in your
If you wish to use this widget only to lock only a single page of your app or the whole app, then you can simply wrap the page you want to lock or the whole app with
FaceDetectionLock widget respectively as follows;
return FaceDetectionLock( body: MyAppOrWidgetToSecure() );
However, if you wish to pass an existing camera controller and/or get hold of the faces that triggered the app unlock, then do the following.
- You can get hold of the faces, that unlocked the device
- via a call back function. For this function to be initialized
- you need to set the
- sure you initialize the
FaceDetectionBloca widget above and
- call the
initializeCamevent prior to calling the
MaterialApp( home: BlocProvider( create:(context) => FaceDetectionBloc(cameraController: controller, onFaceSnapshot: callbackFunction ) ..add(const FaceDetectionEvent.initializeCam()); child: BodyWidget() ) )
Then make sure that when calling the
FaceDetectionLock widget lower in the widget true you set the parameter
isBlocInitializeAbove to true. For instance
return FaceDetectionLock( isBlocInitializeAbove: true, body: BankAccountPageToSecure() );