toggle method
void
toggle()
Toggles the current boolean state.
Changes true
to false
and false
to true
, then notifies all listeners
of the change. This is equivalent to setting value = !value
but provides
a more semantic API for toggle operations.
Example:
final controller = ToggleController(false);
controller.toggle(); // value is now true
controller.toggle(); // value is now false
Implementation
void toggle() {
value = !value;
}