Closed chitgoks closed 1 year ago
The SaveConfig does not provide a callback to call after a media has been saved.
However, you can listen to cameraState.captureState$
to react to different capture states. A new event is provided whenever the status of the capture status changes, including when a media is saved.
Here, you probably want a MediaCapture
with a MediaCaptureStatus.success
before running your code.
Thanks! I think that is what I am looking for.
@apalala-dev how do you do this with the awesome builder or would we have to use the custom builder?
The SaveConfig does not provide a callback to call after a media has been saved.
However, you can listen to
cameraState.captureState$
to react to different capture states. A new event is provided whenever the status of the capture status changes, including when a media is saved. Here, you probably want aMediaCapture
with aMediaCaptureStatus.success
before running your code.
Here's how I'm implementing this. Is there a better way to get access to state, not in the builder?
return CameraAwesomeBuilder.awesome(
saveConfig: SaveConfig.photo(),
onMediaTap: (mediaCapture) {
print("Tapped");
},
topActionsBuilder: (state) {
// This is placed here due to the presence of state;
_captureStateSubscription ??=
state.captureState$.listen((MediaCapture? mediaCapture) {
if (mediaCapture != null) {
capture = mediaCapture;
switch (mediaCapture.status) {
case MediaCaptureStatus.success:
// Image captured, perform additional code (e.g., get the file path)
print("Image captured: ${filePath(mediaCapture)}");
break;
case MediaCaptureStatus.capturing:
print("Capturing in progress...");
break;
case MediaCaptureStatus.failure:
print("Capture failed!");
break;
}
}
});
return Container();
},
// Retrieve the file path
String filePath(MediaCapture mediaCapture) {
if (mediaCapture.status == MediaCaptureStatus.success &&
mediaCapture.captureRequest != null) {
return mediaCapture.captureRequest.when(
single: (single) => single.file!.path,
multiple: (multiple) => multiple.fileBySensor.values.first!.path,
);
} else {
return "null found";
}
}
}
);
I already have a code in place to run the code what to do with the picture or video taken. But i am not sure where this takes place.
I figured it would be in
but that sample just returns a string. what would the photoPathBuilder look like if i would place code after a picture is taken (or video)?
Thoughts?