i tried to run a simple post request using flutter but i got redirected to this code the second code that starts with class is my actual code, i will be grateful if you can help me out
`
unawaited(xhr.onLoad.first.then((_) {
var body = (xhr.response as ByteBuffer).asUint8List();
completer.complete(StreamedResponse(
ByteStream.fromBytes(body), xhr.status!,
contentLength: body.length,
request: request,
headers: xhr.responseHeaders,
reasonPhrase: xhr.statusText));
}));
class MyHomePage extends StatefulWidget {
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final _formKey = GlobalKey<FormState>();
postData() async {
const url = 'https://jsonplaceholder.typicode.com/posts';
var response = await http.post(Uri.parse(url),
body: {'id': 1.toString(), 'name': 'paul', 'email': '[email protected]'});
print(response.body);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Post Data '),
),
body: Form(
key: _formKey,
child: Center(
child: ListView(
children: [
TextFormField(
decoration: InputDecoration(labelText: 'type your message '),
validator: (value) {
if (value!.isEmpty) {
return 'Please enter a valid message ';
}
return null;
},
onChanged: () {
setState(() {
});
},
),
SizedBox(
height: 10,
),
ElevatedButton(
onPressed: () {
// Perform registration logic here
postData();
},
child: const Text("submit"))
],
),
),
),
);
}
}
`
i checked the documentation to see wether their is a package i missed but known
i checked flutter_cors but still got the same issues i checked the documentation to see wether their is a package i missed but known
i checked flutter_cors but still got the same issues i checked the documentation to see wether their is a package i missed but known
i checked flutter_cors but still got the same issues
i checked the documentation to see wether their is a package i missed but known
i checked flutter_cors but still got the same issues