openFaceCamera method
Future<void>
openFaceCamera(
- BuildContext context,
- ShowFaceCameraAction action,
- ScopeManager? scopeManager
override
Implementation
@override
Future<void> openFaceCamera(BuildContext context, ShowFaceCameraAction action,
ScopeManager? scopeManager) async {
if (!kIsWeb) {
await FaceCamera.initialize();
}
final camera = FaceDetectionCamera(
onCapture: (file) async {
// Pop the camera page once a capture has occurred.
Navigator.pop(context);
final fileJson = file?.toJson();
// If an ID is provided and scopeManager exists, update dataContext and dispatch event.
if (action.id != null && scopeManager != null) {
scopeManager.dataContext.addDataContext({
action.id!: {
'files': [fileJson]
}
});
scopeManager.dispatch(
ModelChangeEvent(
APIBindingSource(action.id!),
{
'files': [fileJson]
},
),
);
}
// Execute the onCapture action if provided.
if (action.onCapture != null) {
try {
await ScreenController().executeAction(context, action.onCapture!);
} on Exception catch (_) {}
}
},
onError: (error) {
// Close the camera page when an error occurs.
Navigator.pop(context);
if (action.onError != null) {
ScreenController().executeAction(
context,
action.onError!,
event: EnsembleEvent(null, error: error.toString()),
);
}
},
);
// Set properties from options
final options = action.options ?? {};
for (var option in options.keys) {
final value = scopeManager?.dataContext.eval(options[option]);
camera.setProperty(option, value);
}
await Navigator.push(
context,
MaterialPageRoute(builder: (context) => camera),
);
}