I have a button in my flutter application that I want to send a request to an API after pressing it. I should wait for the process, and I want to have a progress circle that shows from the time I pressed the button until I get a response from the request. Can anyone help me with this? Thanks. Here is my onPressed code:
onPressed: () async {
Map data = {
//some data
};
var body = json.encode(data);
var response = await http.post(
Uri.parse("***MY API URL ***"),
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: body);
// print(response.body);
// print(response.statusCode);
if (response.statusCode == 201 || response.statusCode == 200) {
print('success');
Toast.show("Success", context);
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (BuildContext context) => const HomePage(),
),
(route) => false,
);
} else {
Toast.show("ERROR! Please try again.", context);
}
}