Remove RefreshIndicator and some work on providers

(still not the optimal solution)
This commit is contained in:
Roland Geider
2021-01-26 20:23:48 +01:00
parent e31e1bd6c0
commit fb8083912f
9 changed files with 42 additions and 55 deletions

View File

@@ -323,6 +323,14 @@ class AppLocalizations {
);
}
String get loadingText {
return Intl.message(
'Loading...',
name: 'loadingText',
desc: 'Text to show when entries are being loaded in the background',
);
}
String get delete {
return Intl.message(
'Delete',

View File

@@ -65,7 +65,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Loading...',
AppLocalizations.of(context).loadingText,
style: Theme.of(context).textTheme.headline5,
),
Padding(padding: EdgeInsets.symmetric(vertical: 8)),

View File

@@ -48,7 +48,7 @@ class _NutritionalPlanScreenState extends State<NutritionalPlanScreen> {
Widget getAppBar(NutritionalPlan plan) {
return AppBar(
title: Text(plan.description),
title: Text(AppLocalizations.of(context).nutritionalPlan),
actions: [
PopupMenuButton<NutritionalPlanOptions>(
icon: Icon(Icons.more_vert),
@@ -97,11 +97,8 @@ class _NutritionalPlanScreenState extends State<NutritionalPlanScreen> {
builder: (context, AsyncSnapshot<NutritionalPlan> snapshot) =>
snapshot.connectionState == ConnectionState.waiting
? Center(child: CircularProgressIndicator())
: RefreshIndicator(
onRefresh: () => _loadNutritionalPlanDetail(context, nutritionalPlan.id),
child: Consumer<Nutrition>(
builder: (context, workout, _) => NutritionalPlanDetailWidget(snapshot.data),
),
: Consumer<Nutrition>(
builder: (context, nutrition, _) => NutritionalPlanDetailWidget(snapshot.data),
),
),
);

View File

@@ -20,7 +20,6 @@ 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/nutrition.dart';
import 'package:wger/providers/workout_plans.dart';
import 'package:wger/widgets/app_drawer.dart';
import 'package:wger/widgets/core/bottom_sheet.dart';
@@ -35,10 +34,6 @@ class NutritionScreen extends StatefulWidget {
}
class _NutritionScreenState extends State<NutritionScreen> {
Future<void> _refreshPlans(BuildContext context) async {
await Provider.of<Nutrition>(context, listen: false).fetchAndSetPlans();
}
Widget getAppBar() {
return AppBar(
title: Text(AppLocalizations.of(context).nutritionalPlans),
@@ -61,11 +56,8 @@ class _NutritionScreenState extends State<NutritionScreen> {
//await showNutritionalPlanSheet(context, nutritionalPlan);
},
),
body: RefreshIndicator(
onRefresh: () => _refreshPlans(context),
child: Consumer<WorkoutPlans>(
builder: (context, productsData, child) => NutritionalPlansList(),
),
body: Consumer<WorkoutPlans>(
builder: (context, productsData, child) => NutritionalPlansList(),
),
);
}

View File

@@ -34,15 +34,11 @@ class WeightScreen extends StatefulWidget {
}
class _WeightScreenState extends State<WeightScreen> {
Future<void> _refreshWeightEntries(BuildContext context) async {
await Provider.of<BodyWeight>(context, listen: false).fetchAndSetEntries();
}
WeightEntry weightEntry = WeightEntry();
Widget getAppBar() {
return AppBar(
title: Text('Weight'),
title: Text(AppLocalizations.of(context).weight),
);
}
@@ -62,14 +58,11 @@ class _WeightScreenState extends State<WeightScreen> {
},
),
body: FutureBuilder(
future: _refreshWeightEntries(context),
future: Provider.of<BodyWeight>(context, listen: false).fetchAndSetEntries(),
builder: (context, snapshot) => snapshot.connectionState == ConnectionState.waiting
? Center(child: CircularProgressIndicator())
: RefreshIndicator(
onRefresh: () => _refreshWeightEntries(context),
child: Consumer<BodyWeight>(
builder: (context, productsData, child) => WeightEntriesList(),
),
: Consumer<BodyWeight>(
builder: (context, weightProvider, child) => WeightEntriesList(weightProvider),
),
),
);

View File

@@ -55,12 +55,6 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
});
}
Future<WorkoutPlan> _loadWorkoutPlanDetail(BuildContext context, int workoutId) async {
var workout =
await Provider.of<WorkoutPlans>(context, listen: false).fetchAndSetFullWorkout(workoutId);
return workout;
}
Widget getAppBar(WorkoutPlan plan) {
return AppBar(
title: Text(plan.description),
@@ -115,10 +109,14 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
Widget getBody(WorkoutPlan plan) {
switch (_mode) {
case WorkoutScreenMode.workout:
return WorkoutPlanDetail(plan, _changeMode);
return Consumer<WorkoutPlans>(
builder: (context, value, child) => WorkoutPlanDetail(plan, _changeMode),
);
break;
case WorkoutScreenMode.log:
return WorkoutLogs(plan, _changeMode);
return Consumer<WorkoutPlans>(
builder: (context, value, child) => WorkoutLogs(plan, _changeMode),
);
break;
case WorkoutScreenMode.gym:
return Text('Gym Mode');
@@ -133,7 +131,8 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
return Scaffold(
appBar: getAppBar(workoutPlan),
body: FutureBuilder<WorkoutPlan>(
future: _loadWorkoutPlanDetail(context, workoutPlan.id),
future: Provider.of<WorkoutPlans>(context, listen: false)
.fetchAndSetFullWorkout(workoutPlan.id),
builder: (context, AsyncSnapshot<WorkoutPlan> snapshot) =>
snapshot.connectionState == ConnectionState.waiting
? Center(child: CircularProgressIndicator())

View File

@@ -35,10 +35,6 @@ class WorkoutPlansScreen extends StatefulWidget {
}
class _WorkoutPlansScreenState extends State<WorkoutPlansScreen> {
Future<void> _refreshWorkoutPlans(BuildContext context) async {
await Provider.of<WorkoutPlans>(context, listen: false).fetchAndSetWorkouts();
}
Widget getAppBar() {
return AppBar(
title: Text(AppLocalizations.of(context).labelWorkoutPlans),
@@ -60,11 +56,8 @@ class _WorkoutPlansScreenState extends State<WorkoutPlansScreen> {
);
},
),
body: RefreshIndicator(
onRefresh: () => _refreshWorkoutPlans(context),
child: Consumer<WorkoutPlans>(
builder: (context, productsData, child) => WorkoutPlansList(),
),
body: Consumer<WorkoutPlans>(
builder: (context, workoutProvider, child) => WorkoutPlansList(workoutProvider),
),
);
}

View File

@@ -26,23 +26,26 @@ import 'package:wger/widgets/weight/charts.dart';
import 'package:wger/widgets/weight/forms.dart';
class WeightEntriesList extends StatelessWidget {
final BodyWeight _weightProvider;
WeightEntriesList(this._weightProvider);
@override
Widget build(BuildContext context) {
final weightEntriesData = Provider.of<BodyWeight>(context);
return Column(
children: [
Container(
padding: EdgeInsets.all(15),
height: 220,
child: WeightChartWidget(weightEntriesData.items),
child: WeightChartWidget(_weightProvider.items),
),
Divider(),
Expanded(
child: ListView.builder(
padding: const EdgeInsets.all(10.0),
itemCount: weightEntriesData.items.length,
itemCount: _weightProvider.items.length,
itemBuilder: (context, index) {
final currentEntry = weightEntriesData.items[index];
final currentEntry = _weightProvider.items[index];
return Dismissible(
key: Key(currentEntry.id.toString()),
onDismissed: (direction) {

View File

@@ -23,15 +23,17 @@ import 'package:wger/providers/workout_plans.dart';
import 'package:wger/screens/workout_plan_screen.dart';
class WorkoutPlansList extends StatelessWidget {
final WorkoutPlans _workoutProvider;
WorkoutPlansList(this._workoutProvider);
@override
Widget build(BuildContext context) {
final workoutPlansData = Provider.of<WorkoutPlans>(context);
return ListView.builder(
padding: const EdgeInsets.all(10.0),
itemCount: workoutPlansData.items.length,
itemCount: _workoutProvider.items.length,
itemBuilder: (context, index) {
final currentWorkout = workoutPlansData.items[index];
final currentWorkout = _workoutProvider.items[index];
return Dismissible(
key: Key(currentWorkout.id.toString()),
confirmDismiss: (direction) async {
@@ -94,7 +96,7 @@ class WorkoutPlansList extends StatelessWidget {
child: Card(
child: ListTile(
onTap: () {
workoutPlansData.setCurrentPlan(currentWorkout.id);
_workoutProvider.setCurrentPlan(currentWorkout.id);
return Navigator.of(context)
.pushNamed(WorkoutPlanScreen.routeName, arguments: currentWorkout);