Closed apalala-dev closed 1 year ago
Nice refactor ! How can we force download to
Nice refactor ! How can we force download to
- custom path
- download folder
- application folder
Here is an example for the download folder, with a different name for each picture on multicam:
CameraAwesomeBuilder.awesome(
saveConfig: SaveConfig.photoAndVideo(
initialCaptureMode: CaptureMode.photo,
photoPathBuilder: (sensors) async {
final Directory? extDir = await getDownloadsDirectory();
final testDir = await Directory(
'${extDir!.path}/camerawesome',
).create(recursive: true);
if (sensors.length == 1) {
final String filePath =
'${testDir.path}/${DateTime.now().millisecondsSinceEpoch}.jpg';
return SingleCaptureRequest(XFile(filePath), sensors.first);
} else {
// Separate pictures taken with front and back camera
return MultipleCaptureRequest({
for (final sensor in sensors)
sensor: XFile(
'${testDir.path}/${sensor.position == SensorPosition.front ? 'front_' : "back_"}${DateTime.now().millisecondsSinceEpoch}.jpg',
)
});
}
},
),
);
One downside of this solution is that the app using CamerAwesome must also add a cross_file
and a path_provider
dependency to set a custom save path.
Maybe we could make this simpler ?
Maybe we could make this simpler ?
I don't think we can simplify the part to specify the path (retrieving the directory, creating it if it doesn't exist, building the filePath). After that, I separated as an example if there was one or more sensors taking pictures, but in most cases it will only use the first part. However, the need to build an XFile (and by doing so, adding a dependancy in the client side to cross_file) does not seem very nice to me. We probably could just pass the path and build an XFile in the lib.
Feel free to share any other idea 😅
Description
This PR intends to give more informations about which picture was taken (which sensor took it). It should also provide a better web support with the use of the cross_file package.
FilePathBuilder
, it now takesCaptureRequestBuilder
List<Sensor>
as argumentSingleCaptureRequest
or aMultipleCaptureRequest
depending on the number of sensors requiredSaveConfig
has a default value forCaptureRequestBuilder
. Medias will be saved at [temporary directory]/camerawesome/[time in millis].jpgCaptureRequest
usesXFile
instead ofString
to better support Web (e.g.:file
property for aSingleCaptureRequest
)XFile
will be built by the camera implementation without a real path.MediaCapture
object now contains aCaptureRequest
instead of a path (String).CaptureRequest
can either be aSingleCaptureRequest
or aMultipleCaptureRequest
, awhen
operator is introduced to deal with these without explicit casting on the dev side.XFile
may be added to let users specify their own path in theSaveConfig
with the current implementation. An alternative would be to create our ownFile
class and convert it toXFile
when we want to work with it.Checklist
Before creating any Pull Request, confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
).flutter analyze
without any issues.Breaking Change
Introduction of the
CaptureRequest
concept to deal with multiple pictures and ease the CamerAwesome web implementation.