【问题标题】:How to make loading progress when sending data to the database向数据库发送数据时如何进行加载
【发布时间】:2023-03-16 13:00:02
【问题描述】:

假设每次我想向数据库发送数据,如何让它看起来像页面正在加载?

  HashMap ApiParams1 = new HashMap<String, String>();
  ApiParams1.putIfAbsent("email", () => _email.text);
  ApiParams1.putIfAbsent("mobileno", () => _phonenumber.text);
  initApi("http://xxxxxxxxx/xxxx",
          ApiParams1)
      .PostApi()
      .then((response) {
    var jsondecode = json.decode(response);

    if (jsondecode["status"].toString() == "success") {
      Fluttertoast.showToast(
          msg: jsondecode["message"].toString(),
          backgroundColor: Colors.green,
          toastLength: Toast.LENGTH_LONG);
      saveEmaildetails();
    } else if (jsondecode["status"].toString() != "success") {
      Fluttertoast.showToast(
        msg: jsondecode["message"],
        backgroundColor: Colors.red,
        toastLength: Toast.LENGTH_LONG);
    }
  });

我希望当我单击提交按钮时,它会显示一些加载以通知用户他们正在将数据发送到数据库。我想确保用户不会多次单击按钮。

【问题讨论】:

    标签: api dart flutter


    【解决方案1】:

    使用 statefull 小部件并创建一个名为 isLoading 的布尔变量,该变量最初为 false。

    当用户按下按钮时,使用 setState 将其设置为 true,当请求完成时,再次使用 setState 将其设置为 false。

    在您的按钮小部件内将 onPressed 更改为

    onPressed: isLoading 
                 ? null
                 : _handlePress()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-12
      • 1970-01-01
      • 1970-01-01
      • 2023-02-07
      • 1970-01-01
      • 2019-11-13
      • 2017-05-20
      • 1970-01-01
      相关资源
      最近更新 更多