Skip to content

Commit a7dbec3

Browse files
authored
Cover more tests with leak tracking. (#133958)
1 parent 7625c10 commit a7dbec3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1989
-1649
lines changed

packages/flutter/lib/src/material/time_picker.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,15 @@ class _TimePickerDialogState extends State<TimePickerDialog> with RestorationMix
22062206
static const Size _kTimePickerMinLandscapeSize = Size(416, 248);
22072207
static const Size _kTimePickerMinInputSize = Size(312, 196);
22082208

2209+
@override
2210+
void dispose() {
2211+
_selectedTime.dispose();
2212+
_entryMode.dispose();
2213+
_autovalidateMode.dispose();
2214+
_orientation.dispose();
2215+
super.dispose();
2216+
}
2217+
22092218
@override
22102219
String? get restorationId => widget.restorationId;
22112220

@@ -2586,6 +2595,13 @@ class _TimePickerState extends State<_TimePicker> with RestorationMixin {
25862595
void dispose() {
25872596
_vibrateTimer?.cancel();
25882597
_vibrateTimer = null;
2598+
_orientation.dispose();
2599+
_selectedTime.dispose();
2600+
_hourMinuteMode.dispose();
2601+
_lastModeAnnounced.dispose();
2602+
_autofocusHour.dispose();
2603+
_autofocusMinute.dispose();
2604+
_announcedInitialTime.dispose();
25892605
super.dispose();
25902606
}
25912607

packages/flutter/test/material/checkbox_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ void main() {
644644

645645
testWidgetsWithLeakTracking('Material2 - Checkbox is focusable and has correct focus color', (WidgetTester tester) async {
646646
final FocusNode focusNode = FocusNode(debugLabel: 'Checkbox');
647-
addTearDown(() => focusNode.dispose());
647+
addTearDown(focusNode.dispose);
648648
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
649649
bool? value = true;
650650
Widget buildApp({bool enabled = true}) {
@@ -715,7 +715,7 @@ void main() {
715715

716716
testWidgetsWithLeakTracking('Material3 - Checkbox is focusable and has correct focus color', (WidgetTester tester) async {
717717
final FocusNode focusNode = FocusNode(debugLabel: 'Checkbox');
718-
addTearDown(() => focusNode.dispose());
718+
addTearDown(focusNode.dispose);
719719
final ThemeData theme = ThemeData(useMaterial3: true);
720720
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
721721
bool? value = true;
@@ -1244,7 +1244,7 @@ void main() {
12441244

12451245
testWidgetsWithLeakTracking('Checkbox fill color resolves in hovered/focused states', (WidgetTester tester) async {
12461246
final FocusNode focusNode = FocusNode(debugLabel: 'checkbox');
1247-
addTearDown(() => focusNode.dispose());
1247+
addTearDown(focusNode.dispose);
12481248

12491249
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
12501250
const Color hoveredFillColor = Color(0xFF000001);
@@ -1345,7 +1345,7 @@ void main() {
13451345

13461346
testWidgetsWithLeakTracking('Material2 - Checkbox default overlay color in active/pressed/focused/hovered states', (WidgetTester tester) async {
13471347
final FocusNode focusNode = FocusNode(debugLabel: 'Checkbox');
1348-
addTearDown(() => focusNode.dispose());
1348+
addTearDown(focusNode.dispose);
13491349
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
13501350

13511351
final ThemeData theme = ThemeData(useMaterial3: false);
@@ -1413,7 +1413,7 @@ void main() {
14131413

14141414
testWidgetsWithLeakTracking('Material3 - Checkbox default overlay color in active/pressed/focused/hovered states', (WidgetTester tester) async {
14151415
final FocusNode focusNode = FocusNode(debugLabel: 'Checkbox');
1416-
addTearDown(() => focusNode.dispose());
1416+
addTearDown(focusNode.dispose);
14171417
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
14181418

14191419
final ThemeData theme = ThemeData(useMaterial3: true);
@@ -1479,7 +1479,7 @@ void main() {
14791479

14801480
testWidgetsWithLeakTracking('Checkbox overlay color resolves in active/pressed/focused/hovered states', (WidgetTester tester) async {
14811481
final FocusNode focusNode = FocusNode(debugLabel: 'Checkbox');
1482-
addTearDown(() => focusNode.dispose());
1482+
addTearDown(focusNode.dispose);
14831483
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
14841484

14851485
const Color fillColor = Color(0xFF000000);
@@ -1973,7 +1973,7 @@ void main() {
19731973

19741974
testWidgetsWithLeakTracking('Material3 - Checkbox has default error color when isError is set to true', (WidgetTester tester) async {
19751975
final FocusNode focusNode = FocusNode(debugLabel: 'Checkbox');
1976-
addTearDown(() => focusNode.dispose());
1976+
addTearDown(focusNode.dispose);
19771977
final ThemeData themeData = ThemeData(useMaterial3: true);
19781978
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
19791979
bool? value = true;
@@ -2046,7 +2046,7 @@ void main() {
20462046

20472047
testWidgetsWithLeakTracking('Material3 - Checkbox MaterialStateBorderSide applies in error states', (WidgetTester tester) async {
20482048
final FocusNode focusNode = FocusNode(debugLabel: 'Checkbox');
2049-
addTearDown(() => focusNode.dispose());
2049+
addTearDown(focusNode.dispose);
20502050
final ThemeData themeData = ThemeData(useMaterial3: true);
20512051
const Color borderColor = Color(0xffffeb3b);
20522052
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;

packages/flutter/test/material/dialog_test.dart

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void main() {
111111
expect(materialWidget.color, customColor);
112112
});
113113

114-
testWidgets('Dialog Defaults', (WidgetTester tester) async {
114+
testWidgetsWithLeakTracking('Dialog Defaults', (WidgetTester tester) async {
115115
const AlertDialog dialog = AlertDialog(
116116
title: Text('Title'),
117117
content: Text('Y'),
@@ -146,7 +146,7 @@ void main() {
146146
expect(material3Widget.elevation, 6.0);
147147
});
148148

149-
testWidgets('Dialog.fullscreen Defaults', (WidgetTester tester) async {
149+
testWidgetsWithLeakTracking('Dialog.fullscreen Defaults', (WidgetTester tester) async {
150150
const String dialogTextM2 = 'Fullscreen Dialog - M2';
151151
const String dialogTextM3 = 'Fullscreen Dialog - M3';
152152

@@ -447,7 +447,7 @@ void main() {
447447
expect(textRect.bottom, dialogRect.bottom - customPadding.bottom);
448448
});
449449

450-
testWidgets('Barrier dismissible', (WidgetTester tester) async {
450+
testWidgetsWithLeakTracking('Barrier dismissible', (WidgetTester tester) async {
451451
await tester.pumpWidget(
452452
const MaterialApp(
453453
home: Material(
@@ -644,7 +644,7 @@ void main() {
644644
expect(actionsSize.width, dialogSize.width - (30.0 * 2));
645645
});
646646

647-
testWidgets('AlertDialog.buttonPadding defaults', (WidgetTester tester) async {
647+
testWidgetsWithLeakTracking('AlertDialog.buttonPadding defaults', (WidgetTester tester) async {
648648
final GlobalKey key1 = GlobalKey();
649649
final GlobalKey key2 = GlobalKey();
650650

@@ -1904,7 +1904,7 @@ void main() {
19041904
semantics.dispose();
19051905
});
19061906

1907-
testWidgets('Dismissible.confirmDismiss defers to an AlertDialog', (WidgetTester tester) async {
1907+
testWidgetsWithLeakTracking('Dismissible.confirmDismiss defers to an AlertDialog', (WidgetTester tester) async {
19081908
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
19091909
final List<int> dismissedItems = <int>[];
19101910

@@ -2035,7 +2035,7 @@ void main() {
20352035
});
20362036

20372037
// Regression test for https://github.com/flutter/flutter/issues/28505.
2038-
testWidgets('showDialog only gets Theme from context on the first call', (WidgetTester tester) async {
2038+
testWidgetsWithLeakTracking('showDialog only gets Theme from context on the first call', (WidgetTester tester) async {
20392039
Widget buildFrame(Key builderKey) {
20402040
return MaterialApp(
20412041
home: Center(
@@ -2072,7 +2072,7 @@ void main() {
20722072
await tester.pump();
20732073
});
20742074

2075-
testWidgets('showDialog safe area', (WidgetTester tester) async {
2075+
testWidgetsWithLeakTracking('showDialog safe area', (WidgetTester tester) async {
20762076
await tester.pumpWidget(
20772077
MaterialApp(
20782078
builder: (BuildContext context, Widget? child) {
@@ -2337,7 +2337,7 @@ void main() {
23372337
});
23382338

23392339
group('AlertDialog.scrollable: ', () {
2340-
testWidgets('Title is scrollable', (WidgetTester tester) async {
2340+
testWidgetsWithLeakTracking('Title is scrollable', (WidgetTester tester) async {
23412341
final Key titleKey = UniqueKey();
23422342
final AlertDialog dialog = AlertDialog(
23432343
title: Container(
@@ -2377,7 +2377,7 @@ void main() {
23772377
expect(box.localToGlobal(Offset.zero), equals(originalOffset.translate(0.0, -200.0)));
23782378
});
23792379

2380-
testWidgets('Title and content are scrollable', (WidgetTester tester) async {
2380+
testWidgetsWithLeakTracking('Title and content are scrollable', (WidgetTester tester) async {
23812381
final Key titleKey = UniqueKey();
23822382
final Key contentKey = UniqueKey();
23832383
final AlertDialog dialog = AlertDialog(
@@ -2416,7 +2416,7 @@ void main() {
24162416
});
24172417
});
24182418

2419-
testWidgets('Dialog with RouteSettings', (WidgetTester tester) async {
2419+
testWidgetsWithLeakTracking('Dialog with RouteSettings', (WidgetTester tester) async {
24202420
late RouteSettings currentRouteSetting;
24212421

24222422
await tester.pumpWidget(
@@ -2510,7 +2510,7 @@ void main() {
25102510
semantics.dispose();
25112511
});
25122512

2513-
testWidgets('DialogRoute is state restorable', (WidgetTester tester) async {
2513+
testWidgetsWithLeakTracking('DialogRoute is state restorable', (WidgetTester tester) async {
25142514
await tester.pumpWidget(
25152515
const MaterialApp(
25162516
restorationScopeId: 'app',
@@ -2706,7 +2706,7 @@ void main() {
27062706
}
27072707
});
27082708

2709-
testWidgets('showAdaptiveDialog should not allow dismiss on barrier on iOS by default', (WidgetTester tester) async {
2709+
testWidgetsWithLeakTracking('showAdaptiveDialog should not allow dismiss on barrier on iOS by default', (WidgetTester tester) async {
27102710
await tester.pumpWidget(
27112711
MaterialApp(
27122712
theme: ThemeData(platform: TargetPlatform.iOS),
@@ -2766,9 +2766,11 @@ void main() {
27662766
expect(find.text('Dialog2'), findsOneWidget);
27672767
});
27682768

2769-
testWidgets('Uses open focus traversal when overridden', (WidgetTester tester) async {
2769+
testWidgetsWithLeakTracking('Uses open focus traversal when overridden', (WidgetTester tester) async {
27702770
final FocusNode okNode = FocusNode();
2771+
addTearDown(okNode.dispose);
27712772
final FocusNode cancelNode = FocusNode();
2773+
addTearDown(cancelNode.dispose);
27722774

27732775
Future<bool> nextFocus() async {
27742776
final bool result = Actions.invoke(

0 commit comments

Comments
 (0)