Created
May 21, 2021 07:50
-
-
Save anisalibegic/06ba5db014dfded055a1fde7d13fb9cf to your computer and use it in GitHub Desktop.
This mixin overrides default setState method and adds a check if widget is still mounted in the widget tree.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/widgets.dart'; | |
mixin SafeSetStateMixin<T extends StatefulWidget> on State<T> { | |
@override | |
void setState(VoidCallback fn) { | |
if (!mounted) return; | |
super.setState(fn); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment