127 lines
3.3 KiB
Dart
127 lines
3.3 KiB
Dart
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{
|
|
String token;
|
|
int workoutId;
|
|
|
|
AddExercise(this.token, 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=" + super.widget.token);
|
|
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']);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |