toggle method

bool toggle(String value, [ bool shouldAdd ])

Adds the class value to the element if it is not on it, removes it if it is.

If shouldAdd is true, then we always add that value to the element. If shouldAdd is false then we always remove value from the element.

Source

bool toggle(String value, [bool shouldAdd]) {
  _validateToken(value);
  Set<String> s = readClasses();
  bool result = false;
  if (shouldAdd == null) shouldAdd = !s.contains(value);
  if (shouldAdd) {
    s.add(value);
    result = true;
  } else {
    s.remove(value);
  }
  writeClasses(s);
  return result;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-svg/AttributeClassSet/toggle.html