Some renaming

This commit is contained in:
Roland Geider
2025-09-24 12:31:28 +02:00
parent 5f7116ca92
commit 530efd366e
8 changed files with 18 additions and 19 deletions

View File

@@ -392,7 +392,7 @@ class NutritionPlansProvider with ChangeNotifier {
}
/// Searches for an ingredient with bar code
Future<Ingredient?> searchIngredientWithCode(String barcode) async {
Future<Ingredient?> 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]);
}

View File

@@ -252,8 +252,8 @@ class IngredientFormState extends State<IngredientForm> {
barcode: widget.barcode,
test: widget.test,
selectIngredient: selectIngredient,
unSelectIngredient: unSelectIngredient,
updateSearchQuery: updateSearchQuery,
onDeselectIngredient: unSelectIngredient,
onUpdateSearchQuery: updateSearchQuery,
),
Row(
children: [

View File

@@ -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<IngredientTypeahead> {
return null;
}
widget.updateSearchQuery(pattern);
// unselect to start a new search
widget.unSelectIngredient();
widget.onUpdateSearchQuery(pattern);
widget.onDeselectIngredient();
return Provider.of<NutritionPlansProvider>(context, listen: false).searchIngredient(
pattern,
@@ -219,7 +218,7 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
context: context,
builder: (context) => FutureBuilder<Ingredient?>(
future: Provider.of<NutritionPlansProvider>(context, listen: false)
.searchIngredientWithCode(barcode),
.searchIngredientWithBarcode(barcode),
builder: (BuildContext context, AsyncSnapshot<Ingredient?> snapshot) {
return IngredientScanResultDialog(snapshot, barcode, widget.selectIngredient);
},

View File

@@ -1007,7 +1007,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i20.NutritionPlans
) as _i18.Future<List<_i13.Ingredient>>);
@override
_i18.Future<_i13.Ingredient?> searchIngredientWithCode(String? barcode) => (super.noSuchMethod(
_i18.Future<_i13.Ingredient?> searchIngredientWithBarcode(String? barcode) => (super.noSuchMethod(
Invocation.method(
#searchIngredientWithCode,
[barcode],

View File

@@ -412,7 +412,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
) as _i9.Future<List<_i7.Ingredient>>);
@override
_i9.Future<_i7.Ingredient?> searchIngredientWithCode(String? barcode) => (super.noSuchMethod(
_i9.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) => (super.noSuchMethod(
Invocation.method(
#searchIngredientWithCode,
[barcode],

View File

@@ -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'),

View File

@@ -412,7 +412,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP
) as _i9.Future<List<_i7.Ingredient>>);
@override
_i9.Future<_i7.Ingredient?> searchIngredientWithCode(String? barcode) => (super.noSuchMethod(
_i9.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) => (super.noSuchMethod(
Invocation.method(
#searchIngredientWithCode,
[barcode],

View File

@@ -737,7 +737,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i16.NutritionPlans
) as _i11.Future<List<_i9.Ingredient>>);
@override
_i11.Future<_i9.Ingredient?> searchIngredientWithCode(String? barcode) => (super.noSuchMethod(
_i11.Future<_i9.Ingredient?> searchIngredientWithBarcode(String? barcode) => (super.noSuchMethod(
Invocation.method(
#searchIngredientWithCode,
[barcode],