fitness-app/lib/Views/new_workout_view.dart

73 lines
1.9 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 NewWorkoutView extends StatefulWidget{
@override
State<StatefulWidget> createState() {
return new NewWorkoutViewState();
}
}
class WorkoutType{
String id, name, description, type, unit;
WorkoutType(this.id, this.name, this.description, this.type, this.unit);
}
class NewWorkoutViewState extends State<NewWorkoutView>{
String name = "";
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);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Füge eine Übung hinzu"),
),
body: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
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;
});
},
),
),
Padding(
padding: EdgeInsets.all(8),
child: RaisedButton(
onPressed: speichern,
child: Text("Workout erstellen"),
),
)
],
),
);
}
}