mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Search ingredients and exercises in the current locale
This commit is contained in:
@@ -149,14 +149,17 @@ class Exercises extends WgerBaseProvider with ChangeNotifier {
|
||||
///
|
||||
/// We could do this locally, but the server has better text searching capabilities
|
||||
/// with postgresql.
|
||||
Future<List> searchExercise(String name) async {
|
||||
Future<List> searchExercise(String name, [String languageCode = 'en']) async {
|
||||
if (name.length <= 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Send the request
|
||||
final response = await client.get(
|
||||
makeUrl(_exerciseSearchPath, query: {'term': name}),
|
||||
makeUrl(
|
||||
_exerciseSearchPath,
|
||||
query: {'term': name, 'language': languageCode},
|
||||
),
|
||||
headers: <String, String>{
|
||||
'Authorization': 'Token ${auth.token}',
|
||||
'User-Agent': 'wger Workout Manager App',
|
||||
|
||||
@@ -268,14 +268,17 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
/// Searches for an ingredient
|
||||
Future<List> searchIngredient(String name) async {
|
||||
Future<List> searchIngredient(String name, [String languageCode = 'en']) async {
|
||||
if (name.length <= 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Send the request
|
||||
final response = await client.get(
|
||||
makeUrl(_ingredientSearchPath, query: {'term': name}),
|
||||
makeUrl(
|
||||
_ingredientSearchPath,
|
||||
query: {'term': name, 'language': languageCode},
|
||||
),
|
||||
headers: <String, String>{
|
||||
HttpHeaders.authorizationHeader: 'Token ${auth.token}',
|
||||
HttpHeaders.userAgentHeader: 'wger Workout Manager App',
|
||||
|
||||
@@ -27,6 +27,7 @@ import 'package:wger/models/nutrition/meal.dart';
|
||||
import 'package:wger/models/nutrition/meal_item.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/screens/nutritional_plan_screen.dart';
|
||||
|
||||
class MealForm extends StatelessWidget {
|
||||
late Meal _meal;
|
||||
@@ -122,8 +123,10 @@ class MealItemForm extends StatelessWidget {
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.ingredient),
|
||||
),
|
||||
suggestionsCallback: (pattern) async {
|
||||
return await Provider.of<Nutrition>(context, listen: false)
|
||||
.searchIngredient(pattern);
|
||||
return await Provider.of<Nutrition>(context, listen: false).searchIngredient(
|
||||
pattern,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
},
|
||||
itemBuilder: (context, dynamic suggestion) {
|
||||
return ListTile(
|
||||
@@ -230,7 +233,6 @@ class PlanForm extends StatelessWidget {
|
||||
|
||||
// Saving was successful, reset the data
|
||||
_descriptionController.clear();
|
||||
_plan = NutritionalPlan.empty();
|
||||
} on WgerHttpException catch (error) {
|
||||
showHttpExceptionErrorDialog(error, context);
|
||||
} catch (error) {
|
||||
|
||||
@@ -282,7 +282,10 @@ class _SetFormWidgetState extends State<SetFormWidget> {
|
||||
helperText: AppLocalizations.of(context)!.selectExercises),
|
||||
),
|
||||
suggestionsCallback: (pattern) async {
|
||||
return await Provider.of<Exercises>(context, listen: false).searchExercise(pattern);
|
||||
return await Provider.of<Exercises>(context, listen: false).searchExercise(
|
||||
pattern,
|
||||
Localizations.localeOf(context).languageCode,
|
||||
);
|
||||
},
|
||||
itemBuilder: (context, suggestion) {
|
||||
final result = suggestion! as Map;
|
||||
|
||||
Reference in New Issue
Block a user