mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Add gym workout screen
This commit is contained in:
@@ -67,6 +67,30 @@ class AppLocalizations {
|
||||
);
|
||||
}
|
||||
|
||||
String get repetitions {
|
||||
return Intl.message(
|
||||
'Repetitions',
|
||||
name: 'repetitions',
|
||||
desc: 'Repetitions for an exercise set',
|
||||
);
|
||||
}
|
||||
|
||||
String get impression {
|
||||
return Intl.message(
|
||||
'Impression',
|
||||
name: 'impression',
|
||||
desc: 'General Impression for a workout session (good, bad, etc.)',
|
||||
);
|
||||
}
|
||||
|
||||
String get notes {
|
||||
return Intl.message(
|
||||
'Notes',
|
||||
name: 'notes',
|
||||
desc: 'Personal notes for a workout session',
|
||||
);
|
||||
}
|
||||
|
||||
String get workoutSession {
|
||||
return Intl.message(
|
||||
'Workout session',
|
||||
@@ -227,6 +251,22 @@ class AppLocalizations {
|
||||
);
|
||||
}
|
||||
|
||||
String get timeStart {
|
||||
return Intl.message(
|
||||
'Start time',
|
||||
name: 'timeStart',
|
||||
desc: 'The starting time of a workout',
|
||||
);
|
||||
}
|
||||
|
||||
String get timeEnd {
|
||||
return Intl.message(
|
||||
'End time',
|
||||
name: 'timeEnd',
|
||||
desc: 'The end time of a workout',
|
||||
);
|
||||
}
|
||||
|
||||
String get ingredient {
|
||||
return Intl.message(
|
||||
'Ingredient',
|
||||
|
||||
@@ -26,6 +26,7 @@ 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';
|
||||
import 'package:wger/screens/gym_mode.dart';
|
||||
import 'package:wger/screens/home_tabs_screen.dart';
|
||||
import 'package:wger/screens/nutritional_plan_screen.dart';
|
||||
import 'package:wger/screens/nutritional_plans_screen.dart';
|
||||
@@ -98,6 +99,7 @@ class MyApp extends StatelessWidget {
|
||||
WeightScreen.routeName: (ctx) => WeightScreen(),
|
||||
WorkoutPlansScreen.routeName: (ctx) => WorkoutPlansScreen(),
|
||||
WorkoutPlanScreen.routeName: (ctx) => WorkoutPlanScreen(),
|
||||
GymModeScreen.routeName: (ctx) => GymModeScreen(),
|
||||
NutritionScreen.routeName: (ctx) => NutritionScreen(),
|
||||
NutritionalPlanScreen.routeName: (ctx) => NutritionalPlanScreen(),
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:wger/helpers/json.dart';
|
||||
|
||||
part 'session.g.dart';
|
||||
|
||||
const impressionMap = {1: 'bad', 2: 'neutral', 3: 'good'};
|
||||
const ImpressionMap = {1: 'bad', 2: 'neutral', 3: 'good'};
|
||||
|
||||
@JsonSerializable()
|
||||
class WorkoutSession {
|
||||
@@ -41,6 +41,6 @@ class WorkoutSession {
|
||||
Map<String, dynamic> toJson() => _$WorkoutSessionToJson(this);
|
||||
|
||||
get impressionAsString {
|
||||
return impressionMap[impression];
|
||||
return ImpressionMap[impression];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,20 +171,21 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
exercises.add(exercise);
|
||||
|
||||
// Settings
|
||||
//if (exerciseData['setting_obj_list'].length > 0) {
|
||||
settings.add(
|
||||
Setting(
|
||||
id: exerciseData['setting_obj_list'][0]['id'],
|
||||
comment: exerciseData['setting_obj_list'][0]['comment'],
|
||||
reps: exerciseData['setting_obj_list'][0]['reps'],
|
||||
//weight: setting['setting_obj_list'][0]['weight'] == null
|
||||
// ? ''
|
||||
// : setting['setting_obj_list'][0]['weight'],
|
||||
repsText: exerciseData['setting_text'],
|
||||
exerciseObj: exercise,
|
||||
),
|
||||
);
|
||||
//}
|
||||
if (exerciseData['setting_obj_list'].length > 0) {
|
||||
settings.add(
|
||||
Setting(
|
||||
id: exerciseData['setting_obj_list'][0]['id'],
|
||||
setId: exerciseData['setting_obj_list'][0]['set'],
|
||||
comment: exerciseData['setting_obj_list'][0]['comment'],
|
||||
reps: exerciseData['setting_obj_list'][0]['reps'],
|
||||
//weight: setting['setting_obj_list'][0]['weight'] == null
|
||||
// ? ''
|
||||
// : setting['setting_obj_list'][0]['weight'],
|
||||
repsText: exerciseData['setting_text'],
|
||||
exerciseObj: exercise,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Sets
|
||||
@@ -356,6 +357,17 @@ class WorkoutPlans extends WgerBaseProvider with ChangeNotifier {
|
||||
return setting;
|
||||
}
|
||||
|
||||
Future<void> deleteSetting(Setting workoutSetting) async {
|
||||
await deleteRequest(_settingsUrlPath, workoutSetting.id);
|
||||
|
||||
for (var workout in _workoutPlans) {
|
||||
for (var day in workout.days) {
|
||||
day.sets.removeWhere((element) => element.id == workoutSetting.setId);
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/*
|
||||
* Sessions
|
||||
*/
|
||||
|
||||
44
lib/screens/gym_mode.dart
Normal file
44
lib/screens/gym_mode.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (C) 2020 wger Team
|
||||
*
|
||||
* wger Workout Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wger Workout Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/models/workouts/workout_plan.dart';
|
||||
import 'package:wger/providers/workout_plans.dart';
|
||||
import 'package:wger/widgets/workouts/gym_mode.dart';
|
||||
|
||||
class GymModeScreen extends StatefulWidget {
|
||||
static const routeName = '/gym-mode';
|
||||
|
||||
@override
|
||||
_GymModeScreenState createState() => _GymModeScreenState();
|
||||
}
|
||||
|
||||
class _GymModeScreenState extends State<GymModeScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final workoutPlan = ModalRoute.of(context).settings.arguments as WorkoutPlan;
|
||||
|
||||
return Scaffold(
|
||||
//appBar: getAppBar(workoutPlan),
|
||||
body: Consumer<WorkoutPlans>(
|
||||
builder: (context, value, child) => GymMode(workoutPlan),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -16,56 +16,339 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wger/locale/locales.dart';
|
||||
import 'package:wger/models/workouts/session.dart';
|
||||
import 'package:wger/models/workouts/workout_plan.dart';
|
||||
import 'package:wger/screens/workout_plan_screen.dart';
|
||||
|
||||
class GymMode extends StatefulWidget {
|
||||
final WorkoutPlan _workoutPlan;
|
||||
final _changeMode;
|
||||
GymMode(this._workoutPlan, this._changeMode);
|
||||
GymMode(this._workoutPlan);
|
||||
|
||||
@override
|
||||
_GymModeState createState() => _GymModeState();
|
||||
}
|
||||
|
||||
class _GymModeState extends State<GymMode> {
|
||||
final dayController = TextEditingController();
|
||||
PageController _controller = PageController(
|
||||
initialPage: 0,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Text(
|
||||
'Gym mode',
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
),
|
||||
return PageView(
|
||||
controller: _controller,
|
||||
children: [
|
||||
StartPage(widget._workoutPlan),
|
||||
TimerWidget(_controller),
|
||||
LogPage(_controller),
|
||||
TimerWidget(_controller),
|
||||
LogPage(_controller),
|
||||
SessionPage(),
|
||||
|
||||
//MyPage2Widget(),
|
||||
//MyPage3Widget(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class StartPage extends StatelessWidget {
|
||||
final WorkoutPlan _workoutPlan;
|
||||
|
||||
StartPage(this._workoutPlan);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Text(
|
||||
'Gym mode',
|
||||
style: Theme.of(context).textTheme.headline5,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Text(
|
||||
widget._workoutPlan.description,
|
||||
style: Theme.of(context).textTheme.headline5,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Text(
|
||||
_workoutPlan.description,
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
),
|
||||
//...widget._workoutPlan.days.map((workoutDay) => WorkoutDayWidget(workoutDay)).toList(),
|
||||
Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
child: Text('Open workout'),
|
||||
onPressed: () {
|
||||
widget._changeMode(WorkoutScreenMode.workout);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text('Back to workout'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class LogPage extends StatelessWidget {
|
||||
PageController _controller;
|
||||
final _form = GlobalKey<FormState>();
|
||||
final repsController = TextEditingController();
|
||||
|
||||
LogPage(this._controller);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Text(
|
||||
'Log',
|
||||
style: Theme.of(context).textTheme.headline5,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Form(
|
||||
key: _form,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
TextFormField(
|
||||
decoration:
|
||||
InputDecoration(labelText: AppLocalizations.of(context).repetitions),
|
||||
controller: repsController,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context).weight),
|
||||
controller: repsController,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
onPressed: () async {},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.chevron_right),
|
||||
onPressed: () {
|
||||
_controller.nextPage(
|
||||
duration: Duration(milliseconds: 200),
|
||||
curve: Curves.bounceIn,
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SessionPage extends StatefulWidget {
|
||||
@override
|
||||
_SessionPageState createState() => _SessionPageState();
|
||||
}
|
||||
|
||||
class _SessionPageState extends State<SessionPage> {
|
||||
final _form = GlobalKey<FormState>();
|
||||
final impressionController = TextEditingController();
|
||||
final notesController = TextEditingController();
|
||||
final timeStartController = TextEditingController();
|
||||
final timeEndController = TextEditingController();
|
||||
|
||||
int impressionValue = 2;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Text(
|
||||
'Session',
|
||||
style: Theme.of(context).textTheme.headline5,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Form(
|
||||
key: _form,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
DropdownButton<int>(
|
||||
value: impressionValue,
|
||||
underline: Container(height: 0),
|
||||
onChanged: (int newValue) {
|
||||
setState(() {
|
||||
impressionValue = newValue;
|
||||
});
|
||||
},
|
||||
items: ImpressionMap.keys.map<DropdownMenuItem<int>>((int key) {
|
||||
return DropdownMenuItem<int>(
|
||||
value: key,
|
||||
child: Text(
|
||||
ImpressionMap[key],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).notes,
|
||||
),
|
||||
maxLines: 3,
|
||||
controller: notesController,
|
||||
keyboardType: TextInputType.multiline,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {},
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: TextFormField(
|
||||
decoration:
|
||||
InputDecoration(labelText: AppLocalizations.of(context).timeStart),
|
||||
controller: timeStartController,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {},
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: TextFormField(
|
||||
decoration:
|
||||
InputDecoration(labelText: AppLocalizations.of(context).timeEnd),
|
||||
controller: timeEndController,
|
||||
onFieldSubmitted: (_) {},
|
||||
onSaved: (newValue) {},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
onPressed: () async {},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.stop),
|
||||
onPressed: () {},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TimerWidget extends StatefulWidget {
|
||||
PageController _controller;
|
||||
|
||||
TimerWidget(this._controller);
|
||||
|
||||
@override
|
||||
_TimerWidgetState createState() => _TimerWidgetState();
|
||||
}
|
||||
|
||||
class _TimerWidgetState extends State<TimerWidget> {
|
||||
// See https://stackoverflow.com/questions/54610121/flutter-countdown-timer
|
||||
|
||||
Timer _timer;
|
||||
int _currentTime = 1;
|
||||
|
||||
void startTimer() {
|
||||
setState(() {
|
||||
_currentTime = 0;
|
||||
});
|
||||
|
||||
_timer?.cancel();
|
||||
|
||||
const oneSecond = const Duration(seconds: 1);
|
||||
_timer = new Timer.periodic(
|
||||
oneSecond,
|
||||
(Timer timer) {
|
||||
if (_currentTime == 10) {
|
||||
setState(() {
|
||||
timer.cancel();
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
_currentTime++;
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
startTimer();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Text(
|
||||
'Timer',
|
||||
style: Theme.of(context).textTheme.headline5,
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text("start"),
|
||||
onPressed: () {
|
||||
startTimer();
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Text(
|
||||
_currentTime.toString(),
|
||||
style: Theme.of(context).textTheme.headline1,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.chevron_right),
|
||||
onPressed: () {
|
||||
widget._controller
|
||||
.nextPage(duration: Duration(milliseconds: 200), curve: Curves.bounceIn);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:wger/locale/locales.dart';
|
||||
import 'package:wger/models/workouts/workout_plan.dart';
|
||||
import 'package:wger/screens/gym_mode.dart';
|
||||
import 'package:wger/screens/workout_plan_screen.dart';
|
||||
import 'package:wger/widgets/core/bottom_sheet.dart';
|
||||
import 'package:wger/widgets/workouts/day.dart';
|
||||
@@ -72,6 +73,13 @@ class _WorkoutPlanDetailState extends State<WorkoutPlanDetail> {
|
||||
widget._changeMode(WorkoutScreenMode.log);
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text('Start gym mode'),
|
||||
onPressed: () {
|
||||
return Navigator.of(context)
|
||||
.pushNamed(GymModeScreen.routeName, arguments: widget._workoutPlan);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
@@ -45,9 +45,7 @@ class WorkoutPlansList extends StatelessWidget {
|
||||
content: Text("Are you sure you want to delete ${currentWorkout.description}?"),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(
|
||||
"Cancel",
|
||||
),
|
||||
child: Text("Cancel"),
|
||||
onPressed: () => Navigator.of(contextDialog).pop(),
|
||||
),
|
||||
TextButton(
|
||||
|
||||
Reference in New Issue
Block a user