Open PackRuble opened 7 months ago
I found a great solution!
The units of measurement of the fields will be according to the model field UnitsMeasure units
:
class WeatherCurrent {
// in those units represented in `units`
final double temp;
final UnitsMeasure units;
}
class UnitsMeasure {
final Temp temp;
final Speed speed;
// ...
}
And to convert model into the required units, just use the copyWith(units: newUnits)
method.
Currently, weather models have fields in standard units of measurement. This
Kelvin
meter/sec
hPa
Using weather model fields can be quite inconvenient at the moment:
There are perhaps a great number of solutions to this boilerplate. It comes to mind:
double
(and other) types, so that it looks like this:However, this option is not very successful because it does not take into account the
tempUnits
parameter (imagine that the user has selected the desired units of measurement in the settings)similar option with new extension types (in Dart 3.3.0)
use some additional state field where to collect the units of measurement of all quantities
In addition, make this field changeable (right now our models are intentionally immutable, then we can play
copyWith
to change only the parameter of this state). I like this option the best as it elegantly allows you to do everything. I don't see any restrictions.This change will also affect #12