Unverified Commit 5c17a37b authored by Tomasz Gucio's avatar Tomasz Gucio Committed by GitHub

Dispose overlay entries (#132826)

parent 901a392a
...@@ -138,6 +138,7 @@ class _OverlayExampleState extends State<OverlayExample> { ...@@ -138,6 +138,7 @@ class _OverlayExampleState extends State<OverlayExample> {
// Remove the OverlayEntry. // Remove the OverlayEntry.
void removeHighlightOverlay() { void removeHighlightOverlay() {
overlayEntry?.remove(); overlayEntry?.remove();
overlayEntry?.dispose();
overlayEntry = null; overlayEntry = null;
} }
......
...@@ -572,6 +572,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker ...@@ -572,6 +572,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
}); });
} }
_lastOverlayEntry?.remove(); _lastOverlayEntry?.remove();
_lastOverlayEntry?.dispose();
_lastOverlayEntry = null; _lastOverlayEntry = null;
case AnimationStatus.completed: case AnimationStatus.completed:
...@@ -585,6 +586,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker ...@@ -585,6 +586,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
// one frame. // one frame.
SchedulerBinding.instance.addPostFrameCallback((Duration _) { SchedulerBinding.instance.addPostFrameCallback((Duration _) {
_lastOverlayEntry?.remove(); _lastOverlayEntry?.remove();
_lastOverlayEntry?.dispose();
_lastOverlayEntry = null; _lastOverlayEntry = null;
_openController.reset(); _openController.reset();
}); });
......
...@@ -484,10 +484,9 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin ...@@ -484,10 +484,9 @@ class _RangeSliderState extends State<RangeSlider> with TickerProviderStateMixin
enableController.dispose(); enableController.dispose();
startPositionController.dispose(); startPositionController.dispose();
endPositionController.dispose(); endPositionController.dispose();
if (overlayEntry != null) { overlayEntry?.remove();
overlayEntry!.remove(); overlayEntry?.dispose();
overlayEntry = null; overlayEntry = null;
}
super.dispose(); super.dispose();
} }
...@@ -842,8 +841,9 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -842,8 +841,9 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
parent: _state.valueIndicatorController, parent: _state.valueIndicatorController,
curve: Curves.fastOutSlowIn, curve: Curves.fastOutSlowIn,
)..addStatusListener((AnimationStatus status) { )..addStatusListener((AnimationStatus status) {
if (status == AnimationStatus.dismissed && _state.overlayEntry != null) { if (status == AnimationStatus.dismissed) {
_state.overlayEntry!.remove(); _state.overlayEntry?.remove();
_state.overlayEntry?.dispose();
_state.overlayEntry = null; _state.overlayEntry = null;
} }
}); });
......
...@@ -654,10 +654,9 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin { ...@@ -654,10 +654,9 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
valueIndicatorController.dispose(); valueIndicatorController.dispose();
enableController.dispose(); enableController.dispose();
positionController.dispose(); positionController.dispose();
if (overlayEntry != null) { overlayEntry?.remove();
overlayEntry!.remove(); overlayEntry?.dispose();
overlayEntry = null; overlayEntry = null;
}
_focusNode?.dispose(); _focusNode?.dispose();
super.dispose(); super.dispose();
} }
...@@ -1116,8 +1115,9 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { ...@@ -1116,8 +1115,9 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
parent: _state.valueIndicatorController, parent: _state.valueIndicatorController,
curve: Curves.fastOutSlowIn, curve: Curves.fastOutSlowIn,
)..addStatusListener((AnimationStatus status) { )..addStatusListener((AnimationStatus status) {
if (status == AnimationStatus.dismissed && _state.overlayEntry != null) { if (status == AnimationStatus.dismissed) {
_state.overlayEntry!.remove(); _state.overlayEntry?.remove();
_state.overlayEntry?.dispose();
_state.overlayEntry = null; _state.overlayEntry = null;
} }
}); });
......
...@@ -446,6 +446,7 @@ class _RawAutocompleteState<T extends Object> extends State<RawAutocomplete<T>> ...@@ -446,6 +446,7 @@ class _RawAutocompleteState<T extends Object> extends State<RawAutocomplete<T>>
} }
_floatingOptions?.remove(); _floatingOptions?.remove();
_floatingOptions?.dispose();
if (_shouldShowOptions) { if (_shouldShowOptions) {
final OverlayEntry newFloatingOptions = OverlayEntry( final OverlayEntry newFloatingOptions = OverlayEntry(
builder: (BuildContext context) { builder: (BuildContext context) {
...@@ -562,6 +563,7 @@ class _RawAutocompleteState<T extends Object> extends State<RawAutocomplete<T>> ...@@ -562,6 +563,7 @@ class _RawAutocompleteState<T extends Object> extends State<RawAutocomplete<T>>
_focusNode.dispose(); _focusNode.dispose();
} }
_floatingOptions?.remove(); _floatingOptions?.remove();
_floatingOptions?.dispose();
_floatingOptions = null; _floatingOptions = null;
super.dispose(); super.dispose();
} }
......
...@@ -568,6 +568,7 @@ class _HeroFlight { ...@@ -568,6 +568,7 @@ class _HeroFlight {
assert(overlayEntry != null); assert(overlayEntry != null);
overlayEntry!.remove(); overlayEntry!.remove();
overlayEntry!.dispose();
overlayEntry = null; overlayEntry = null;
// We want to keep the hero underneath the current page hidden. If // We want to keep the hero underneath the current page hidden. If
// [AnimationStatus.completed], toHero will be the one on top and we keep // [AnimationStatus.completed], toHero will be the one on top and we keep
......
...@@ -242,9 +242,8 @@ class MagnifierController { ...@@ -242,9 +242,8 @@ class MagnifierController {
Widget? debugRequiredFor, Widget? debugRequiredFor,
OverlayEntry? below, OverlayEntry? below,
}) async { }) async {
if (overlayEntry != null) { _overlayEntry?.remove();
overlayEntry!.remove(); _overlayEntry?.dispose();
}
final OverlayState overlayState = Overlay.of( final OverlayState overlayState = Overlay.of(
context, context,
...@@ -257,7 +256,7 @@ class MagnifierController { ...@@ -257,7 +256,7 @@ class MagnifierController {
to: Navigator.maybeOf(context)?.context, to: Navigator.maybeOf(context)?.context,
); );
_overlayEntry = OverlayEntry( _overlayEntry = OverlayEntry(
builder: (BuildContext context) => capturedThemes.wrap(builder(context)), builder: (BuildContext context) => capturedThemes.wrap(builder(context)),
); );
overlayState.insert(overlayEntry!, below: below); overlayState.insert(overlayEntry!, below: below);
...@@ -307,6 +306,7 @@ class MagnifierController { ...@@ -307,6 +306,7 @@ class MagnifierController {
@visibleForTesting @visibleForTesting
void removeFromOverlay() { void removeFromOverlay() {
_overlayEntry?.remove(); _overlayEntry?.remove();
_overlayEntry?.dispose();
_overlayEntry = null; _overlayEntry = null;
} }
......
...@@ -832,6 +832,7 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke ...@@ -832,6 +832,7 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
_recognizer?.dispose(); _recognizer?.dispose();
_recognizer = null; _recognizer = null;
_overlayEntry?.remove(); _overlayEntry?.remove();
_overlayEntry?.dispose();
_overlayEntry = null; _overlayEntry = null;
_finalDropPosition = null; _finalDropPosition = null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment