Files
recipe_journal/lib/constants/cooking_units.dart

192 lines
3.7 KiB
Dart

import 'package:flutter/material.dart';
import '../models/unit.dart' show Unit;
import '../src/enums.dart';
abstract class CookingUnits {
// Fluid volume units
static Unit get teaspoon => Unit(
'teaspoon',
UnitType.fluid,
system: System.imperial,
);
static Unit get tablespoon => Unit(
'tablespoon',
UnitType.fluid,
system: System.imperial,
);
static Unit get fluidOunce => Unit(
'fluid ounce',
UnitType.fluid,
system: System.imperial,
);
static Unit get cup => Unit(
'cup',
UnitType.fluid,
system: System.imperial,
);
static Unit get pint => Unit(
'pint',
UnitType.fluid,
system: System.imperial,
);
static Unit get quart => Unit(
'quart',
UnitType.fluid,
system: System.imperial,
);
static Unit get gallon => Unit(
'gallon',
UnitType.fluid,
system: System.imperial,
);
static Unit get milliliter => Unit(
'milliliter',
UnitType.fluid,
);
static Unit get liter => Unit(
'liter',
UnitType.fluid,
);
// Weight units
static Unit get ounce => Unit(
'ounce',
UnitType.weight,
system: System.imperial,
);
static Unit get pound => Unit(
'pound',
UnitType.weight,
system: System.imperial,
);
static Unit get gram => Unit(
'gram',
UnitType.weight,
);
static Unit get kilogram => Unit(
'kilogram',
UnitType.weight,
);
// Count units
static Unit get piece => Unit(
'piece',
UnitType.count,
system: System.neutral,
);
static Unit get dozen => Unit(
'dozen',
UnitType.count,
system: System.neutral,
);
// Informal units
static Unit get pinch => Unit(
'pinch',
UnitType.count,
system: System.neutral,
);
static Unit get dash => Unit(
'dash',
UnitType.count,
system: System.neutral,
);
static Unit get drop => Unit(
'drop',
UnitType.fluid,
system: System.neutral,
);
static Unit get stick => Unit(
'stick',
UnitType.count,
system: System.neutral,
);
static Unit get can => Unit(
'can',
UnitType.count,
system: System.neutral,
);
static Unit get batch => Unit(
'batch',
UnitType.count,
system: System.neutral,
);
static Unit get handful => Unit(
'handful',
UnitType.count,
system: System.neutral,
);
/// returns english abbreviation if available, else empty String
static String getUnitAbbreviation(BuildContext context, Unit unit) {
final abbreviations = {
'teaspoon': 'tsp',
'tablespoon': 'tbsp',
'fluid ounce': 'fl oz',
'cup': 'c',
'pint': 'pt',
'quart': 'qt',
'gallon': 'gal',
'milliliter': 'ml',
'liter': 'l',
'ounce': 'oz',
'pound': 'lb',
'gram': 'g',
'kilogram': 'kg',
};
return abbreviations[unit.name] ?? '';
}
static List<Unit> get values => [
teaspoon,
tablespoon,
fluidOunce,
cup,
pint,
quart,
gallon,
milliliter,
liter,
ounce,
pound,
gram,
kilogram,
piece,
dozen,
pinch,
dash,
drop,
stick,
can,
batch,
handful,
];
static List<Unit> getByType(UnitType type) {
return values.where((unit) => unit.type == type).toList();
}
static List<Unit> getBySystem(System system) {
return values.where((unit) => unit.system == system).toList();
}
}