Skip to content

Commit

Permalink
Merge pull request #41 from Conezi/controller
Browse files Browse the repository at this point in the history
Added a controller for the [SmartFaceCamera] widget.
  • Loading branch information
Conezi authored May 28, 2024
2 parents e8e4fdd + d14ffe5 commit 2140e93
Show file tree
Hide file tree
Showing 14 changed files with 699 additions and 526 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Dev_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: subosito/flutter-action@v2
with:
channel: 'stable' # 'dev', 'alpha', default to: 'stable'
flutter-version: '3.16.5' # you can also specify exact version of flutter
flutter-version: '3.22.1' # you can also specify exact version of flutter

- uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603

Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.1.1

- Added `FaceCameraController` allowing developers to control the `SmartFaceCamera` widget.
- Updated dependencies.
- Modified `README.md`.

**BREAKING CHANGES:**
- `captureControlIcon` has been replaced with `captureControlBuilder`.
- `imageResolution, defaultCameraLens, defaultFlashMode, enableAudio, autoCapture, orientation, onCapture, onFaceDetected, performanceMode` has been moved to `FaceCameraController`.

## 0.1.0

- Improved codebase documentations.
Expand Down
63 changes: 42 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,32 @@ void main() async{
runApp(const MyApp());
}
```
* Then render the component in your application setting the onCapture callback.

* Create a new `FaceCameraController` controller, setting the onCapture callback.
```dart
late FaceCameraController controller;
@override
void initState() {
controller = FaceCameraController(
autoCapture: true,
defaultCameraLens: CameraLens.front,
onCapture: (File? image) {
},
);
super.initState();
}
```

* Then render the component in your application using the required options.
```dart
@override
Widget build(BuildContext context) {
return Scaffold(
body: SmartFaceCamera(
autoCapture: true,
defaultCameraLens: CameraLens.front,
controller: controller,
message: 'Center your face in the square',
onCapture: (File? image){
},
)
);
}
Expand All @@ -82,6 +96,27 @@ void main() async{

Here is a list of properties available to customize your widget:

| Name | Type | Description |
|---------------------------|-----------------------|-------------------------------------------------------------------------------|
| controller | FaceCameraController | The controller for the [SmartFaceCamera] widget |
| showControls | bool | set false to hide all controls |
| showCaptureControl | bool | set false to hide capture control icon |
| showFlashControl | bool | set false to hide flash control control icon |
| showCameraLensControl | bool | set false to hide camera lens control icon |
| message | String | use this pass a message above the camera |
| messageStyle | TextStyle | style applied to the message widget |
| lensControlIcon | Widget | use this to render a custom widget for camera lens control |
| flashControlBuilder | FlashControlBuilder | use this to build custom widgets for flash control based on camera flash mode |
| messageBuilder | MessageBuilder | use this to build custom messages based on face position |
| indicatorShape | IndicatorShape | use this to change the shape of the face indicator |
| indicatorAssetImage | String | use this to pass an asset image when IndicatorShape is set to image |
| indicatorBuilder | IndicatorBuilder | use this to build custom widgets for the face indicator |
| captureControlBuilder | CaptureControlBuilder | use this to build custom widgets for capture control |
| autoDisableCaptureControl | bool | set true to disable capture control widget when no face is detected |


Here is a list of properties available to customize your controller:

| Name | Type | Description |
|---------------------------|-------------------------|-------------------------------------------------------------------------------|
| onCapture | Function(File?) | callback invoked when camera captures image |
Expand All @@ -91,24 +126,10 @@ Here is a list of properties available to customize your widget:
| defaultFlashMode | CameraFlashMode | use this to set initial flash mode |
| enableAudio | bool | set false to disable capture sound |
| autoCapture | bool | set true to capture image on face detected |
| showControls | bool | set false to hide all controls |
| showCaptureControl | bool | set false to hide capture control icon |
| showFlashControl | bool | set false to hide flash control control icon |
| showCameraLensControl | bool | set false to hide camera lens control icon |
| message | String | use this pass a message above the camera |
| messageStyle | TextStyle | style applied to the message widget |
| orientation | CameraOrientation | use this to lock camera orientation |
| captureControlIcon | Widget | use this to render a custom widget for capture control |
| lensControlIcon | Widget | use this to render a custom widget for camera lens control |
| flashControlBuilder | FlashControlBuilder | use this to build custom widgets for flash control based on camera flash mode |
| messageBuilder | MessageBuilder | use this to build custom messages based on face position |
| indicatorShape | IndicatorShape | use this to change the shape of the face indicator |
| indicatorAssetImage | String | use this to pass an asset image when IndicatorShape is set to image |
| indicatorBuilder | IndicatorBuilder | use this to build custom widgets for the face indicator |
| captureControlBuilder | CaptureControlBuilder | use this to build custom widgets for capture control |
| autoDisableCaptureControl | bool | set true to disable capture control widget when no face is detected |
| performanceMode | FaceDetectorMode | Use this to set your preferred performance mode |


### Contributions
---

Expand Down
122 changes: 59 additions & 63 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,63 @@ PODS:
- face_camera (0.0.1):
- Flutter
- Flutter (1.0.0)
- google_mlkit_commons (0.6.1):
- google_mlkit_commons (0.7.1):
- Flutter
- MLKitVision
- google_mlkit_face_detection (0.9.0):
- google_mlkit_face_detection (0.11.0):
- Flutter
- google_mlkit_commons
- GoogleMLKit/FaceDetection (~> 4.0.0)
- GoogleDataTransport (9.2.3):
- GoogleMLKit/FaceDetection (~> 6.0.0)
- GoogleDataTransport (9.4.1):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- nanopb (< 2.30911.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
- GoogleMLKit/FaceDetection (4.0.0):
- GoogleMLKit/FaceDetection (6.0.0):
- GoogleMLKit/MLKitCore
- MLKitFaceDetection (~> 3.0.0)
- GoogleMLKit/MLKitCore (4.0.0):
- MLKitCommon (~> 9.0.0)
- GoogleToolboxForMac/DebugUtils (2.3.2):
- GoogleToolboxForMac/Defines (= 2.3.2)
- GoogleToolboxForMac/Defines (2.3.2)
- GoogleToolboxForMac/Logger (2.3.2):
- GoogleToolboxForMac/Defines (= 2.3.2)
- "GoogleToolboxForMac/NSData+zlib (2.3.2)":
- GoogleToolboxForMac/Defines (= 2.3.2)
- "GoogleToolboxForMac/NSDictionary+URLArguments (2.3.2)":
- GoogleToolboxForMac/DebugUtils (= 2.3.2)
- GoogleToolboxForMac/Defines (= 2.3.2)
- "GoogleToolboxForMac/NSString+URLArguments (= 2.3.2)"
- "GoogleToolboxForMac/NSString+URLArguments (2.3.2)"
- GoogleUtilities/Environment (7.11.1):
- MLKitFaceDetection (~> 5.0.0)
- GoogleMLKit/MLKitCore (6.0.0):
- MLKitCommon (~> 11.0.0)
- GoogleToolboxForMac/Defines (4.2.1)
- GoogleToolboxForMac/Logger (4.2.1):
- GoogleToolboxForMac/Defines (= 4.2.1)
- "GoogleToolboxForMac/NSData+zlib (4.2.1)":
- GoogleToolboxForMac/Defines (= 4.2.1)
- GoogleUtilities/Environment (7.13.3):
- GoogleUtilities/Privacy
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/Logger (7.11.1):
- GoogleUtilities/Logger (7.13.3):
- GoogleUtilities/Environment
- GoogleUtilities/UserDefaults (7.11.1):
- GoogleUtilities/Privacy
- GoogleUtilities/Privacy (7.13.3)
- GoogleUtilities/UserDefaults (7.13.3):
- GoogleUtilities/Logger
- GoogleUtilities/Privacy
- GoogleUtilitiesComponents (1.1.0):
- GoogleUtilities/Logger
- GTMSessionFetcher/Core (2.3.0)
- MLImage (1.0.0-beta4)
- MLKitCommon (9.0.0):
- GoogleDataTransport (~> 9.0)
- GoogleToolboxForMac/Logger (~> 2.1)
- "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
- "GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1)"
- GoogleUtilities/UserDefaults (~> 7.0)
- GTMSessionFetcher/Core (3.4.1)
- MLImage (1.0.0-beta5)
- MLKitCommon (11.0.0):
- GoogleDataTransport (< 10.0, >= 9.4.1)
- GoogleToolboxForMac/Logger (< 5.0, >= 4.2.1)
- "GoogleToolboxForMac/NSData+zlib (< 5.0, >= 4.2.1)"
- GoogleUtilities/UserDefaults (< 8.0, >= 7.13.0)
- GoogleUtilitiesComponents (~> 1.0)
- GTMSessionFetcher/Core (< 3.0, >= 1.1)
- MLKitFaceDetection (3.0.0):
- MLKitCommon (~> 9.0)
- MLKitVision (~> 5.0)
- MLKitVision (5.0.0):
- GoogleToolboxForMac/Logger (~> 2.1)
- "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
- GTMSessionFetcher/Core (< 3.0, >= 1.1)
- MLImage (= 1.0.0-beta4)
- MLKitCommon (~> 9.0)
- nanopb (2.30909.0):
- nanopb/decode (= 2.30909.0)
- nanopb/encode (= 2.30909.0)
- nanopb/decode (2.30909.0)
- nanopb/encode (2.30909.0)
- PromisesObjC (2.2.0)
- GTMSessionFetcher/Core (< 4.0, >= 3.3.2)
- MLKitFaceDetection (5.0.0):
- MLKitCommon (~> 11.0)
- MLKitVision (~> 7.0)
- MLKitVision (7.0.0):
- GoogleToolboxForMac/Logger (< 5.0, >= 4.2.1)
- "GoogleToolboxForMac/NSData+zlib (< 5.0, >= 4.2.1)"
- GTMSessionFetcher/Core (< 4.0, >= 3.3.2)
- MLImage (= 1.0.0-beta5)
- MLKitCommon (~> 11.0)
- nanopb (2.30910.0):
- nanopb/decode (= 2.30910.0)
- nanopb/encode (= 2.30910.0)
- nanopb/decode (2.30910.0)
- nanopb/encode (2.30910.0)
- PromisesObjC (2.4.0)

DEPENDENCIES:
- camera_avfoundation (from `.symlinks/plugins/camera_avfoundation/ios`)
Expand Down Expand Up @@ -101,24 +97,24 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/google_mlkit_face_detection/ios"

SPEC CHECKSUMS:
camera_avfoundation: 3125e8cd1a4387f6f31c6c63abb8a55892a9eeeb
camera_avfoundation: 759172d1a77ae7be0de08fc104cfb79738b8a59e
face_camera: 9473f8c80e20d67bd2d946ed573ccee168d31186
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
google_mlkit_commons: 3857c1e9f23ca02073f8dd34a7a3580feb814cef
google_mlkit_face_detection: 52f7e4c15a7c49b98940fa32af4c2b10fd8608fc
GoogleDataTransport: f0308f5905a745f94fb91fea9c6cbaf3831cb1bd
GoogleMLKit: 2bd0dc6253c4d4f227aad460f69215a504b2980e
GoogleToolboxForMac: 8bef7c7c5cf7291c687cf5354f39f9db6399ad34
GoogleUtilities: 9aa0ad5a7bc171f8bae016300bfcfa3fb8425749
google_mlkit_commons: 96aaca445520311b84a2da013dedf3427fe4cc69
google_mlkit_face_detection: b760d6035222630f347352b3b13f4a23ea9fb994
GoogleDataTransport: 6c09b596d841063d76d4288cc2d2f42cc36e1e2a
GoogleMLKit: 97ac7af399057e99182ee8edfa8249e3226a4065
GoogleToolboxForMac: d1a2cbf009c453f4d6ded37c105e2f67a32206d8
GoogleUtilities: ea963c370a38a8069cc5f7ba4ca849a60b6d7d15
GoogleUtilitiesComponents: 679b2c881db3b615a2777504623df6122dd20afe
GTMSessionFetcher: 3a63d75eecd6aa32c2fc79f578064e1214dfdec2
MLImage: 7bb7c4264164ade9bf64f679b40fb29c8f33ee9b
MLKitCommon: c1b791c3e667091918d91bda4bba69a91011e390
MLKitFaceDetection: 4981488f71ea8ed718cda692a29ab562637d9ae5
MLKitVision: 8baa5f46ee3352614169b85250574fde38c36f49
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef
GTMSessionFetcher: 8000756fc1c19d2e5697b90311f7832d2e33f6cd
MLImage: 1824212150da33ef225fbd3dc49f184cf611046c
MLKitCommon: afec63980417d29ffbb4790529a1b0a2291699e1
MLKitFaceDetection: 7c0e8bf09ddd27105da32d088fca978a99fc30cc
MLKitVision: e858c5f125ecc288e4a31127928301eaba9ae0c1
nanopb: 438bc412db1928dac798aa6fd75726007be04262
PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47

PODFILE CHECKSUM: 0d895a65d153cd6b7f421b4d23b29c977b9f03bc

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
37 changes: 28 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
File? _capturedImage;

late FaceCameraController controller;

@override
void initState() {
controller = FaceCameraController(
autoCapture: true,
defaultCameraLens: CameraLens.front,
onCapture: (File? image) {
setState(() => _capturedImage = image);
},
onFaceDetected: (Face? face) {
//Do something
},
);
super.initState();
}

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand All @@ -41,7 +58,10 @@ class _MyAppState extends State<MyApp> {
fit: BoxFit.fitWidth,
),
ElevatedButton(
onPressed: () => setState(() => _capturedImage = null),
onPressed: () async {
await controller.startImageStream();
setState(() => _capturedImage = null);
},
child: const Text(
'Capture Again',
textAlign: TextAlign.center,
Expand All @@ -53,14 +73,7 @@ class _MyAppState extends State<MyApp> {
);
}
return SmartFaceCamera(
autoCapture: true,
defaultCameraLens: CameraLens.front,
onCapture: (File? image) {
setState(() => _capturedImage = image);
},
onFaceDetected: (Face? face) {
//Do something
},
controller: controller,
messageBuilder: (context, face) {
if (face == null) {
return _message('Place your face in the camera');
Expand All @@ -81,4 +94,10 @@ class _MyAppState extends State<MyApp> {
style: const TextStyle(
fontSize: 14, height: 1.5, fontWeight: FontWeight.w400)),
);

@override
void dispose() {
controller.dispose();
super.dispose();
}
}
Loading

0 comments on commit 2140e93

Please sign in to comment.