isSingleButton function Null safety
- int buttons
Returns whether buttons
contains one and only one button.
The buttons
parameter is a bit field where each set bit represents a button.
This function returns whether there is only one set bit in the given integer.
It returns false when buttons
is zero.
Example:
assert(isSingleButton(0x1) == true);
assert(isSingleButton(0x11) == false);
assert(isSingleButton(0) == false);
See also:
- smallestButton, which returns the button in a
buttons
bit field with the smallest integer button.
Implementation
bool isSingleButton(int buttons) => buttons != 0 && (smallestButton(buttons) == buttons);