diff --git a/packages/flutter/lib/src/material/dropdown_menu.dart b/packages/flutter/lib/src/material/dropdown_menu.dart index 3beb00d3dda3..ca439552ba00 100644 --- a/packages/flutter/lib/src/material/dropdown_menu.dart +++ b/packages/flutter/lib/src/material/dropdown_menu.dart @@ -541,6 +541,9 @@ class _DropdownMenuState extends State> { @override void dispose() { + if (widget.controller == null) { + _textEditingController.dispose(); + } super.dispose(); } diff --git a/packages/flutter/test/material/dropdown_menu_theme_test.dart b/packages/flutter/test/material/dropdown_menu_theme_test.dart index dabb572db829..f0c0f1796232 100644 --- a/packages/flutter/test/material/dropdown_menu_theme_test.dart +++ b/packages/flutter/test/material/dropdown_menu_theme_test.dart @@ -100,7 +100,7 @@ void main() { expect(material.textStyle?.color, themeData.colorScheme.onSurface); }); - testWidgets('ThemeData.dropdownMenuTheme overrides defaults', (WidgetTester tester) async { + testWidgetsWithLeakTracking('ThemeData.dropdownMenuTheme overrides defaults', (WidgetTester tester) async { final ThemeData theme = ThemeData( dropdownMenuTheme: DropdownMenuThemeData( textStyle: TextStyle(