-2

I am using the below function to be called on the button press, which updates the data in the backend server. If the function is successful, I want the page to reload and new data to be updated on the page. how should I do that in Flutter?

approvalbutton() async {

    var jsonResponse = null;

    var response = await http.post(approvalapiurl, body: data);
    if (response.statusCode == 200) {
      jsonResponse = json.decode(response.body);
      print('Response status: ${response.statusCode}');
      print('Response body: ${response.body}');
      String errorcheck = jsonResponse['error'];

      if (errorcheck == "false") {


       print('success');

      }
      else {
       print('failed');
      }
    }

  }

1 Answers1

0

Use setState() method to rebuild a stateful widget

lenz
  • 2,193
  • 17
  • 31
  • how exactly to call? please guide me I am new to flutter –  Sep 02 '20 at 11:31
  • 1
    This is very basic Flutter (the default counter app has an example of this). I recommend you read up on stateful VS stateless widgets. It will save you lots of headaches. Also,this can help wih setState https://stackoverflow.com/questions/51283077/when-use-setstate-in-flutter – lenz Sep 02 '20 at 11:40
  • Usefule read on Stateful VS Stateless [here](https://flutter.dev/docs/development/ui/interactive) – lenz Sep 02 '20 at 11:42