Allow editing the workout name when creating one

This commit is contained in:
Roland Geider
2020-11-21 21:01:30 +01:00
parent 7f8ecfe770
commit a00ac1afdf
7 changed files with 90 additions and 10 deletions

View File

@@ -1,15 +1,33 @@
{
"@@last_modified": "2020-11-11T15:35:32.537025",
"@@last_modified": "2020-11-21T20:55:11.028883",
"labelWorkoutPlans": "Workout plans",
"@labelWorkoutPlans": {
"description": "Title for screen workout plans",
"type": "text",
"placeholders": {}
},
"newWorkout": "new Workout",
"@newWorkout": {
"description": "Header when adding a new workout",
"type": "text",
"placeholders": {}
},
"description": "description",
"@description": {
"description": "Description of a workout, nutritional plan, etc.",
"type": "text",
"placeholders": {}
},
"labelWorkoutPlan": "Workout plan",
"@labelWorkoutPlan": {
"description": "Title for screen workout plan",
"type": "text",
"placeholders": {}
},
"labelDashboard": "Dashboard",
"@labelDashboard": {
"description": "Title for screen dashboard",
"type": "text",
"placeholders": {}
}
}

View File

@@ -21,7 +21,10 @@ class MessageLookup extends MessageLookupByLibrary {
final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"description" : MessageLookupByLibrary.simpleMessage("description"),
"labelDashboard" : MessageLookupByLibrary.simpleMessage("Dashboard"),
"labelWorkoutPlan" : MessageLookupByLibrary.simpleMessage("Workout plan"),
"labelWorkoutPlans" : MessageLookupByLibrary.simpleMessage("Workout plans")
"labelWorkoutPlans" : MessageLookupByLibrary.simpleMessage("Workout plans"),
"newWorkout" : MessageLookupByLibrary.simpleMessage("new Workout")
};
}

View File

@@ -25,6 +25,22 @@ class AppLocalizations {
);
}
String get newWorkout {
return Intl.message(
'new Workout',
name: 'newWorkout',
desc: 'Header when adding a new workout',
);
}
String get description {
return Intl.message(
'description',
name: 'description',
desc: 'Description of a workout, nutritional plan, etc.',
);
}
String get labelWorkoutPlan {
return Intl.message(
'Workout plan',

View File

@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:wger/models/workouts/day.dart';
@@ -18,9 +19,9 @@ class WorkoutPlan {
List<Day> days = [];
WorkoutPlan({
this.id,
this.creationDate,
this.description,
@required this.id,
@required this.creationDate,
@required this.description,
this.days,
});

View File

@@ -140,7 +140,7 @@ class WorkoutPlans with ChangeNotifier {
}
}
Future<void> addWorkout(WorkoutPlan workout) async {
Future<WorkoutPlan> addWorkout(WorkoutPlan workout) async {
try {
final response = await http.post(
_url,
@@ -150,8 +150,10 @@ class WorkoutPlans with ChangeNotifier {
},
body: json.encode(workout.toJson()),
);
_entries.insert(0, WorkoutPlan.fromJson(json.decode(response.body)));
workout = WorkoutPlan.fromJson(json.decode(response.body));
_entries.insert(0, workout);
notifyListeners();
return workout;
} catch (error) {
throw error;
}

View File

@@ -1,8 +1,10 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:wger/locale/locales.dart';
import 'package:wger/models/workouts/workout_plan.dart';
import 'package:wger/providers/workout_plans.dart';
import 'package:wger/screens/workout_plan_screen.dart';
import 'package:wger/widgets/app_drawer.dart';
import 'package:wger/widgets/workouts/workout_plans_list.dart';
@@ -14,6 +16,8 @@ class WorkoutPlansScreen extends StatefulWidget {
}
class _WorkoutPlansScreenState extends State<WorkoutPlansScreen> {
final workoutController = TextEditingController();
Future<WorkoutPlan> _refreshWorkoutPlans(BuildContext context) async {
await Provider.of<WorkoutPlans>(context, listen: false).fetchAndSetWorkouts();
}
@@ -37,8 +41,44 @@ class _WorkoutPlansScreenState extends State<WorkoutPlansScreen> {
drawer: AppDrawer(),
floatingActionButton: FloatingActionButton(
onPressed: () {
Provider.of<WorkoutPlans>(context, listen: false).addWorkout(
WorkoutPlan(description: 'button'),
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
margin: EdgeInsets.all(20),
child: Form(
child: Column(
children: [
Text(
AppLocalizations.of(context).newWorkout,
style: Theme.of(context).textTheme.headline6,
),
TextFormField(
decoration:
InputDecoration(labelText: AppLocalizations.of(context).description),
controller: workoutController,
onFieldSubmitted: (_) {},
),
ElevatedButton(
child: Text('Save'),
onPressed: () {
final workoutFuture = Provider.of<WorkoutPlans>(context, listen: false)
.addWorkout(WorkoutPlan(description: workoutController.text));
workoutController.text = '';
Navigator.of(context).pop();
workoutFuture.then(
(workout) => Navigator.of(context).pushNamed(
WorkoutPlanScreen.routeName,
arguments: workout,
),
);
},
),
],
),
),
);
},
);
},
child: const Icon(Icons.add),

View File

@@ -23,7 +23,7 @@ class WorkoutPlansList extends StatelessWidget {
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text(
"Workout ${currentWorkout.id} deleted",
'Workout "${currentWorkout.description}" deleted',
textAlign: TextAlign.center,
),
),