我有一个消息传递应用程序,您可以在其中从要与之交谈的用户列表中进行选择。应用栏上有一个图标按钮,您可以在其中确认要发送消息的用户组。现在,用户可以多次向图标按钮发送垃圾邮件。我想在按下一次图标按钮后禁用它。我有一个 bool iconEnabled 变量,但我不确定将它放在 onPressed 的哪个位置。
return Scaffold(
appBar: AppBar(
title: Text("Users"),
actions: <Widget>[
new IconButton(
icon: new Icon(Icons.check),
onPressed: widget.isNew
? () async {
if (newUsers.length == 0) {
return;
}
widget.thread.users.addAll(newUsers);
widget.thread.userIds.addAll(widget.thread.users.map((user) => user.id).toList());
widget.thread.users = widget.thread.users;
// Call New Thread
var threadId = await Client.addThread(widget.thread);
widget.thread.id = threadId;
Navigator.pushReplacement(
context,
MaterialPageRoute(
settings: RouteSettings(name: "MessagePage"),
builder: (context) => MessagePage(
thread: widget.thread,
),
),
);
}
: () {
if (newUsers.length == 0) {
return;
}
widget.thread.users.addAll(newUsers);
widget.thread.userIds.addAll(widget.thread.users.map((user) => user.id).toList());
widget.thread.users = widget.thread.users;
// Call users patch
Client.addUsers(widget.thread);
Navigator.pop(context);
},
),
],
),