toggle method

List<E> toggle(
  1. E value, {
  2. bool? exist,
  3. int newIndex = 0,
  4. void callback(
    1. bool status
    )?,
})

Implementation

List<E> toggle(
  E value, {
  bool? exist,
  int newIndex = 0,
  void Function(bool status)? callback,
}) {
  final a = use;
  exist ??= a.contains(value);
  if (exist) {
    a.remove(value);
    if (callback != null) callback(false);
  } else {
    if (newIndex > -1) {
      a.insert(newIndex, value);
    } else {
      a.add(value);
    }
    if (callback != null) callback(true);
  }
  return a;
}