future_button icon indicating copy to clipboard operation
future_button copied to clipboard

setState only when widget is mounted

Open burhanrashid52 opened this issue 3 years ago • 0 comments

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.

burhanrashid52 avatar Mar 23 '22 07:03 burhanrashid52