toggleBit method

  1. @nonVirtual
T toggleBit(
  1. int n, [
  2. bool? v
])

Sets the nth bit if v is true, otherwise clears.

If v is not provided defaults to the opposit of the current value.

Returns the new value.

Implementation

@nonVirtual
// ignore: avoid_positional_boolean_parameters
T toggleBit(int n, [bool? v]) {
  v ??= !isSet(n);
  return v ? setBit(n) : clearBit(n);
}