From fa3938ab699ecc5b63534523a44dcd12d8b45f36 Mon Sep 17 00:00:00 2001 From: Goeran Heinemann Date: Thu, 2 Apr 2020 00:54:01 +0200 Subject: [PATCH] =?UTF-8?q?=C3=BCbungen=20k=C3=B6nnen=20hinzugef=C3=BCgt?= =?UTF-8?q?=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Views/add_exercise.dart | 126 ++++++++++++++++++++++++++++++++ lib/Views/exercises_view.dart | 38 ++++++---- lib/Views/new_workout_view.dart | 3 +- 3 files changed, 153 insertions(+), 14 deletions(-) create mode 100644 lib/Views/add_exercise.dart diff --git a/lib/Views/add_exercise.dart b/lib/Views/add_exercise.dart new file mode 100644 index 0000000..f45c1a7 --- /dev/null +++ b/lib/Views/add_exercise.dart @@ -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 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{ + + 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 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 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: [ + 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']); + }, + ); + }, + ), + ) + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/Views/exercises_view.dart b/lib/Views/exercises_view.dart index 452467a..21b42ff 100644 --- a/lib/Views/exercises_view.dart +++ b/lib/Views/exercises_view.dart @@ -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; @@ -53,20 +54,31 @@ class ExerciseViewState extends State{ ), 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((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']) - )); - }, - ); + 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), ), ); } diff --git a/lib/Views/new_workout_view.dart b/lib/Views/new_workout_view.dart index cf4f01c..ea23efc 100644 --- a/lib/Views/new_workout_view.dart +++ b/lib/Views/new_workout_view.dart @@ -38,7 +38,7 @@ class NewWorkoutViewState extends State{ 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, @@ -46,6 +46,7 @@ class NewWorkoutViewState extends State{ Padding( padding: EdgeInsets.all(8), child: TextField( + keyboardType: TextInputType.number, autocorrect: true, decoration: InputDecoration( border: OutlineInputBorder(),