saveToLibrary method

  1. @override
Future<PickerAsset?> saveToLibrary(
  1. CapturedMedia capture
)
override

Saves a camera capture into the device library and returns it as a library asset.

The picker addresses every asset by platform id (PickerAsset.id) — thumbnails resolve through it and so does export — so a capture has to become a library asset before the grid can show it. That is why the camera delegate hands back a file and this does the write: it keeps photo_manager inside the one layer allowed to touch it (design §4.1).

Returns null when the platform saved something the picker never surfaces. Throws when the platform refused the write; the caller surfaces that rather than swallowing it.

Implementation

@override
Future<PickerAsset?> saveToLibrary(CapturedMedia capture) async {
  savedCaptures.add(capture);
  if (saveThrows) {
    throw StateError('fake save refused');
  }
  return saveResult;
}