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 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{ 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 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("Erstelle ein neues Workout"), ), body: Column( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsets.all(8), child: TextField( 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"), ), ) ], ), ); } }