addActionListener method Null safety
- ActionListenerCallback listener
Register a callback to listen for changes to the state of this action.
If you call this, you must call removeActionListener a matching number of times, or memory leaks will occur. To help manage this and avoid memory leaks, use of the ActionListener widget to register and unregister your listener appropriately is highly recommended.
If a listener had been added twice, and is removed once during an iteration (i.e. in response to a notification), it will still be called again. If, on the other hand, it is removed as many times as it was registered, then it will no longer be called. This odd behavior is the result of the Action not being able to determine which listener is being removed, since they are identical, and therefore conservatively still calling all the listeners when it knows that any are still registered.
This surprising behavior can be unexpectedly observed when registering a listener on two separate objects which are both forwarding all registrations to a common upstream object.
@mustCallSuper void addActionListener(ActionListenerCallback listener) => _listeners.add(listener);