Skip to content

Commit

Permalink
Round calories + protein in entries
Browse files Browse the repository at this point in the history
They are calculated values so the # of
decimals can get rediculous
  • Loading branch information
brandonp2412 committed May 31, 2024
1 parent a027f52 commit 418aba7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/edit_entry_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class _EditEntryPageState extends State<EditEntryPage> {
setState(() {
_nameController?.text = food.name;
_selectedFood = food;
_caloriesController.text = food.calories?.toString() ?? "";
_proteinController.text = food.proteinG?.toString() ?? "0";
_caloriesController.text = food.calories?.toStringAsFixed(2) ?? "";
_proteinController.text = food.proteinG?.toStringAsFixed(2) ?? "0";
_kilojoulesController.text = food.calories == null
? ''
: (food.calories! * 4.184).toStringAsFixed(2);
Expand Down Expand Up @@ -198,8 +198,9 @@ class _EditEntryPageState extends State<EditEntryPage> {
);

setState(() {
_caloriesController.text = entry.kCalories.value.toString();
_proteinController.text = entry.proteinG.value.toString();
_caloriesController.text =
entry.kCalories.value?.toStringAsFixed(2) ?? "0";
_proteinController.text = entry.proteinG.value?.toStringAsFixed(2) ?? "0";
_kilojoulesController.text =
((entry.kCalories.value ?? 0) * 4.184).toStringAsFixed(2);
});
Expand Down

0 comments on commit 418aba7

Please sign in to comment.