select method

void select(
  1. MediaEntity entity,
  2. BuildContext context
)

Implementation

void select(MediaEntity entity, BuildContext context) {
  if (singleSelection) {
    _onChanged?.call(entity, false);
    if (setting.onItemClick != null) {
      setting.onItemClick!(entity, [entity]);
    }
    final selectedList = value.selectedEntities.toList();
    selectedList.add(entity);
    completeTaskSingleSelection(context, selectedList);
  } else {
    final selectedList = value.selectedEntities.toList();

    if (selectedList.contains(entity)) {
      selectedList.remove(entity);
      _onChanged?.call(entity, true);
    } else {
      if (reachedMaximumLimit) {
        if (setting.onReachedMaximumLimit == null) {
          ScaffoldMessenger.of(context)
            ..clearSnackBars()
            ..showSnackBar(SnackBar(
                content: Text(
              'Maximum selection limit of '
              '${setting.maximum} has been reached!',
            )));
        } else {
          setting.onReachedMaximumLimit!();
        }
        return;
      }
      selectedList.add(entity);
      _onChanged?.call(entity, false);
    }
    internal = true;
    value = value.copyWith(
      selectedEntities: selectedList,
      previousSelection: false,
    );

    if (setting.onItemClick != null) {
      setting.onItemClick!(entity, selectedList);
    }
  }
}