toggle method

bool toggle (
  1. String value,
  2. [bool? shouldAdd]
)
inherited

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.

Implementation

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.dart.dev/stable/2.13.0/dart-svg/AttributeClassSet/toggle.html