übungen können hinzugefügt werden
This commit is contained in:
parent
fb23e24413
commit
fa3938ab69
126
lib/Views/add_exercise.dart
Normal file
126
lib/Views/add_exercise.dart
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class AddExercise extends StatefulWidget{
|
||||||
|
int workoutId;
|
||||||
|
|
||||||
|
AddExercise(this.workoutId);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<StatefulWidget> createState() {
|
||||||
|
return new AddExerciseState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class WorkoutType{
|
||||||
|
String id, name, description, type, unit;
|
||||||
|
WorkoutType(this.id, this.name, this.description, this.type, this.unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddExerciseState extends State<AddExercise>{
|
||||||
|
|
||||||
|
int anzahl, sets, exerciseID = 0;
|
||||||
|
List data;
|
||||||
|
|
||||||
|
void speichern(String id) async {
|
||||||
|
if(this.anzahl != 0){
|
||||||
|
var url = Uri.parse("http://10.16.17.18/api/add_exercise_to_workout.php?token=satbwertwhbertnwertwertghwertgwertg");
|
||||||
|
var request = http.MultipartRequest("post", url);
|
||||||
|
Map<String, String> test = {
|
||||||
|
"workout": this.widget.workoutId.toString(),
|
||||||
|
"exercise": id,
|
||||||
|
"amount": anzahl.toString(),
|
||||||
|
"sets": sets.toString()
|
||||||
|
};
|
||||||
|
print(test);
|
||||||
|
request.fields.addAll(test);
|
||||||
|
var response = await request.send();
|
||||||
|
var test2 = await response.stream.bytesToString();
|
||||||
|
print(test2);
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List> getWorkouts() async {
|
||||||
|
var response = await http.get(
|
||||||
|
"http://10.16.17.18/api/exercises.php?token=satbwertwhbertnwertwertghwertgwertg",
|
||||||
|
headers: {
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.setState(() {
|
||||||
|
data = JsonDecoder().convert(response.body);
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
// TODO: implement initState
|
||||||
|
getWorkouts();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text("Füge eine neue Übung hinzu"),
|
||||||
|
),
|
||||||
|
body: Column(
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
children: <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.all(8),
|
||||||
|
child: TextField(
|
||||||
|
autocorrect: true,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
labelText: "anzahl"
|
||||||
|
),
|
||||||
|
onChanged: (String s){
|
||||||
|
setState(() {
|
||||||
|
anzahl = int.parse(s);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.all(8),
|
||||||
|
child: TextField(
|
||||||
|
autocorrect: true,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
labelText: "sets"
|
||||||
|
),
|
||||||
|
onChanged: (String s){
|
||||||
|
setState(() {
|
||||||
|
sets = int.parse(s);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: data== null? 0 : data.length,
|
||||||
|
itemBuilder: (BuildContext context, int index){
|
||||||
|
return new ListTile(
|
||||||
|
title: Text(data[index]['name']),
|
||||||
|
subtitle: Text(data[index]['description']),
|
||||||
|
onTap: (){
|
||||||
|
speichern(data[index]['id']);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:fitnessapp/Views/add_exercise.dart';
|
||||||
import 'package:fitnessapp/Views/exercise_details_view.dart';
|
import 'package:fitnessapp/Views/exercise_details_view.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
@ -53,20 +54,31 @@ class ExerciseViewState extends State<ExerciseView>{
|
|||||||
),
|
),
|
||||||
title: Text(this.widget.title),
|
title: Text(this.widget.title),
|
||||||
),
|
),
|
||||||
body: ListView.builder(
|
body: RefreshIndicator(
|
||||||
itemCount: data == null ? 0 : data.length,
|
child: ListView.builder(
|
||||||
itemBuilder: (BuildContext context, int index){
|
itemCount: data == null ? 0 : data.length,
|
||||||
return new ListTile(
|
itemBuilder: (BuildContext context, int index){
|
||||||
leading: Icon(data[index]['type'] == 'duration' ? Icons.access_alarm : (data[index]['type'] == 'count' ? Icons.filter_1 : Icons.transfer_within_a_station)),
|
return new ListTile(
|
||||||
title: Text((index+1).toString() + ': ' + data[index]['name']),
|
leading: Icon(data[index]['type'] == 'duration' ? Icons.access_alarm : (data[index]['type'] == 'count' ? Icons.filter_1 : Icons.transfer_within_a_station)),
|
||||||
subtitle: Text(data[index]['sets'] + ' x ' + data[index]['amount'] + ' ' + data[index]['unit']),
|
title: Text((index+1).toString() + ': ' + data[index]['name']),
|
||||||
onTap: (){
|
subtitle: Text(data[index]['sets'] + ' x ' + data[index]['amount'] + ' ' + data[index]['unit']),
|
||||||
Navigator.push(context, MaterialPageRoute(
|
onTap: (){
|
||||||
builder: (context) => ExerciseDetailsView(data[index]['name'], data[index]['description'], data[index]['amount'], data[index]['type'], data[index]['unit'])
|
Navigator.push(context, MaterialPageRoute(
|
||||||
));
|
builder: (context) => ExerciseDetailsView(data[index]['name'], data[index]['description'], data[index]['amount'], data[index]['type'], data[index]['unit'])
|
||||||
},
|
));
|
||||||
);
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
onRefresh: getWorkouts,
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: (){
|
||||||
|
Navigator.push(context, MaterialPageRoute(
|
||||||
|
builder: (context) => AddExercise(int.parse(this.widget.id))
|
||||||
|
));
|
||||||
},
|
},
|
||||||
|
child: Icon(Icons.add),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class NewWorkoutViewState extends State<NewWorkoutView>{
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text("Erstelle ein neues Workout"),
|
title: Text("Füge eine Übung hinzu"),
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
mainAxisSize: MainAxisSize.max,
|
mainAxisSize: MainAxisSize.max,
|
||||||
@ -46,6 +46,7 @@ class NewWorkoutViewState extends State<NewWorkoutView>{
|
|||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.all(8),
|
padding: EdgeInsets.all(8),
|
||||||
child: TextField(
|
child: TextField(
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
autocorrect: true,
|
autocorrect: true,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
|
Loading…
Reference in New Issue
Block a user