mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 23:42:00 +01:00
Allow deleting nutritional diary entries
This commit is contained in:
@@ -339,6 +339,13 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Deletes a log entry
|
||||
Future<void> deleteLog(int logId, int planId) async {
|
||||
final plan = findById(planId);
|
||||
plan.logs.removeWhere((element) => element.id == logId);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Load nutrition diary entries for plan
|
||||
Future<void> fetchAndSetLogs(NutritionalPlan plan) async {
|
||||
// TODO: update fetch to that it can use the pagination
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/models/nutrition/log.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/models/nutrition/nutritrional_values.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/theme/theme.dart';
|
||||
import 'package:wger/widgets/core/core.dart';
|
||||
import 'package:wger/widgets/nutrition/charts.dart';
|
||||
@@ -216,7 +218,12 @@ class NutritionalDiaryDetailWidget extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(onPressed: null, icon: Icon(Icons.edit)),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
Provider.of<NutritionPlansProvider>(context, listen: false)
|
||||
.deleteLog(log.id!, _nutritionalPlan.id!);
|
||||
},
|
||||
icon: Icon(Icons.delete_outline)),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
|
||||
Reference in New Issue
Block a user