future_button
future_button copied to clipboard
setState only when widget is mounted
Usecase
Use FutureIconButton in the list and remove each item quickly.
Problem
When the user removes an item quickly from the list some of the future buttons throw the following error.
Null check operator used on a null value
#0 State.setState (package:flutter/src/widgets/framework.dart:1287)
#1 GenericFutureButtonState.onPressed (package:future_button/src/generic_future_button.dart:277)
<asynchronous suspension>
This happens because the item list no longer exists in the tree and the future button tries to set the state on it.
Solution
A simple solution is to check if the widget is mounted before setting the state.