toggleAttr method

bool toggleAttr(
  1. String name, [
  2. bool? force
])

Toggles a boolean attribute on the element.

Implementation

bool toggleAttr(String name, [bool? force]) {
  if (_element == null) return false;

  final shouldAdd = force ?? !hasAttr(name);
  if (shouldAdd) {
    _element!.setAttribute(name, '');
  } else {
    _element!.removeAttribute(name);
  }
  return shouldAdd;
}