toggle method

bool toggle(
  1. XAsset a
)

Toggle selection. Returns false when adding past the limit.

Implementation

bool toggle(XAsset a) {
  final i = _picked.indexWhere((x) => x.id == a.id);
  if (i >= 0) {
    _picked.removeAt(i);
    notifyListeners();
    return true;
  }
  if (_picked.length >= limit) return false;
  _picked.add(a);
  notifyListeners();
  return true;
}