【问题标题】:How to get the page refreshed after the function calling in flutter?如何在flutter中调用函数后刷新页面?
【发布时间】:2020-12-21 13:30:09
【问题描述】:

我正在使用以下函数在按下按钮时调用,它会更新后端服务器中的数据。如果该功能成功,我希望页面重新加载并在页面上更新新数据。我应该如何在 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');
      }
    }

  }

【问题讨论】:

    标签: json flutter dart page-refresh


    【解决方案1】:

    使用 setState() 方法重建有状态的小部件

    【讨论】:

    • 具体怎么调用?请指导我,我是 Flutter 的新手
    • 这是非常基本的 Flutter(默认计数器应用有一个示例)。我建议您阅读有状态 VS 无状态小部件。它将为您省去很多麻烦。此外,这可以帮助 setState stackoverflow.com/questions/51283077/…
    • Stateful VS Stateless here的有用阅读
    猜你喜欢
    • 2018-01-21
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    • 2015-03-01
    • 1970-01-01
    • 2018-02-26
    • 2015-07-25
    • 1970-01-01
    相关资源
    最近更新 更多