set_state_async 0.1.3
set_state_async: ^0.1.3 copied to clipboard
A mixin for avoiding State.setState during build or locking issue and improving 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() or markNeedsBuild() called during build or when widget tree was 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
SetStateAsyncmixin to yourStateclass:
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.