Apparence-io / CamerAwesome

📸 Embedding a camera experience within your own app shouldn't be that hard. A flutter plugin to integrate awesome Android / iOS camera experience.
https://ApparenceKit.dev
MIT License
912 stars 201 forks source link

Rework SaveConfig for web & multi sensors #312

Closed apalala-dev closed 1 year ago

apalala-dev commented 1 year ago

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.

Checklist

Before creating any Pull Request, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).

Breaking Change

Introduction of the CaptureRequest concept to deal with multiple pictures and ease the CamerAwesome web implementation.

g-apparence commented 1 year ago

Nice refactor ! How can we force download to

apalala-dev commented 1 year ago

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.

g-apparence commented 1 year ago

Maybe we could make this simpler ?

apalala-dev commented 1 year ago

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 😅