toggleable 2.1.2 copy "toggleable: ^2.1.2" to clipboard
toggleable: ^2.1.2 copied to clipboard

Helps maintaining the state which can toggle. It provides various of helper methods.

Features #

Toggleable - enum #

It is the switchable enum value which has on, off.
Toggleable t1 = Toggleable.on;
Toggleable t2 = Toggleable.off;
  • No more verbose if else - Use when()
Toggleable toggleable = Toggleable.on;
// ... some logics that changes the toggleable
final result = toggleable.when(
  on: () => 1,
  off: () => 2,
);
// You could check the "Usage" section to explore more awesome examples!
  • It also provides some alias getters
final t1 = Toggleable.on;

t1.isOn; // true
t1.isEnabled; // true

t1.isOff; // false
t1.isDisabled; // false
  • You can initializing it from boolean
expect(Toggleable.from(true), Toggleable.on);
expect(Toggleable.from(false), Toggleable.off);

ToggleableState #

It is wrapper for Toggleable which helps using it.
final state = ToggleableState(initialState: Toggleable.off);

state.toggle(); // toggles the state
state.on(); // turn on the state
state.off(); // turn off the state

Usage #

final mySwitch = ToggleableState();

mySwitch.on();
mySwitch.isOn; // true
mySwitch.isEnabled; // true

mySwitch.off();
mySwitch.isOff; // true
mySwitch.isDisabled; // true

mySwitch.toggle();

int someOtherState = 1;

mySwitch.addListener(turnOnCallback: () => someOtherState++);

Additional information #

  • Please improve this package by contributing!
7
likes
150
points
25
downloads

Publisher

unverified uploader

Weekly Downloads

Helps maintaining the state which can toggle. It provides various of helper methods.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

easy_debounce

More

Packages that depend on toggleable