Unverified Commit 7625c10f authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

_MaterialAppState should dispose MaterialHeroController. (#133951)

parent af1b7494
...@@ -880,6 +880,12 @@ class _MaterialAppState extends State<MaterialApp> { ...@@ -880,6 +880,12 @@ class _MaterialAppState extends State<MaterialApp> {
_heroController = MaterialApp.createMaterialHeroController(); _heroController = MaterialApp.createMaterialHeroController();
} }
@override
void dispose() {
_heroController.dispose();
super.dispose();
}
// Combine the Localizations for Material with the ones contributed // Combine the Localizations for Material with the ones contributed
// by the localizationsDelegates parameter, if any. Only the first delegate // by the localizationsDelegates parameter, if any. Only the first delegate
// of a particular LocalizationsDelegate.type is loaded so the // of a particular LocalizationsDelegate.type is loaded so the
......
...@@ -612,6 +612,19 @@ class _HeroFlight { ...@@ -612,6 +612,19 @@ class _HeroFlight {
navigator.userGestureInProgressNotifier.addListener(delayedPerformAnimationUpdate); navigator.userGestureInProgressNotifier.addListener(delayedPerformAnimationUpdate);
} }
/// Releases resources.
@mustCallSuper
void dispose() {
if (overlayEntry != null) {
overlayEntry!.remove();
overlayEntry!.dispose();
overlayEntry = null;
_proxyAnimation.parent = null;
_proxyAnimation.removeListener(onTick);
_proxyAnimation.removeStatusListener(_handleAnimationUpdate);
}
}
void onTick() { void onTick() {
final RenderBox? toHeroBox = (!_aborted && manifest.toHero.mounted) final RenderBox? toHeroBox = (!_aborted && manifest.toHero.mounted)
? manifest.toHero.context.findRenderObject() as RenderBox? ? manifest.toHero.context.findRenderObject() as RenderBox?
...@@ -1027,6 +1040,14 @@ class HeroController extends NavigatorObserver { ...@@ -1027,6 +1040,14 @@ class HeroController extends NavigatorObserver {
}, },
); );
} }
/// Releases resources.
@mustCallSuper
void dispose() {
for (final _HeroFlight flight in _flights.values) {
flight.dispose();
}
}
} }
/// Enables or disables [Hero]es in the widget subtree. /// Enables or disables [Hero]es in the widget subtree.
......
...@@ -14,6 +14,7 @@ import 'package:flutter/foundation.dart'; ...@@ -14,6 +14,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() { void main() {
testWidgets('SnackBar control test', (WidgetTester tester) async { testWidgets('SnackBar control test', (WidgetTester tester) async {
...@@ -2542,7 +2543,9 @@ void main() { ...@@ -2542,7 +2543,9 @@ void main() {
expect(find.text(secondHeader), findsOneWidget); expect(find.text(secondHeader), findsOneWidget);
}); });
testWidgets('Should have only one SnackBar during back swipe navigation', (WidgetTester tester) async { testWidgetsWithLeakTracking('Should have only one SnackBar during back swipe navigation',
leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed(),
(WidgetTester tester) async {
const String snackBarText = 'hello snackbar'; const String snackBarText = 'hello snackbar';
const Key snackTarget = Key('snack-target'); const Key snackTarget = Key('snack-target');
const Key transitionTarget = Key('transition-target'); const Key transitionTarget = Key('transition-target');
......
...@@ -865,7 +865,7 @@ void main() { ...@@ -865,7 +865,7 @@ void main() {
); );
}); });
testWidgets('Material3 - SwitchListTile respects thumbColor in hovered/pressed states', (WidgetTester tester) async { testWidgetsWithLeakTracking('Material3 - SwitchListTile respects thumbColor in hovered/pressed states', (WidgetTester tester) async {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
const Color hoveredThumbColor = Color(0xFF4caf50); const Color hoveredThumbColor = Color(0xFF4caf50);
const Color pressedThumbColor = Color(0xFFF44336); const Color pressedThumbColor = Color(0xFFF44336);
......
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