I have a messaging application where you can select from a list of users to talk with. There is an icon button on the App Bar where you can confirm the group of users you want to message. Right now, the user can spam the icon button multiple times. I want to disable the icon button after it has been pressed once. I have a bool iconEnabled variable, but I am unsure where to place it in 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);
},
),
],
),