Merge branch 'development'
This commit is contained in:
commit
9181aaf830
|
@ -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:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
@ -23,7 +24,7 @@ class ExerciseViewState extends State<ExerciseView>{
|
|||
|
||||
Future<List> getWorkouts() async {
|
||||
var response = await http.get(
|
||||
"http://10.16.17.65/api/workout.php?token=satbwertwhbertnwertwertghwertgwertg&workout="+this.widget.id,
|
||||
"http://10.16.17.18/api/workout.php?token=satbwertwhbertnwertwertghwertgwertg&workout="+this.widget.id,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
|
@ -53,21 +54,31 @@ class ExerciseViewState extends State<ExerciseView>{
|
|||
),
|
||||
title: Text(this.widget.title),
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemCount: data == null ? 0 : data.length,
|
||||
itemBuilder: (BuildContext context, int index){
|
||||
return new ListTile(
|
||||
leading: Icon(data[index]['type'] == 'duration' ? Icons.access_alarm : (data[index]['type'] == 'count' ? Icons.filter_1 : Icons.transfer_within_a_station)),
|
||||
title: Text(data[index]['name']),
|
||||
subtitle: Text(data[index]['amount'] + ' ' + data[index]['unit']),
|
||||
trailing: Icon(Icons.add_box),
|
||||
onTap: (){
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => ExerciseDetailsView(data[index]['name'], data[index]['description'], data[index]['amount'], data[index]['type'], data[index]['unit'])
|
||||
));
|
||||
},
|
||||
);
|
||||
body: RefreshIndicator(
|
||||
child: ListView.builder(
|
||||
itemCount: data == null ? 0 : data.length,
|
||||
itemBuilder: (BuildContext context, int index){
|
||||
return new ListTile(
|
||||
leading: Icon(data[index]['type'] == 'duration' ? Icons.access_alarm : (data[index]['type'] == 'count' ? Icons.filter_1 : Icons.transfer_within_a_station)),
|
||||
title: Text((index+1).toString() + ': ' + data[index]['name']),
|
||||
subtitle: Text(data[index]['sets'] + ' x ' + data[index]['amount'] + ' ' + data[index]['unit']),
|
||||
onTap: (){
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:async';
|
||||
|
@ -16,42 +17,28 @@ class WorkoutType{
|
|||
}
|
||||
|
||||
class NewWorkoutViewState extends State<NewWorkoutView>{
|
||||
List<WorkoutType> data;
|
||||
List<WorkoutType> selectedExercises = new List();
|
||||
String selectedExercisesString = "Derzeit ausgewählte übungen: ";
|
||||
|
||||
Future<List> getWorkouts() async {
|
||||
var response = await http.get(
|
||||
"http://10.16.17.65/api/exercises.php?token=satbwertwhbertnwertwertghwertgwertg",
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
);
|
||||
String name = "";
|
||||
|
||||
List results = JsonDecoder().convert(response.body);
|
||||
List<WorkoutType> templist = [];
|
||||
for(var i = 0; i < results.length; i++){
|
||||
templist.add(new WorkoutType(results[i]['id'], results[i]['name'], results[i]['description'], results[i]['type'], results[i]['unit']));
|
||||
void speichern() async {
|
||||
if(this.name != ''){
|
||||
FormData data = new FormData.fromMap({
|
||||
"name": "Hallo Welt"
|
||||
});
|
||||
var url = Uri.parse("http://10.16.17.18/api/new_workout.php?token=satbwertwhbertnwertwertghwertgwertg");
|
||||
var request = http.MultipartRequest("post", url);
|
||||
Map<String, String> test = {"name": name};
|
||||
request.fields.addAll(test);
|
||||
var response = await request.send();
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
this.setState(() {
|
||||
data = templist;
|
||||
});
|
||||
print(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
getWorkouts();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Erstelle ein neues Workout"),
|
||||
title: Text("Füge eine Übung hinzu"),
|
||||
),
|
||||
body: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
|
@ -59,39 +46,24 @@ class NewWorkoutViewState extends State<NewWorkoutView>{
|
|||
Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
autocorrect: true,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: "Name des Workouts"
|
||||
),
|
||||
onChanged: (String s){
|
||||
setState(() {
|
||||
name = s;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
Text(selectedExercisesString),
|
||||
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: (){
|
||||
setState(() {
|
||||
if(selectedExercises == null){
|
||||
selectedExercises = [data[index]];
|
||||
}else{
|
||||
selectedExercises.add(data[index]);
|
||||
}
|
||||
});
|
||||
String temp = "Ausgewählte übungen: ";
|
||||
for (var i = 0; i < selectedExercises.length; i++){
|
||||
temp = temp + selectedExercises[i].name + ', ';
|
||||
}
|
||||
setState(() {
|
||||
selectedExercisesString = temp;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: RaisedButton(
|
||||
onPressed: speichern,
|
||||
child: Text("Workout erstellen"),
|
||||
),
|
||||
)
|
||||
],
|
||||
|
|
|
@ -18,7 +18,7 @@ class WorkoutsViewState extends State<WorkoutsView>{
|
|||
|
||||
Future<List> getWorkouts() async {
|
||||
var response = await http.get(
|
||||
"http://10.16.17.65/api/index.php?token=satbwertwhbertnwertwertghwertgwertg",
|
||||
"http://10.16.17.18/api/index.php?token=satbwertwhbertnwertwertghwertgwertg",
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
|
@ -39,20 +39,23 @@ class WorkoutsViewState extends State<WorkoutsView>{
|
|||
Widget build(BuildContext context) {
|
||||
// TODO: implement build
|
||||
return Scaffold(
|
||||
body: ListView.builder(
|
||||
itemCount: data == null ? 0 : data.length,
|
||||
itemBuilder: (BuildContext context, int index){
|
||||
return new ListTile(
|
||||
leading: Icon(Icons.add),
|
||||
title: Text(data[index]['title']),
|
||||
subtitle: Text(data[index]['creator']),
|
||||
onTap: (){
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => ExerciseView(data[index]['title'], data[index]['id'])
|
||||
));
|
||||
},
|
||||
);
|
||||
},
|
||||
body: RefreshIndicator(
|
||||
child: ListView.builder(
|
||||
itemCount: data == null ? 0 : data.length,
|
||||
itemBuilder: (BuildContext context, int index){
|
||||
return new ListTile(
|
||||
leading: Icon(Icons.add),
|
||||
title: Text(data[index]['title']),
|
||||
subtitle: Text(data[index]['creator']),
|
||||
onTap: (){
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => ExerciseView(data[index]['title'], data[index]['id'])
|
||||
));
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
onRefresh: getWorkouts,
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: (){
|
||||
|
|
|
@ -64,6 +64,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.3"
|
||||
dio:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: dio
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.9"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
@ -206,4 +213,4 @@ packages:
|
|||
source: hosted
|
||||
version: "3.5.0"
|
||||
sdks:
|
||||
dart: ">=2.4.0 <3.0.0"
|
||||
dart: ">2.4.0 <3.0.0"
|
||||
|
|
|
@ -24,6 +24,7 @@ dependencies:
|
|||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^0.1.2
|
||||
http:
|
||||
dio:
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in New Issue