mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Don't load the routine every time the log page are accessed
This commit is contained in:
@@ -58,7 +58,6 @@ class BaseConfig {
|
||||
required this.slotEntryId,
|
||||
required this.iteration,
|
||||
this.repeat = false,
|
||||
// required this.trigger,
|
||||
required this.value,
|
||||
this.operation = 'r',
|
||||
this.step = 'abs',
|
||||
|
||||
@@ -28,31 +28,14 @@ class WorkoutLogsScreen extends StatelessWidget {
|
||||
|
||||
static const routeName = '/workout-logs';
|
||||
|
||||
Future<Routine> _loadFullWorkout(BuildContext context, int routineId) {
|
||||
return Provider.of<RoutinesProvider>(context, listen: false).fetchAndSetRoutineFull(routineId);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final routine = ModalRoute.of(context)!.settings.arguments as Routine;
|
||||
|
||||
return Scaffold(
|
||||
appBar: RoutineDetailAppBar(routine),
|
||||
body: FutureBuilder(
|
||||
future: _loadFullWorkout(context, routine.id!),
|
||||
builder: (context, AsyncSnapshot<Routine> snapshot) => ListView(
|
||||
children: [
|
||||
if (snapshot.connectionState == ConnectionState.waiting)
|
||||
const SizedBox(
|
||||
height: 200,
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
else
|
||||
Consumer<RoutinesProvider>(
|
||||
builder: (context, value, child) => WorkoutLogs(routine),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Consumer<RoutinesProvider>(
|
||||
builder: (context, value, child) => WorkoutLogs(routine),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -39,24 +39,24 @@ class RoutinesList extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
itemCount: _routineProvider.items.length,
|
||||
itemBuilder: (context, index) {
|
||||
final currentWorkout = _routineProvider.items[index];
|
||||
final currentRoutine = _routineProvider.items[index];
|
||||
|
||||
return Card(
|
||||
child: ListTile(
|
||||
onTap: () async {
|
||||
_routineProvider.setCurrentPlan(currentWorkout.id!);
|
||||
_routineProvider.setCurrentPlan(currentRoutine.id!);
|
||||
final routine =
|
||||
await _routineProvider.fetchAndSetRoutineFull(currentWorkout.id!);
|
||||
await _routineProvider.fetchAndSetRoutineFull(currentRoutine.id!);
|
||||
|
||||
Navigator.of(context).pushNamed(
|
||||
RoutineScreen.routeName,
|
||||
arguments: routine,
|
||||
);
|
||||
},
|
||||
title: Text(currentWorkout.name),
|
||||
title: Text(currentRoutine.name),
|
||||
subtitle: Text(
|
||||
'${DateFormat.yMd(Localizations.localeOf(context).languageCode).format(currentWorkout.start)}'
|
||||
' - ${DateFormat.yMd(Localizations.localeOf(context).languageCode).format(currentWorkout.end)}',
|
||||
'${DateFormat.yMd(Localizations.localeOf(context).languageCode).format(currentRoutine.start)}'
|
||||
' - ${DateFormat.yMd(Localizations.localeOf(context).languageCode).format(currentRoutine.end)}',
|
||||
),
|
||||
trailing: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
const VerticalDivider(),
|
||||
@@ -70,7 +70,7 @@ class RoutinesList extends StatelessWidget {
|
||||
builder: (BuildContext contextDialog) {
|
||||
return AlertDialog(
|
||||
content: Text(
|
||||
AppLocalizations.of(context).confirmDelete(currentWorkout.name),
|
||||
AppLocalizations.of(context).confirmDelete(currentRoutine.name),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -91,7 +91,7 @@ class RoutinesList extends StatelessWidget {
|
||||
Provider.of<RoutinesProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).deleteRoutine(currentWorkout.id!);
|
||||
).deleteRoutine(currentRoutine.id!);
|
||||
|
||||
// Close the popup
|
||||
Navigator.of(contextDialog).pop();
|
||||
|
||||
@@ -47,7 +47,7 @@ class _WorkoutLogsState extends State<WorkoutLogs> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
return ListView(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
|
||||
@@ -23,8 +23,8 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:golden_toolkit/golden_toolkit.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/models/workouts/routine.dart';
|
||||
import 'package:wger/providers/routines.dart';
|
||||
import 'package:wger/screens/routine_logs_screen.dart';
|
||||
import 'package:wger/screens/routine_screen.dart';
|
||||
@@ -34,11 +34,12 @@ import 'routine_logs_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RoutinesProvider])
|
||||
void main() {
|
||||
late Routine routine;
|
||||
final mockRoutinesProvider = MockRoutinesProvider();
|
||||
|
||||
setUp(() {
|
||||
when(mockRoutinesProvider.fetchAndSetRoutineFull(any))
|
||||
.thenAnswer((_) => Future.value(getTestRoutine()));
|
||||
routine = getTestRoutine();
|
||||
routine.logs[0].date = DateTime.now();
|
||||
});
|
||||
|
||||
Widget renderWidget({locale = 'en'}) {
|
||||
@@ -54,7 +55,7 @@ void main() {
|
||||
home: TextButton(
|
||||
onPressed: () => key.currentState!.push(
|
||||
MaterialPageRoute<void>(
|
||||
settings: RouteSettings(arguments: getTestRoutine()),
|
||||
settings: RouteSettings(arguments: routine),
|
||||
builder: (_) => const WorkoutLogsScreen(),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -57,18 +57,8 @@ void main() {
|
||||
|
||||
test('Checks that an model with data correctly calculates hasProgressionRules', () {
|
||||
final slotEntry = SlotEntry.empty();
|
||||
slotEntry.weightConfigs.add(BaseConfig(
|
||||
id: 1,
|
||||
slotEntryId: 1,
|
||||
iteration: 1,
|
||||
value: 1,
|
||||
));
|
||||
slotEntry.weightConfigs.add(BaseConfig(
|
||||
id: 2,
|
||||
slotEntryId: 1,
|
||||
iteration: 1,
|
||||
value: 1,
|
||||
));
|
||||
slotEntry.weightConfigs.add(BaseConfig.firstIteration(3, 1));
|
||||
slotEntry.weightConfigs.add(BaseConfig.firstIteration(4, 1));
|
||||
expect(slotEntry.hasProgressionRules, true);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user