Refactor supplement intake handling to support fractional units and update notification service initialization for Linux

This commit is contained in:
2025-08-26 01:35:43 +02:00
parent 05a9d13164
commit e6181add08
7 changed files with 127 additions and 54 deletions

View File

@@ -133,7 +133,7 @@ class SupplementsListScreen extends StatelessWidget {
context: context,
builder: (context) => StatefulBuilder(
builder: (context, setState) {
final units = int.tryParse(unitsController.text) ?? supplement.numberOfUnits;
final units = double.tryParse(unitsController.text) ?? supplement.numberOfUnits.toDouble();
final totalDosage = supplement.dosageAmount * units;
return AlertDialog(
@@ -146,7 +146,7 @@ class SupplementsListScreen extends StatelessWidget {
Expanded(
child: TextField(
controller: unitsController,
keyboardType: TextInputType.number,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
decoration: InputDecoration(
labelText: 'Number of ${supplement.unitType}',
border: const OutlineInputBorder(),
@@ -175,7 +175,7 @@ class SupplementsListScreen extends StatelessWidget {
),
),
Text(
'${totalDosage.toStringAsFixed(1)} ${supplement.unit}',
'${totalDosage.toStringAsFixed(totalDosage % 1 == 0 ? 0 : 1)} ${supplement.unit}',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
@@ -203,7 +203,7 @@ class SupplementsListScreen extends StatelessWidget {
),
ElevatedButton(
onPressed: () {
final unitsTaken = int.tryParse(unitsController.text) ?? supplement.numberOfUnits;
final unitsTaken = double.tryParse(unitsController.text) ?? supplement.numberOfUnits.toDouble();
final totalDosageTaken = supplement.dosageAmount * unitsTaken;
context.read<SupplementProvider>().recordIntake(
supplement.id!,