From c3445dc1907fa705a256b7279228700353fbbcd9 Mon Sep 17 00:00:00 2001 From: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Date: Tue, 16 Apr 2024 22:53:27 +0800 Subject: [PATCH] Fix memory leak in `BottomNavigationBar` (#146748) --- .../flutter/lib/src/material/bottom_navigation_bar.dart | 3 +++ packages/flutter/test/material/bottom_sheet_test.dart | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index 6e981ec86bf7..32037ece8b18 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -883,6 +883,9 @@ class _BottomNavigationBarState extends State with TickerPr for (final _Circle circle in _circles) { circle.dispose(); } + for (final CurvedAnimation animation in _animations) { + animation.dispose(); + } super.dispose(); } diff --git a/packages/flutter/test/material/bottom_sheet_test.dart b/packages/flutter/test/material/bottom_sheet_test.dart index 101191a3bd65..20b65da0358d 100644 --- a/packages/flutter/test/material/bottom_sheet_test.dart +++ b/packages/flutter/test/material/bottom_sheet_test.dart @@ -7,6 +7,7 @@ import 'dart:ui'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; import '../widgets/semantics_tester.dart'; @@ -1282,7 +1283,10 @@ void main() { await checkDragHandleAndColors(); }); - testWidgets('showModalBottomSheet does not use root Navigator by default', (WidgetTester tester) async { + testWidgets('showModalBottomSheet does not use root 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 ['CurvedAnimation']), + (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( home: Scaffold( body: Navigator(onGenerateRoute: (RouteSettings settings) => MaterialPageRoute(builder: (_) {