让我说每次我想将数据发送到数据库时,如何使其看起来像页面正在加载?
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);
}
});
我希望当我单击一个提交按钮时,它将显示一些负载,以通知用户他们正在将数据发送到数据库。我要确保用户不会多次单击按钮。
答案 0 :(得分:0)
使用有状态的窗口小部件并创建一个名为isLoading的布尔变量,该变量最初为false。
当用户按下按钮时,使用setState将其设置为true,当请求完成时,再次使用setState将其设置为false。
在按钮小部件内部将onPressed更改为
onPressed: isLoading
? null
: _handlePress()