Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/images/barcode_scanner_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 39 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -507,5 +507,43 @@
"description": "Snackbar message to show on copying data to a new log entry"
},
"appUpdateTitle" : "Update needed",
"appUpdateContent" : "This version of the app is not compatible with the server, please update your application."
"appUpdateContent" : "This version of the app is not compatible with the server, please update your application.",

"productFound": "Product found",
"@productFound": {
"description": "Header label for dialog when product is found with barcode"
},

"productFoundDescription": "The barcode corresponds to this product: \n {productName} \nDo you want to continue ?",
"@productFoundDescription": {
"description": "Dialog info when product is found with barcode",
"type": "text",
"placeholders": {
"productName": {}
}
},

"productNotFound": "Product not found",
"@productNotFound": {
"description": "Header label for dialog when product is not found with barcode"
},

"productNotFoundDescription": "Product with scanned barcode ({barcode}) was not found.",
"@productNotFoundDescription": {
"description": "Dialog info when product is not found with barcode",
"type": "text",
"placeholders": {
"barcode": {}
}
},

"scanBarcode": "Scan barcode",
"@scanBarcode": {
"description": "Label for scan barcode button"
},

"close": "Close",
"@close": {
"description": "Translation for close"
}
}
3 changes: 2 additions & 1 deletion lib/models/body_weight/weight_entry.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/models/exercises/category.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions lib/models/exercises/exercise.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/models/exercises/image.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/models/measurements/measurement_category.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/models/measurements/measurement_entry.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/models/nutrition/ingredient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class Ingredient {
@JsonKey(required: true)
final int id;

/// Barcode of the product
@JsonKey(required: true)
final String code;

/// Name of the product
@JsonKey(required: true)
final String name;
Expand Down Expand Up @@ -66,6 +70,7 @@ class Ingredient {

const Ingredient({
required this.id,
required this.code,
required this.name,
required this.creationDate,
required this.energy,
Expand Down
6 changes: 5 additions & 1 deletion lib/models/nutrition/ingredient.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/models/nutrition/ingredient_weight_unit.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion lib/models/nutrition/log.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/models/nutrition/nutritional_plan.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/models/nutrition/weight_unit.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/models/workouts/repetition_unit.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions lib/models/workouts/session.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/models/workouts/weight_unit.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/models/workouts/workout_plan.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions lib/providers/nutrition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,28 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
return json.decode(utf8.decode(response.bodyBytes))['suggestions'] as List<dynamic>;
}

/// Searches for an ingredient with code
Future<Ingredient?> searchIngredientWithCode(String code) async {

if (code.isEmpty ) {
return null;
}

// Send the request
final data = await fetch(
makeUrl(
_ingredientPath,
query: {'code': code},
),
);

if(data["count"]==0){
return null;
}else{
return Ingredient.fromJson(data['results'][0]);
}
}

/// Log meal to nutrition diary
Future<void> logMealToDiary(Meal meal) async {
for (final item in meal.mealItems) {
Expand Down
17 changes: 14 additions & 3 deletions lib/widgets/nutrition/forms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:provider/provider.dart';
import 'package:wger/exceptions/http_exception.dart';
Expand Down Expand Up @@ -116,17 +117,25 @@ class MealItemForm extends StatelessWidget {
final Meal _meal;
late final MealItem _mealItem;
final List<MealItem> _listMealItems;
late String _barcode;
late bool _test;

final _form = GlobalKey<FormState>();
final _ingredientIdController = TextEditingController();
final _ingredientController = TextEditingController();
final _amountController = TextEditingController();

MealItemForm(this._meal, this._listMealItems, [mealItem]) {
MealItemForm(this._meal, this._listMealItems, [mealItem, code, test]) {
_mealItem = mealItem ?? MealItem.empty();
_test = test ?? false;
_barcode = code ?? '';
_mealItem.mealId = _meal.id!;
}

TextEditingController get ingredientIdController => _ingredientIdController;

MealItem get mealItem => _mealItem;

@override
Widget build(BuildContext context) {
final String unit = AppLocalizations.of(context).g;
Expand All @@ -136,8 +145,9 @@ class MealItemForm extends StatelessWidget {
key: _form,
child: Column(
children: [
IngredientTypeahead(_ingredientIdController, _ingredientController),
IngredientTypeahead(_ingredientIdController, _ingredientController, true, _barcode, _test, ),
TextFormField(
key: const Key('field-weight'),
decoration: InputDecoration(labelText: AppLocalizations.of(context).weight),
controller: _amountController,
keyboardType: TextInputType.number,
Expand All @@ -155,6 +165,7 @@ class MealItemForm extends StatelessWidget {
},
),
ElevatedButton(
key: const Key(SUBMIT_BUTTON_KEY_NAME),
child: Text(AppLocalizations.of(context).save),
onPressed: () async {
if (!_form.currentState!.validate()) {
Expand Down Expand Up @@ -235,7 +246,7 @@ class IngredientLogForm extends StatelessWidget {
key: _form,
child: Column(
children: [
IngredientTypeahead(_ingredientIdController, _ingredientController),
IngredientTypeahead(_ingredientIdController, _ingredientController, true, '', false,),
TextFormField(
decoration: InputDecoration(labelText: AppLocalizations.of(context).weight),
controller: _amountController,
Expand Down
Loading