UnitOfMeasurementFormat<TValue, TUnit> class
abstract
Base class for unit of measurement formats.
Individual formatters for units of measurement extend this class to obtain the majority of the necessary
implementation. The TValue
type represents the values being formatted. That is, the unit of measurement values or
their rated variants.
The TUnit
type (typically an enumeration) represents the valid units for that unit of measurement.
The format is specified as a pattern, which supports the following components:
Specifier | Description |
---|---|
u |
The symbol of the value's unit, automatically inferred based on the value being formatted. |
u:$UNIT_SPECIFIER |
The symbol of the value's unit, explicitly specified after the colon. |
U |
The name of the value's unit, automatically inferred based on the value being formatted. |
U:$UNIT_SPECIFIER |
The name of the value's unit, explicitly specified after the colon. |
r |
The symbol of the rate's unit (if applicable), automatically inferred based on the value being formatted. |
r:$RATE_SPECIFIER |
The symbol of the rate's unit (if applicable), explicitly specified after the colon. |
R |
The name of the rate's unit (if applicable), automatically inferred based on the value being formatted. |
R:$RATE_SPECIFIER |
The name of the rate's unit (if applicable), explicitly specified after the colon. |
' |
Used to demarcate verbatim output |
(any other character) | Forwarded onto a NumberFormat . |
Rate unit specifiers are common across all rated values:
Unit | Specifier |
---|---|
seconds | s |
minutes | min |
hours | hr |
days | day |
weeks | wk |
Value unit specifiers are specific to the unit of measurement value being formatted and can be found in the documentation for the relevant format implementation.
See also:
NumberFormat
Constructors
- UnitOfMeasurementFormat({required String pattern, String? locale})
-
Creates a unit of measurement format with the specified
pattern
andlocale
.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- locale → String?
-
The locale to use when formatting values.
final
- pattern → String
-
The pattern that indicates the desired output when formatting input values.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
format(
TValue input) → String -
Formats
input
according to the pattern and locale of this format. -
getLargestUnit(
TValue input) → TUnit -
Determines the largest denomination of unit in
input
that has a value of at least1
. -
getPatternSpecifierFor(
TUnit valueUnit) → String - Gets the pattern specifier for the given value unit.
-
getPermissibleRateUnits(
) → Set< RateUnit> - Gets a set of permissible RateUnit values.
-
getPermissibleValueUnits(
) → Set< TUnit> -
Gets a set of permissible
TUnit
values. -
getUnitName(
TUnit unit, String locale) → String -
Gets the a
unit
name in the givenlocale
. -
getUnitQuantity(
TValue input, TUnit unit) → Rational -
Determines how many units of
unit
theinput
contains, including any fractional portion. -
getUnitSymbol(
TUnit unit, String locale) → String -
Gets the a
unit
symbol in the givenlocale
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pluralizeValueUnits(
String locale) → bool -
Determines whether value units should be pluralized. Defaults to
true
. -
scaleToRateUnit(
TValue input, RateUnit rateUnit) → TValue -
Scales
input
, which is assumed to be a rated unit of measurement, so that its rate israteUnit
. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- rateUnitNameFormatSpecifier → const String
- The format specifier for a rate name.
- rateUnitSymbolFormatSpecifier → const String
- The format specifier for a rate symbol.
- valueUnitNameFormatSpecifier → const String
- The format specifier for a unit name.
- valueUnitSymbolFormatSpecifier → const String
- The format specifier for a unit symbol.