I am building a flutter program that I want to hook up to my database, I know this is bad practice but it will be for personal use.
The php works and can communicate with the database, but when using an http post request method within my app it does not make it past the first print statement, "Made it to method" and is not calling the php function to update the database. I have the php file hard coded to write to a table and I'm not very concerned with that, I just cannot get the method to run my file.
I have followed a lot of guides online which is why I am using a different local host but still cannot get the method to complete. Any Ideas?
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() => runApp(new MyApp());
String username='';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter App with MYSQL',
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
TextEditingController name=new TextEditingController();
TextEditingController email=new TextEditingController();
TextEditingController mobile=new TextEditingController();
void post() async {
print("Made it to method");
final response = await http.post("http://10.0.2.2:8000/config.php", body: {
"name": name.text,
"email": email.text,
"mobile":mobile.text,
});
print("completed Method");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Register"),),
body: Container(
child: Center(
child: Column(
children: <Widget>[
Text("Username",style: TextStyle(fontSize: 18.0),),
TextField(
controller: name,
decoration: InputDecoration(
hintText: 'name'
),
),
Text("Email",style: TextStyle(fontSize: 18.0),),
TextField(
controller: email,
decoration: InputDecoration(
hintText: 'Email'
),
),
Text("Mobile",style: TextStyle(fontSize: 18.0),),
TextField(
controller: mobile,
decoration: InputDecoration(
hintText: 'Mobile'
),
),
RaisedButton(
child: Text("Register"),
onPressed: (){
post();
},
),
],
),
),
),
);
}
}