FuelConsumption class final
Represents fuel consumption and fuel economy.
FuelConsumption is an inverse quantity. Its conversions route through an internal canonical form of liters per kilometer, and it intentionally does not expose generic arithmetic operators.
The "50 mpg < 25 mpg" Paradox
Because this class fundamentally represents fuel consumption (volume of fuel consumed per given distance, e.g., L/100km), its internal magnitude increases as efficiency decreases.
As a result, comparing fuel economy units like MPG operates mathematically on the underlying consumed volume. A vehicle getting 50 MPG consumes less fuel than one getting 25 MPG. Therefore, its physical magnitude is smaller:
print(50.mpg < 25.mpg); // true
Sorting Behavior: If you call .sort() on a List<FuelConsumption>,
the list will naturally sort from most efficient (lowest consumption,
highest MPG) to least efficient (highest consumption, lowest MPG).
- Inheritance
-
- Object
- Quantity<
FuelConsumptionUnit> - InverseQuantity<
FuelConsumptionUnit, FuelConsumption> - FuelConsumption
- Available extensions
- Annotations
-
- @immutable
Constructors
- FuelConsumption(double _value, FuelConsumptionUnit _unit)
-
Creates a new FuelConsumption with the given value and unit.
const
Properties
- asKmPerL → FuelConsumption
-
Available on FuelConsumption, provided by the FuelConsumptionValueGetters extension
Returns a FuelConsumption converted to kilometers per liter.no setter - asLPer100Km → FuelConsumption
-
Available on FuelConsumption, provided by the FuelConsumptionValueGetters extension
Returns a FuelConsumption converted to liters per 100 kilometers.no setter - asMpgUk → FuelConsumption
-
Available on FuelConsumption, provided by the FuelConsumptionValueGetters extension
Returns a FuelConsumption converted to miles per imperial gallon.no setter - asMpgUs → FuelConsumption
-
Available on FuelConsumption, provided by the FuelConsumptionValueGetters extension
Returns a FuelConsumption converted to miles per US gallon.no setter - comparisonValue → double
-
Returns this quantity expressed in a fixed comparison space whose
ordering is monotonic with the underlying physical magnitude.
no setteroverride
- hashCode → int
-
Returns a hash code for this
Quantityinstance.no setterinherited - inKmPerL → double
-
Available on FuelConsumption, provided by the FuelConsumptionValueGetters extension
Returns the fuel economy value in kilometers per liter.no setter - inLPer100Km → double
-
Available on FuelConsumption, provided by the FuelConsumptionValueGetters extension
Returns the fuel consumption value in liters per 100 kilometers.no setter - inMpgUk → double
-
Available on FuelConsumption, provided by the FuelConsumptionValueGetters extension
Returns the fuel economy value in miles per imperial gallon.no setter - inMpgUs → double
-
Available on FuelConsumption, provided by the FuelConsumptionValueGetters extension
Returns the fuel economy value in miles per US gallon.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- unit → FuelConsumptionUnit
-
Returns the unit of measurement associated with this quantity's original value.
no setterinherited
- value → double
-
Returns the numerical value of this quantity in its original unit.
no setterinherited
Methods
-
compareTo(
Quantity< FuelConsumptionUnit> other) → int -
Compares inverse quantities in a fixed monotonic comparison space.
inherited
-
convertTo(
FuelConsumptionUnit targetUnit) → FuelConsumption -
Creates a new
Qinstance with the value converted totargetUnit.inherited -
create(
double value, FuelConsumptionUnit unit) → FuelConsumption -
Factory that creates a new instance of the concrete subtype
Q.override -
getValue(
FuelConsumptionUnit targetUnit) → double -
Converts this fuel consumption value to
targetUnit.override -
isEquivalentTo(
Quantity< FuelConsumptionUnit> other, {double tolerance = 1e-9, double absoluteTolerance = 0.0}) → bool -
Checks if this quantity has the same physical magnitude as another,
accounting for IEEE 754 floating-point rounding inaccuracies.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
{FuelConsumptionUnit? targetUnit, QuantityFormat format = QuantityFormat.invariant}) → String -
Returns a string representation of this quantity.
inherited
Operators
-
operator <(
Quantity< FuelConsumptionUnit> other) → bool -
Checks if this quantity's magnitude is less than another's.
inherited
-
operator <=(
Quantity< FuelConsumptionUnit> other) → bool -
Checks if this quantity's magnitude is less than or equal to another's.
inherited
-
operator ==(
Object other) → bool -
Determines whether this Quantity is equal to another Object.
inherited
-
operator >(
Quantity< FuelConsumptionUnit> other) → bool -
Checks if this quantity's magnitude is greater than another's.
inherited
-
operator >=(
Quantity< FuelConsumptionUnit> other) → bool -
Checks if this quantity's magnitude is greater than or equal to another's.
inherited
Static Properties
-
parser
→ QuantityParser<
FuelConsumptionUnit, FuelConsumption> -
The parser instance used to convert strings into FuelConsumption.
final
Static Methods
-
parse(
String input, {List< QuantityFormat> formats = const [QuantityFormat.invariant]}) → FuelConsumption - Parses a string representation of fuel consumption into a FuelConsumption.
-
tryParse(
String input, {List< QuantityFormat> formats = const [QuantityFormat.invariant]}) → FuelConsumption? -
Parses a string representation of fuel consumption, returning
nullon failure.