pickImages static method

Future<List<Asset>> pickImages({
  1. required int maxImages,
  2. bool enableCamera = false,
  3. List<Asset> selectedAssets = const [],
  4. CupertinoOptions cupertinoOptions = const CupertinoOptions(),
  5. MaterialOptions materialOptions = const MaterialOptions(),
})

Invokes the multi image picker selector.

You must provide maxImages option, which will limit the number of images that the user can choose. On iOS you can pass also cupertinoOptions parameter which should be an instance of CupertinoOptions class. It allows you to customize the look of the image picker. On Android you can pass the materialOptions parameter, which should be an instance of MaterialOptions class. As from version 2.1.40 a new parameter enableCamera was added, which allows the user to take a picture directly from the gallery.

If you would like to present the picker with pre selected photos, you can pass selectedAssets with List of Asset objects picked previously from the picker.

This method returns list of Asset objects. Because they are just placeholders containing the actual identifier to the image, not the image itself you can pick thousands of images at a time, with no performance penalty. How to request the original image or a thumb you can refer to the docs for the Asset class.

Implementation

static Future<List<Asset>> pickImages({
  required int maxImages,
  bool enableCamera = false,
  List<Asset> selectedAssets = const [],
  CupertinoOptions cupertinoOptions = const CupertinoOptions(),
  MaterialOptions materialOptions = const MaterialOptions(),
}) async {
  if (maxImages < 0) {
    throw new ArgumentError.value(maxImages, 'maxImages cannot be negative');
  }

  try {
    final List<dynamic> images = await _channel.invokeMethod(
      'pickImages',
      <String, dynamic>{
        'maxImages': maxImages,
        'enableCamera': enableCamera,
        'iosOptions': cupertinoOptions.toJson(),
        'androidOptions': materialOptions.toJson(),
        'selectedAssets': selectedAssets
            .map(
              (Asset asset) => asset.identifier,
            )
            .toList(),
      },
    );

    var assets = <Asset>[];
    for (var item in images) {
      var asset = Asset(
        item['identifier'],
        item['name'],
        item['width'],
        item['height'],
      );
      assets.add(asset);
    }
    return assets;
  } on PlatformException catch (e) {
    switch (e.code) {
      case "CANCELLED":
        throw NoImagesSelectedException(e.message!);
      case "PERMISSION_DENIED":
        throw PermissionDeniedException(e.message!);
      case "PERMISSION_PERMANENTLY_DENIED":
        throw PermissionPermanentlyDeniedExeption(e.message!);
      default:
        throw e;
    }
  }
}