mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix memory leaks in _PopupMenuRoute (#148373)
This commit is contained in:
parent
ffae7c60c2
commit
8b129b9b89
@ -880,10 +880,12 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
|
||||
final Clip clipBehavior;
|
||||
final AnimationStyle? popUpAnimationStyle;
|
||||
|
||||
CurvedAnimation? _animation;
|
||||
|
||||
@override
|
||||
Animation<double> createAnimation() {
|
||||
if (popUpAnimationStyle != AnimationStyle.noAnimation) {
|
||||
return CurvedAnimation(
|
||||
return _animation ??= CurvedAnimation(
|
||||
parent: super.createAnimation(),
|
||||
curve: popUpAnimationStyle?.curve ?? Curves.linear,
|
||||
reverseCurve: popUpAnimationStyle?.reverseCurve ?? const Interval(0.0, _kMenuCloseIntervalEnd),
|
||||
@ -962,6 +964,12 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
|
||||
Set<Rect> _avoidBounds(MediaQueryData mediaQuery) {
|
||||
return DisplayFeatureSubScreen.avoidBounds(mediaQuery).toSet();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_animation?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// Show a popup menu that contains the `items` at `position`.
|
||||
|
||||
@ -9,6 +9,7 @@ import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
|
||||
|
||||
import '../widgets/semantics_tester.dart';
|
||||
import 'feedback_tester.dart';
|
||||
@ -2096,7 +2097,10 @@ void main() {
|
||||
expect(find.text('PopupMenuButton icon'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('showMenu uses nested navigator by default', (WidgetTester tester) async {
|
||||
testWidgets('showMenu uses nested navigator by default',
|
||||
// TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in]
|
||||
experimentalLeakTesting: LeakTesting.settings.withTracked(classes: const <String>['CurvedAnimation']),
|
||||
(WidgetTester tester) async {
|
||||
final MenuObserver rootObserver = MenuObserver();
|
||||
final MenuObserver nestedObserver = MenuObserver();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user