mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Rename provider
This commit is contained in:
@@ -22,7 +22,7 @@ import 'package:provider/provider.dart';
|
||||
import 'package:wger/locale/locales.dart';
|
||||
import 'package:wger/providers/body_weight.dart';
|
||||
import 'package:wger/providers/exercises.dart';
|
||||
import 'package:wger/providers/nutritional_plans.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/providers/workout_plans.dart';
|
||||
import 'package:wger/screens/auth_screen.dart';
|
||||
import 'package:wger/screens/dashboard.dart';
|
||||
@@ -64,9 +64,9 @@ class MyApp extends StatelessWidget {
|
||||
previous == null ? [] : previous.items,
|
||||
),
|
||||
),
|
||||
ChangeNotifierProxyProvider<Auth, NutritionalPlans>(
|
||||
ChangeNotifierProxyProvider<Auth, Nutrition>(
|
||||
create: null, // TODO: Create is required but it can be null??
|
||||
update: (context, auth, previous) => NutritionalPlans(
|
||||
update: (context, auth, previous) => Nutrition(
|
||||
auth,
|
||||
previous == null ? [] : previous.items,
|
||||
),
|
||||
|
||||
@@ -28,7 +28,7 @@ import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/auth.dart';
|
||||
import 'package:wger/providers/base_provider.dart';
|
||||
|
||||
class NutritionalPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
static const nutritionalPlansUrl = 'nutritionplan';
|
||||
static const nutritionalPlansInfoUrl = 'nutritionplaninfo';
|
||||
static const mealUrl = 'meal';
|
||||
@@ -40,7 +40,7 @@ class NutritionalPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
Auth _auth;
|
||||
List<NutritionalPlan> _plans = [];
|
||||
|
||||
NutritionalPlans(Auth auth, List<NutritionalPlan> entries)
|
||||
Nutrition(Auth auth, List<NutritionalPlan> entries)
|
||||
: this._plans = entries,
|
||||
super(auth, nutritionalPlansUrl);
|
||||
|
||||
@@ -22,7 +22,7 @@ import 'package:wger/helpers/ui.dart';
|
||||
import 'package:wger/locale/locales.dart';
|
||||
import 'package:wger/models/http_exception.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/nutritional_plans.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/providers/workout_plans.dart';
|
||||
import 'package:wger/widgets/app_drawer.dart';
|
||||
import 'package:wger/widgets/nutrition/nutritional_plans_list.dart';
|
||||
@@ -36,7 +36,7 @@ class NutritionScreen extends StatefulWidget {
|
||||
|
||||
class _NutritionScreenState extends State<NutritionScreen> {
|
||||
Future<void> _refreshPlans(BuildContext context) async {
|
||||
await Provider.of<NutritionalPlans>(context, listen: false).fetchAndSetPlans();
|
||||
await Provider.of<Nutrition>(context, listen: false).fetchAndSetPlans();
|
||||
}
|
||||
|
||||
final descriptionController = TextEditingController();
|
||||
@@ -116,8 +116,7 @@ class _NutritionScreenState extends State<NutritionScreen> {
|
||||
|
||||
// Save the entry on the server
|
||||
try {
|
||||
await Provider.of<NutritionalPlans>(ctx, listen: false)
|
||||
.addPlan(nutritionalPlan);
|
||||
await Provider.of<Nutrition>(ctx, listen: false).addPlan(nutritionalPlan);
|
||||
|
||||
// Saving was successful, reset the data
|
||||
descriptionController.clear();
|
||||
|
||||
@@ -20,7 +20,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/locale/locales.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/nutritional_plans.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/widgets/nutrition/nutritional_plan_detail.dart';
|
||||
|
||||
class NutritrionalPlanScreen extends StatefulWidget {
|
||||
@@ -32,7 +32,7 @@ class NutritrionalPlanScreen extends StatefulWidget {
|
||||
|
||||
class _NutritrionalPlanScreenState extends State<NutritrionalPlanScreen> {
|
||||
Future<NutritionalPlan> _loadNutritionalPlanDetail(BuildContext context, int planId) async {
|
||||
var plan = await Provider.of<NutritionalPlans>(context, listen: false).findById(planId);
|
||||
var plan = await Provider.of<Nutrition>(context, listen: false).findById(planId);
|
||||
return plan;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ class _NutritrionalPlanScreenState extends State<NutritrionalPlanScreen> {
|
||||
? Center(child: CircularProgressIndicator())
|
||||
: RefreshIndicator(
|
||||
onRefresh: () => _loadNutritionalPlanDetail(context, nutritionalPlan.id),
|
||||
child: Consumer<NutritionalPlans>(
|
||||
child: Consumer<Nutrition>(
|
||||
builder: (context, workout, _) => NutritionalPlanDetailWidget(snapshot.data),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -26,7 +26,7 @@ import 'package:wger/models/http_exception.dart';
|
||||
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/nutritional_plans.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
|
||||
class MealForm extends StatelessWidget {
|
||||
Meal meal;
|
||||
@@ -79,7 +79,7 @@ class MealForm extends StatelessWidget {
|
||||
meal.plan = _plan.id;
|
||||
|
||||
try {
|
||||
Provider.of<NutritionalPlans>(context, listen: false).addMeal(meal, _plan.id);
|
||||
Provider.of<Nutrition>(context, listen: false).addMeal(meal, _plan.id);
|
||||
} on WgerHttpException catch (error) {
|
||||
showHttpExceptionErrorDialog(error, context);
|
||||
} catch (error) {
|
||||
@@ -123,7 +123,7 @@ class MealItemForm extends StatelessWidget {
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).ingredient),
|
||||
),
|
||||
suggestionsCallback: (pattern) async {
|
||||
return await Provider.of<NutritionalPlans>(context, listen: false)
|
||||
return await Provider.of<Nutrition>(context, listen: false)
|
||||
.searchIngredient(pattern);
|
||||
},
|
||||
itemBuilder: (context, suggestion) {
|
||||
@@ -192,8 +192,7 @@ class MealItemForm extends StatelessWidget {
|
||||
try {
|
||||
mealItem.meal = meal.id;
|
||||
|
||||
Provider.of<NutritionalPlans>(context, listen: false)
|
||||
.addMealIteam(mealItem, meal.id);
|
||||
Provider.of<Nutrition>(context, listen: false).addMealIteam(mealItem, meal.id);
|
||||
} on WgerHttpException catch (error) {
|
||||
showHttpExceptionErrorDialog(error, context);
|
||||
} catch (error) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import 'package:provider/provider.dart';
|
||||
import 'package:wger/locale/locales.dart';
|
||||
import 'package:wger/models/nutrition/meal.dart';
|
||||
import 'package:wger/models/nutrition/meal_item.dart';
|
||||
import 'package:wger/providers/nutritional_plans.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/widgets/core/bottom_sheet.dart';
|
||||
import 'package:wger/widgets/nutrition/forms.dart';
|
||||
|
||||
@@ -66,15 +66,19 @@ class MealItemWidget extends StatelessWidget {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(5),
|
||||
child: Table(
|
||||
columnWidths: {
|
||||
0: FlexColumnWidth(5),
|
||||
1: FlexColumnWidth(2),
|
||||
},
|
||||
children: [
|
||||
TableRow(
|
||||
children: [
|
||||
Text('${_item.amount.toStringAsFixed(0)}$unit ${_item.ingredientObj.name}'),
|
||||
Text(
|
||||
'${values["energy"].toStringAsFixed(0)} kcal / ${values["energyKj"].toStringAsFixed(0)} kJ'),
|
||||
Text('${values["protein"].toStringAsFixed(0)} g'),
|
||||
Text('${values["carbohydrates"].toStringAsFixed(0)} g'),
|
||||
Text('${values["fat"].toStringAsFixed(0)} g'),
|
||||
Text('${values["protein"].toStringAsFixed(0)}g'),
|
||||
Text('${values["carbohydrates"].toStringAsFixed(0)}g'),
|
||||
Text('${values["fat"].toStringAsFixed(0)}g'),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -137,7 +141,7 @@ class DismissibleMealHeader extends StatelessWidget {
|
||||
// Delete
|
||||
if (direction == DismissDirection.endToStart) {
|
||||
// Delete the meal
|
||||
Provider.of<NutritionalPlans>(context, listen: false).deleteMeal(_meal);
|
||||
Provider.of<Nutrition>(context, listen: false).deleteMeal(_meal);
|
||||
|
||||
// and inform the user
|
||||
Scaffold.of(context).showSnackBar(
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/providers/nutritional_plans.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/screens/nutritrional_plan_screen.dart';
|
||||
|
||||
class NutritionalPlansList extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final nutritrionalPlansData = Provider.of<NutritionalPlans>(context);
|
||||
final nutritrionalPlansData = Provider.of<Nutrition>(context);
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
itemCount: nutritrionalPlansData.items.length,
|
||||
@@ -35,7 +35,7 @@ class NutritionalPlansList extends StatelessWidget {
|
||||
key: Key(currentPlan.id.toString()),
|
||||
onDismissed: (direction) {
|
||||
// Delete workout from DB
|
||||
Provider.of<NutritionalPlans>(context, listen: false).deletePlan(currentPlan.id);
|
||||
Provider.of<Nutrition>(context, listen: false).deletePlan(currentPlan.id);
|
||||
|
||||
// and inform the user
|
||||
Scaffold.of(context).showSnackBar(
|
||||
|
||||
Reference in New Issue
Block a user