FHUNumericValueNotifierExtension extension
NumericValueNotifierExtension
Extension on ValueNotifier<num>
to enable direct numerical manipulations.
This extension enriches the ValueNotifier with methods specifically tailored for
handling numerical data. It allows for direct mathematical operations on the numeric
value contained within the ValueNotifier, without the need to explicitly access the .value
property.
This simplifies arithmetic operations such as addition, subtraction, multiplication, and division, directly on the ValueNotifier's numeric value, making the code more readable and concise, especially in a reactive programming context.
Example:
final numberValueNotifier = 10.notifier;
numberValueNotifier.increment(5); // Directly adds 5 to the value (now 15)
numberValueNotifier.multiply(2); // Directly multiplies the value by 2 (now 30)
// These operations modify the numeric value within the ValueNotifier without accessing `.value`
- on
Properties
- isFinite → bool
-
Whether this number is finite.
no setter
- isInfinite → bool
-
Whether this number is positive infinity or negative infinity.
no setter
- isNaN → bool
-
Whether this number is a Not-a-Number value.
no setter
- isNegative → bool
-
Whether this number is negative.
no setter
- sign → num
-
Negative one, zero or positive one depending on the sign and
numerical value of this number.
no setter
Methods
-
abs(
) → num - The absolute value of this number.
-
ceil(
) → int -
The least integer no smaller than
this
. -
ceilToDouble(
) → double -
Returns the least double integer value no smaller than
this
. -
clamp(
num lowerLimit, num upperLimit) → num -
Returns this num clamped to be in the range
lowerLimit
-upperLimit
. -
compareTo(
num other) → int -
Compares this to
other
. -
decrement(
[num step = 1]) → void - Decrement the value by a given step (default is 1).
-
divide(
num divisor) → void - Divide the value by a given divisor. Avoid division by zero.
-
floor(
) → int - The greatest integer no greater than this number.
-
floorToDouble(
) → double -
Returns the greatest double integer value no greater than
this
. -
increment(
[num step = 1]) → void - Increment the value by a given step (default is 1).
-
max(
num other) → void - Maximum of the value and another num.
-
min(
num other) → void - Minimum of the value and another num.
-
modulo(
num divisor) → void - Modulo operation with a given divisor. Avoid division by zero.
-
multiply(
num factor) → void - Multiply the value by a given factor.
-
negate(
) → void - Negate the value (change its sign).
-
remainder(
num other) → num -
The remainder of the truncating division of
this
byother
. -
reset(
) → void - reset the value of the ValueNotifier
-
round(
) → int - The integer closest to this number.
-
roundToDouble(
) → double - The double integer value closest to this value.
-
toDouble(
) → double - This number as a double.
-
toInt(
) → int - Truncates this num to an integer and returns the result as an int.
-
toStringAsExponential(
[int? fractionDigits]) → String - An exponential string-representation of this number.
-
toStringAsFixed(
int fractionDigits) → String - A decimal-point string-representation of this number.
-
toStringAsPrecision(
int precision) → String -
A string representation with
precision
significant digits. -
truncate(
) → int -
The integer obtained by discarding any fractional digits from
this
. -
truncateToDouble(
) → double -
Returns the double integer value obtained by discarding any fractional
digits from the double value of
this
.
Operators
-
operator %(
num other) → num -
Euclidean modulo of this number by
other
. -
operator *(
num other) → num -
Multiplies this number by
other
. -
operator +(
num other) → num -
Adds
other
to this number. -
operator -(
num other) → num -
Subtracts
other
from this number. -
operator /(
num other) → double -
Divides this number by
other
. -
operator <(
num other) → bool -
Whether this number is numerically smaller than
other
. -
operator <=(
num other) → bool -
Whether this number is numerically smaller than or equal to
other
. -
operator >(
num other) → bool -
Whether this number is numerically greater than
other
. -
operator >=(
num other) → bool -
Whether this number is numerically greater than or equal to
other
. -
operator unary-(
) → num - The negation of this value.
-
operator ~/(
num other) → int - Truncating division operator.