From 530efd366e3ad23b2b799cc4ddbae638ca3b2eb2 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Wed, 24 Sep 2025 12:31:28 +0200 Subject: [PATCH] Some renaming --- lib/providers/nutrition.dart | 3 +-- lib/widgets/nutrition/forms.dart | 4 ++-- lib/widgets/nutrition/widgets.dart | 15 +++++++-------- test/core/settings_test.mocks.dart | 2 +- .../nutritional_meal_form_test.mocks.dart | 2 +- .../nutritional_meal_item_form_test.dart | 7 ++++--- .../nutritional_plan_form_test.mocks.dart | 2 +- test/weight/weight_screen_test.mocks.dart | 2 +- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index 1d83fc87..b3f84063 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -392,7 +392,7 @@ class NutritionPlansProvider with ChangeNotifier { } /// Searches for an ingredient with bar code - Future searchIngredientWithCode(String barcode) async { + Future searchIngredientWithBarcode(String barcode) async { if (barcode.isEmpty) { return null; } @@ -406,7 +406,6 @@ class NutritionPlansProvider with ChangeNotifier { return null; } // TODO we should probably add it to ingredient cache. - // TODO: we could also use the ingredient cache for code searches return Ingredient.fromJson(data['results'][0]); } diff --git a/lib/widgets/nutrition/forms.dart b/lib/widgets/nutrition/forms.dart index 0c4c347e..ad31917e 100644 --- a/lib/widgets/nutrition/forms.dart +++ b/lib/widgets/nutrition/forms.dart @@ -252,8 +252,8 @@ class IngredientFormState extends State { barcode: widget.barcode, test: widget.test, selectIngredient: selectIngredient, - unSelectIngredient: unSelectIngredient, - updateSearchQuery: updateSearchQuery, + onDeselectIngredient: unSelectIngredient, + onUpdateSearchQuery: updateSearchQuery, ), Row( children: [ diff --git a/lib/widgets/nutrition/widgets.dart b/lib/widgets/nutrition/widgets.dart index 0ac2b489..8b7a95ff 100644 --- a/lib/widgets/nutrition/widgets.dart +++ b/lib/widgets/nutrition/widgets.dart @@ -64,8 +64,8 @@ class IngredientTypeahead extends StatefulWidget { final bool showScanner; final Function(int id, String name, num? amount) selectIngredient; - final Function() unSelectIngredient; - final Function(String query) updateSearchQuery; + final Function() onDeselectIngredient; + final Function(String query) onUpdateSearchQuery; IngredientTypeahead( this._ingredientIdController, @@ -74,8 +74,8 @@ class IngredientTypeahead extends StatefulWidget { this.test = false, this.barcode = '', required this.selectIngredient, - required this.unSelectIngredient, - required this.updateSearchQuery, + required this.onDeselectIngredient, + required this.onUpdateSearchQuery, }); @override @@ -142,9 +142,8 @@ class _IngredientTypeaheadState extends State { return null; } - widget.updateSearchQuery(pattern); - // unselect to start a new search - widget.unSelectIngredient(); + widget.onUpdateSearchQuery(pattern); + widget.onDeselectIngredient(); return Provider.of(context, listen: false).searchIngredient( pattern, @@ -219,7 +218,7 @@ class _IngredientTypeaheadState extends State { context: context, builder: (context) => FutureBuilder( future: Provider.of(context, listen: false) - .searchIngredientWithCode(barcode), + .searchIngredientWithBarcode(barcode), builder: (BuildContext context, AsyncSnapshot snapshot) { return IngredientScanResultDialog(snapshot, barcode, widget.selectIngredient); }, diff --git a/test/core/settings_test.mocks.dart b/test/core/settings_test.mocks.dart index c07d70de..bad6f310 100644 --- a/test/core/settings_test.mocks.dart +++ b/test/core/settings_test.mocks.dart @@ -1007,7 +1007,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i20.NutritionPlans ) as _i18.Future>); @override - _i18.Future<_i13.Ingredient?> searchIngredientWithCode(String? barcode) => (super.noSuchMethod( + _i18.Future<_i13.Ingredient?> searchIngredientWithBarcode(String? barcode) => (super.noSuchMethod( Invocation.method( #searchIngredientWithCode, [barcode], diff --git a/test/nutrition/nutritional_meal_form_test.mocks.dart b/test/nutrition/nutritional_meal_form_test.mocks.dart index 409670f2..8f61b4fc 100644 --- a/test/nutrition/nutritional_meal_form_test.mocks.dart +++ b/test/nutrition/nutritional_meal_form_test.mocks.dart @@ -412,7 +412,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP ) as _i9.Future>); @override - _i9.Future<_i7.Ingredient?> searchIngredientWithCode(String? barcode) => (super.noSuchMethod( + _i9.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) => (super.noSuchMethod( Invocation.method( #searchIngredientWithCode, [barcode], diff --git a/test/nutrition/nutritional_meal_item_form_test.dart b/test/nutrition/nutritional_meal_item_form_test.dart index 20740beb..224dc53e 100644 --- a/test/nutrition/nutritional_meal_item_form_test.dart +++ b/test/nutrition/nutritional_meal_item_form_test.dart @@ -70,9 +70,10 @@ void main() { final MealItem mealItem = MealItem(ingredientId: ingredient.id, amount: 2); mockNutrition = MockNutritionPlansProvider(); - when(mockNutrition.searchIngredientWithCode('123')).thenAnswer((_) => Future.value(ingredient)); - when(mockNutrition.searchIngredientWithCode('')).thenAnswer((_) => Future.value(null)); - when(mockNutrition.searchIngredientWithCode('222')).thenAnswer((_) => Future.value(null)); + when(mockNutrition.searchIngredientWithBarcode('123')) + .thenAnswer((_) => Future.value(ingredient)); + when(mockNutrition.searchIngredientWithBarcode('')).thenAnswer((_) => Future.value(null)); + when(mockNutrition.searchIngredientWithBarcode('222')).thenAnswer((_) => Future.value(null)); when(mockNutrition.searchIngredient( any, languageCode: anyNamed('languageCode'), diff --git a/test/nutrition/nutritional_plan_form_test.mocks.dart b/test/nutrition/nutritional_plan_form_test.mocks.dart index f71cd721..979f854f 100644 --- a/test/nutrition/nutritional_plan_form_test.mocks.dart +++ b/test/nutrition/nutritional_plan_form_test.mocks.dart @@ -412,7 +412,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP ) as _i9.Future>); @override - _i9.Future<_i7.Ingredient?> searchIngredientWithCode(String? barcode) => (super.noSuchMethod( + _i9.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) => (super.noSuchMethod( Invocation.method( #searchIngredientWithCode, [barcode], diff --git a/test/weight/weight_screen_test.mocks.dart b/test/weight/weight_screen_test.mocks.dart index c344ffa4..7e1e2737 100644 --- a/test/weight/weight_screen_test.mocks.dart +++ b/test/weight/weight_screen_test.mocks.dart @@ -737,7 +737,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i16.NutritionPlans ) as _i11.Future>); @override - _i11.Future<_i9.Ingredient?> searchIngredientWithCode(String? barcode) => (super.noSuchMethod( + _i11.Future<_i9.Ingredient?> searchIngredientWithBarcode(String? barcode) => (super.noSuchMethod( Invocation.method( #searchIngredientWithCode, [barcode],