我正在尝试从我的 flutter 应用程序连接数据库,并且我想将我在文本字段中写入的值发布到数据库。我写了一些代码,但无法发布到数据库,它给了我错误。我想我必须编辑我的 php 代码,但我不知道如何编辑,请帮助我...下面的代码和错误
Future<List> sendData() async {
await http.post(
"https://www.ekspar.com/trying/go.php",
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
body: {
"adi": nameController.text,
"soyadi": surnameController.text,
},
);
json.decode(response.body);
}
@override
void initState() {
sendData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
body: Scaffold(
appBar: AppBar(
title: Text("Register"),
),
body: Container(
child: Center(
child: Column(
children: <Widget>[
Text(
"ad",
style: TextStyle(fontSize: 18.0),
),
TextField(
controller: nameController,
decoration: InputDecoration(hintText: 'ad'),
),
Text(
"soyad",
style: TextStyle(fontSize: 18.0),
),
TextField(
controller: surnameController,
decoration: InputDecoration(hintText: 'soyad'),
),
RaisedButton(
child: Text("Register"),
onPressed: () {
setState(() {
_build();
});
sendData();
},
),
_build()
],
),
),
),
)
//(_buildBody(),
);
}
冉冉说