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