SassNumber class Null safety Value

A SassScript number.

Numbers can have units. Although there's no literal syntax for it, numbers support scientific-style numerator and denominator units (for example, miles/hour). These are expected to be resolved before being emitted to CSS.

Inheritance
Annotations

Constructors

SassNumber(num value, [String? unit])
Creates a number, optionally with a single numerator unit.
factory
SassNumber.withUnits(num value, {List<String>? numeratorUnits, List<String>? denominatorUnits})
Creates a number with full numeratorUnits and denominatorUnits.
factory

Properties

asInt int?
If this is an integer according to isInt, returns value as an int.
read-only
asList List<Value>
This value as a list.
read-only, inherited
denominatorUnits List<String>
This number's denominator units.
read-only
hasBrackets bool
Whether this value as a list has brackets.
read-only, inherited
hashCode int
The hash code for this object.
read-only, override
hasUnits bool
Whether this has any units.
read-only
isInt bool
Whether this is an integer, according to fuzzyEquals.
read-only
isTruthy bool
Whether the value counts as true in an @if statement and other contexts.
read-only, inherited
numeratorUnits List<String>
This number's numerator units.
read-only
realNull Value?
Returns Dart's null value if this is sassNull, and returns this otherwise.
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
separator ListSeparator
The separator for this value as a list.
read-only, inherited
unitString String
Returns a human readable string representation of this number's units.
read-only
value num
The value of this number.
read-only

Methods

accept<T>(ValueVisitor<T> visitor) → T
Calls the appropriate visit method on visitor.
assertBoolean([String? name]) SassBoolean
Throws a SassScriptException if this isn't a boolean.
inherited
assertCalculation([String? name]) SassCalculation
Throws a SassScriptException if this isn't a calculation.
inherited
assertColor([String? name]) SassColor
Throws a SassScriptException if this isn't a color.
inherited
assertFunction([String? name]) SassFunction
Throws a SassScriptException if this isn't a function reference.
inherited
assertInt([String? name]) int
Returns value as an int, if it's an integer value according to isInt.
assertMap([String? name]) SassMap
Throws a SassScriptException if this isn't a map.
inherited
assertNoUnits([String? name]) → void
Throws a SassScriptException unless this has no units.
assertNumber([String? name]) SassNumber
Throws a SassScriptException if this isn't a number.
override
assertString([String? name]) SassString
Throws a SassScriptException if this isn't a string.
inherited
assertUnit(String unit, [String? name]) → void
Throws a SassScriptException unless this has unit as its only unit (and as a numerator).
coerce(List<String> newNumerators, List<String> newDenominators, [String? name]) SassNumber
Returns a copy of this number, converted to the units represented by newNumerators and newDenominators.
coerceToMatch(SassNumber other, [String? name, String? otherName]) SassNumber
Returns a copy of this number, converted to the same units as other.
coerceValue(List<String> newNumerators, List<String> newDenominators, [String? name]) num
Returns value, converted to the units represented by newNumerators and newDenominators.
coerceValueToMatch(SassNumber other, [String? name, String? otherName]) num
Returns value, converted to the same units as other.
coerceValueToUnit(String unit, [String? name]) num
A shorthand for coerceValue with only one numerator unit.
compatibleWithUnit(String unit) bool
Returns whether this can be coerced to the given unit.
convert(List<String> newNumerators, List<String> newDenominators, [String? name]) SassNumber
Returns a copy of this number, converted to the units represented by newNumerators and newDenominators.
convertToMatch(SassNumber other, [String? name, String? otherName]) SassNumber
Returns a copy of this number, converted to the same units as other.
convertValue(List<String> newNumerators, List<String> newDenominators, [String? name]) num
Returns value, converted to the units represented by newNumerators and newDenominators.
convertValueToMatch(SassNumber other, [String? name, String? otherName]) num
Returns value, converted to the same units as other.
hasCompatibleUnits(SassNumber other) bool
Returns whether this has units that are compatible with other.
hasPossiblyCompatibleUnits(SassNumber other) bool
Returns whether this has units that are possibly-compatible with other, as defined by the Sass spec.
hasUnit(String unit) bool
Returns whether this has unit as its only unit (and as a numerator).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
sassIndexToListIndex(Value sassIndex, [String? name]) int
Converts sassIndex into a Dart-style index into the list returned by asList.
inherited
toCssString({bool quote = true}) String
Returns a valid CSS representation of this.
inherited
toString() String
Returns a string representation of this.
inherited
tryMap() SassMap?
Returns this as a SassMap if it is one (including empty lists, which count as empty maps) or returns null if it's not.
inherited
valueInRange(num min, num max, [String? name]) num
If value is between min and max, returns it.
valueInUnits(List<String> newNumerators, List<String> newDenominators, [String? name]) num
This has been renamed coerceValue for consistency with coerceToMatch, coerceValueToMatch, convertToMatch, and convertValueToMatch.
@Deprecated("Use coerceValue instead.")
withListContents(Iterable<Value> contents, {ListSeparator? separator, bool? brackets}) SassList
Returns a new list containing contents that defaults to this value's separator and brackets.
inherited

Operators

operator ==(Object other) bool
The equality operator.
override

Constants

precision → const int
The number of distinct digits that are emitted when converting a number to CSS.
10