set_state_async 1.1.0
set_state_async: ^1.1.0 copied to clipboard
A mixin to avoid "setState while widget is building or locked" issue and improve performance.
About #
SetStateAsync
is a mixin that defers multiple setState
calls into one within the same event loop.
This approach helps reduce overhead when calling setState
multiple times in quick succession, preventing "setState while widget is building or locked" issue and improving performance.
Installation #
- Run the following command in your project directory:
flutter pub add set_state_async
- Add the following code to your dart file:
import 'package:set_state_async/set_state_async.dart';
- Add
SetStateAsync
mixin to yourState
class:
class _MyWidgetState extends State<MyWidget> with SetStateAsync {
// ...
}
Usage #
Just call setStateAsync
instead of setState
. An optional callback can be passed if you need to perform changes just before rebuilding the widget.
For more information, please check example or API reference.