mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-19 07:50:52 +01:00
Allow editing the workout name when creating one
This commit is contained in:
@@ -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": {}
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user