|
@@ -0,0 +1,28 @@
|
|
|
+import 'package:vid/us/vid_us_unit.dart';
|
|
|
+
|
|
|
+abstract class UnitMapBase {
|
|
|
+ Map<VidUsUnit, double>? _map;
|
|
|
+ final VidUsUnit unit;
|
|
|
+
|
|
|
+ UnitMapBase(this.unit);
|
|
|
+
|
|
|
+ Map<VidUsUnit, double> get map {
|
|
|
+ _map ??= <VidUsUnit, double>{};
|
|
|
+ return _map!;
|
|
|
+ }
|
|
|
+
|
|
|
+ void initMap();
|
|
|
+
|
|
|
+ void add(VidUsUnit target, double scale) {
|
|
|
+ map[target] = scale;
|
|
|
+ }
|
|
|
+
|
|
|
+ double convert(VidUsUnit target, double value) {
|
|
|
+ if (map.containsKey(target)) {
|
|
|
+ final scale = map[target]!;
|
|
|
+ final result = value / scale;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+}
|