Remove null exception when a disposed controller is set

pull/239/head
Till Friebe 4 years ago
parent 1fedaf0d13
commit 4c11b28cb9
  1. 12
      lib/src/widgets/cursor.dart

@ -139,10 +139,18 @@ class CursorCont extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
/// True when this [CursorCont] instance has been disposed.
///
/// A safety mechanism to prevent the value of a disposed controller from
/// getting set.
bool _isDisposed = false;
@override @override
void dispose() { void dispose() {
_blinkOpacityController.removeListener(_onColorTick); _blinkOpacityController.removeListener(_onColorTick);
stopCursorTimer(); stopCursorTimer();
_isDisposed = true;
_blinkOpacityController.dispose(); _blinkOpacityController.dispose();
show.dispose(); show.dispose();
blink.dispose(); blink.dispose();
@ -174,6 +182,10 @@ class CursorCont extends ChangeNotifier {
} }
void startCursorTimer() { void startCursorTimer() {
if (_isDisposed) {
return;
}
_targetCursorVisibility = true; _targetCursorVisibility = true;
_blinkOpacityController.value = 1.0; _blinkOpacityController.value = 1.0;

Loading…
Cancel
Save