addImage method

Future<void> addImage(
  1. BuildContext context
)

Open assets picker

Implementation

Future<void> addImage(BuildContext context) async {
  final PickerController pickerController = PickerController();
  _isAvailableToAddVideo = assets.value.isEmpty;
  final List<XFile> result = await AdvancedMediaPicker.openPicker(
    controller: pickerController,
    context: context,
    cameraStyle: cameraStylePicker ?? CameraStyle(),
    style: stylePicker ??
        PickerStyle(
          titleWidget: const SizedBox(),
          backgroundColor: Colors.black,
          borderRadius: BorderRadius.circular(16),
          typeSelectionWidget: const SizedBox.shrink(),
          selectIconBackgroundColor: Colors.transparent,
        ),
    isNeedToShowCamera: isNeedToShowCameraPicker,
    isNeedVideoCamera: isNeedVideoCameraPicker,
    allowedTypes: _isAvailableToAddVideo
        ? PickerAssetType.imageAndVideo
        : PickerAssetType.image,
    selectionLimit: 1,
  );
  if (result.isNotEmpty) {
    final XFile file = result.first;
    final CustomAssetType type =
        file.path.isVideo() ? CustomAssetType.video : CustomAssetType.image;
    addCustomAsset(file: file, type: type);
  }
}