diff --git a/lib/food_entry/food_entry_bloc.dart b/lib/food_entry/food_entry_bloc.dart index acf2071..f40cbf5 100644 --- a/lib/food_entry/food_entry_bloc.dart +++ b/lib/food_entry/food_entry_bloc.dart @@ -123,15 +123,17 @@ class FoodEntryBloc extends Bloc { void handleFoodEntryTapped( FoodEntryTapped event, Emitter emit) async { + var oldStateOfTappedEntry = event.entry.isSelected; + for (var entry in state.foodEntries) { entry.isSelected = false; } var selectedEntry = state.foodEntries.firstWhere((entry) { - return entry.id == event.entryID; + return entry.id == event.entry.id; }); - selectedEntry.selected = !selectedEntry.selected; + selectedEntry.isSelected = !oldStateOfTappedEntry; emit(PageState(foodEntries: state.foodEntries)); } @@ -164,9 +166,9 @@ class BarcodeScanned extends FoodEvent { } class FoodEntryTapped extends FoodEvent { - final String entryID; + final FoodEntryState entry; - FoodEntryTapped({required this.entryID}); + FoodEntryTapped({required this.entry}); } /// This is the state for one date/page @@ -223,9 +225,6 @@ class FoodEntryState { required this.isSelected, }); - set selected(bool selected) => isSelected = selected; - bool get selected => isSelected; - @override String toString() { //we use quotation marks around the name because the name might contain diff --git a/lib/food_entry/food_entry_widget.dart b/lib/food_entry/food_entry_widget.dart index 49bda5e..9027346 100644 --- a/lib/food_entry/food_entry_widget.dart +++ b/lib/food_entry/food_entry_widget.dart @@ -78,25 +78,6 @@ class _FoodEntryWidgetState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - SizedBox( - child: IconButton( - padding: const EdgeInsets.all(0.0), - icon: const Icon(Icons.cancel), - onPressed: widget.entry.isSelected - ? widget.onTap(context, widget.entry) - : null, - ), - ), - SizedBox( - child: IconButton( - padding: const EdgeInsets.all(0.0), - iconSize: 24, - icon: const Icon(Icons.delete), - color: Colors.redAccent, - onPressed: widget.entry.isSelected - ? () => widget.onDelete(context, widget.entry.id) - : null), - ), SizedBox( child: IconButton( padding: const EdgeInsets.all(0.0), @@ -117,6 +98,16 @@ class _FoodEntryWidgetState extends State { } : null), ), + SizedBox( + child: IconButton( + padding: const EdgeInsets.all(0.0), + iconSize: 24, + icon: const Icon(Icons.delete), + color: Colors.redAccent, + onPressed: widget.entry.isSelected + ? () => widget.onDelete(context, widget.entry.id) + : null), + ), ], ), ), diff --git a/lib/perdate/entry_list.dart b/lib/perdate/entry_list.dart index 384808a..5208ea8 100644 --- a/lib/perdate/entry_list.dart +++ b/lib/perdate/entry_list.dart @@ -52,7 +52,7 @@ class FoodEntryList extends StatelessWidget { onTap: (_, tappedEntry) { context .read() - .add(FoodEntryTapped(entryID: tappedEntry.id)); + .add(FoodEntryTapped(entry: tappedEntry)); }, ), const Divider(),