Skip to content

Instantly share code, notes, and snippets.

View anisalibegic's full-sized avatar
🎯
Focusing on Flutter

Anis Alibegić anisalibegic

🎯
Focusing on Flutter
View GitHub Profile
@anisalibegic
anisalibegic / safe_set_state_mixin.dart
Created May 21, 2021 07:50
This mixin overrides default setState method and adds a check if widget is still mounted in the widget tree.
import 'package:flutter/widgets.dart';
mixin SafeSetStateMixin<T extends StatefulWidget> on State<T> {
@override
void setState(VoidCallback fn) {
if (!mounted) return;
super.setState(fn);
}
}