-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.dart
30 lines (27 loc) · 855 Bytes
/
utils.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import 'package:flutter/material.dart';
import 'package:waterledger/constants/constants.dart';
double applyUnitsConversion(Units currentUnits, Units newUnits, double amount) {
if ((currentUnits == Units.FLOZ && newUnits == Units.FLOZ) ||
(currentUnits == Units.ML && newUnits == Units.ML)) {
return amount;
}
if (currentUnits == Units.FLOZ && newUnits == Units.ML) {
return amount * FLOZ_ML_RATIO;
}
if (newUnits == Units.FLOZ && currentUnits == Units.ML) {
return amount / FLOZ_ML_RATIO;
}
throw "something went wrong";
}
String unitToString(Units units) {
if (units == Units.FLOZ) {
return "FL oz.";
}
if (units == Units.ML) {
return "ML";
}
throw "Incorrect units";
}
int getElapsedTime(TimeOfDay start, TimeOfDay end) {
return ((end.hour - start.hour) % 24) * 60 + (end.minute - start.minute);
}