Hello! I’m working on the analysis of a meteorological API, and I wanted to do drought calculations.
For this I needed to look for a week’s worth of data so I could then calculate the average, the standard deviation and finally the precipitation index. So I’m using several packages, in this case the problem is the incompatibility between statistics and intl, I use statistics to calculate the averages and the standard deviation, and intl to be able to separate the date from the hours when analyzing the API.
The error appears when implementing the packages, since statistics and most of the other libraries I use have null safety but intl does not.
How can I solve this? What other alternatives to intl exist?
If you visit the pub.dev page intl | Dart package
You’ll see a tag Dart 3 compatible.
You may have some automatic resolution of old packages that block the update.
Specify the last version, intl 0.20.1 to update it.
Statistics too is compatible.
3 Likes
If you’re using intl for extracting the time only you can simply write your own data class or extension.
Like this:
void main() {
final t = Time.fromDateTime(DateTime.now());
print(t); // -> 03:02:02:0131
}
class Time {
const Time({
this.hour = 0,
this.minute = 0,
this.second = 0,
this.millisecond = 0,
});
final int hour;
final int minute;
final int second;
final int millisecond;
factory Time.fromDateTime(DateTime dt) {
return Time(
hour: dt.hour,
minute: dt.minute,
second: dt.second,
millisecond: dt.millisecond,
);
}
@override
String toString() {
return '${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}:${second.toString().padLeft(2, '0')}:${millisecond.toString().padLeft(4, '0')}';
}
}