Skip to content

Commit f76936b

Browse files
authored
refactor: remove material in context_menu_controller_test, icon_test, list_wheel_scroll_view_test, media_query_test, platform_menu_bar_test (#182697)
This PR removes Material imports from context_menu_controller_test, icon_test, list_wheel_scroll_view_test, media_query_test, platform_menu_bar_test. part of: #177415 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
1 parent 4c4f5e7 commit f76936b

6 files changed

Lines changed: 129 additions & 139 deletions

File tree

dev/bots/check_tests_cross_imports.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,18 @@ class TestsCrossImportChecker {
152152
'packages/flutter/test/widgets/router_test.dart',
153153
'packages/flutter/test/widgets/scroll_notification_test.dart',
154154
'packages/flutter/test/widgets/editable_text_test.dart',
155-
'packages/flutter/test/widgets/icon_test.dart',
156155
'packages/flutter/test/widgets/sliver_cross_axis_group_test.dart',
157-
'packages/flutter/test/widgets/list_wheel_scroll_view_test.dart',
158156
'packages/flutter/test/widgets/pop_scope_test.dart',
159157
'packages/flutter/test/widgets/scrollbar_test.dart',
160158
'packages/flutter/test/widgets/scroll_physics_test.dart',
161159
'packages/flutter/test/widgets/obscured_animated_image_test.dart',
162-
'packages/flutter/test/widgets/platform_menu_bar_test.dart',
163160
'packages/flutter/test/widgets/inherited_test.dart',
164161
'packages/flutter/test/widgets/heroes_test.dart',
165162
'packages/flutter/test/widgets/container_test.dart',
166163
'packages/flutter/test/widgets/drawer_test.dart',
167164
'packages/flutter/test/widgets/framework_test.dart',
168165
'packages/flutter/test/widgets/absorb_pointer_test.dart',
169166
'packages/flutter/test/widgets/semantics_role_checks_test.dart',
170-
'packages/flutter/test/widgets/media_query_test.dart',
171167
'packages/flutter/test/widgets/editable_text_cursor_test.dart',
172168
'packages/flutter/test/widgets/sliver_fill_remaining_test.dart',
173169
'packages/flutter/test/widgets/editable_text_show_on_screen_test.dart',
@@ -189,7 +185,6 @@ class TestsCrossImportChecker {
189185
'packages/flutter/test/widgets/navigator_test.dart',
190186
'packages/flutter/test/widgets/page_view_test.dart',
191187
'packages/flutter/test/widgets/page_forward_transitions_test.dart',
192-
'packages/flutter/test/widgets/context_menu_controller_test.dart',
193188
'packages/flutter/test/widgets/slivers_test.dart',
194189
'packages/flutter/test/widgets/navigator_restoration_test.dart',
195190
'packages/flutter/test/widgets/sliver_prototype_item_extent_test.dart',

packages/flutter/test/widgets/context_menu_controller_test.dart

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:flutter/material.dart';
65
import 'package:flutter/services.dart';
6+
import 'package:flutter/widgets.dart';
77
import 'package:flutter_test/flutter_test.dart';
88

99
import 'clipboard_utils.dart';
1010
import 'editable_text_utils.dart';
11+
import 'widgets_app_tester.dart';
1112

1213
void main() {
14+
const kGreyColor = Color(0xFFAAAAAA);
15+
const kRedColor = Color(0xFFFF0000);
1316
final mockClipboard = MockClipboard();
1417
TestWidgetsFlutterBinding.ensureInitialized().defaultBinaryMessenger.setMockMethodCallHandler(
1518
SystemChannels.platform,
@@ -28,14 +31,12 @@ void main() {
2831
late final BuildContext context;
2932

3033
await tester.pumpWidget(
31-
MaterialApp(
32-
home: Scaffold(
33-
body: Builder(
34-
builder: (BuildContext localContext) {
35-
context = localContext;
36-
return const SizedBox.shrink();
37-
},
38-
),
34+
TestWidgetsApp(
35+
home: Builder(
36+
builder: (BuildContext localContext) {
37+
context = localContext;
38+
return const SizedBox.shrink();
39+
},
3940
),
4041
),
4142
);
@@ -97,14 +98,12 @@ void main() {
9798
late final BuildContext context;
9899

99100
await tester.pumpWidget(
100-
MaterialApp(
101-
home: Scaffold(
102-
body: Builder(
103-
builder: (BuildContext localContext) {
104-
context = localContext;
105-
return const SizedBox.shrink();
106-
},
107-
),
101+
TestWidgetsApp(
102+
home: Builder(
103+
builder: (BuildContext localContext) {
104+
context = localContext;
105+
return const SizedBox.shrink();
106+
},
108107
),
109108
),
110109
);
@@ -149,14 +148,12 @@ void main() {
149148
late final BuildContext context;
150149

151150
await tester.pumpWidget(
152-
MaterialApp(
153-
home: Scaffold(
154-
body: Builder(
155-
builder: (BuildContext localContext) {
156-
context = localContext;
157-
return const SizedBox.shrink();
158-
},
159-
),
151+
TestWidgetsApp(
152+
home: Builder(
153+
builder: (BuildContext localContext) {
154+
context = localContext;
155+
return const SizedBox.shrink();
156+
},
160157
),
161158
),
162159
);
@@ -195,24 +192,22 @@ void main() {
195192
addTearDown(focusNode.dispose);
196193

197194
await tester.pumpWidget(
198-
MaterialApp(
199-
home: Scaffold(
200-
body: Builder(
201-
builder: (BuildContext localContext) {
202-
context = localContext;
203-
return EditableText(
204-
controller: textEditingController,
205-
backgroundCursorColor: Colors.grey,
206-
focusNode: focusNode,
207-
style: const TextStyle(),
208-
cursorColor: Colors.red,
209-
selectionControls: materialTextSelectionHandleControls,
210-
contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) {
211-
return Placeholder(key: builtInKey);
212-
},
213-
);
214-
},
215-
),
195+
TestWidgetsApp(
196+
home: Builder(
197+
builder: (BuildContext localContext) {
198+
context = localContext;
199+
return EditableText(
200+
controller: textEditingController,
201+
backgroundCursorColor: kGreyColor,
202+
focusNode: focusNode,
203+
style: const TextStyle(),
204+
cursorColor: kRedColor,
205+
selectionControls: testTextSelectionHandleControls,
206+
contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) {
207+
return Placeholder(key: builtInKey);
208+
},
209+
);
210+
},
216211
),
217212
),
218213
);

packages/flutter/test/widgets/icon_test.dart

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:flutter/material.dart';
5+
import 'package:flutter/widgets.dart';
66
import 'package:flutter_test/flutter_test.dart';
77

88
import 'semantics_tester.dart';
99

1010
void main() {
11+
const kTimeToLeaveIcon = IconData(0xe65f, fontFamily: 'MaterialIcons');
12+
const kAbcIcon = IconData(0xf04b6, fontFamily: 'MaterialIcons');
13+
const kSaveIcon = IconData(0xe550, fontFamily: 'MaterialIcons');
14+
1115
testWidgets('Can set opacity for an Icon', (WidgetTester tester) async {
1216
await tester.pumpWidget(
1317
const Directionality(
@@ -241,7 +245,9 @@ void main() {
241245
await tester.pumpWidget(
242246
const Directionality(
243247
textDirection: TextDirection.ltr,
244-
child: Center(child: Icon(Icons.title, semanticLabel: 'a label')),
248+
child: Center(
249+
child: Icon(IconData(0xe668, fontFamily: 'MaterialIcons'), semanticLabel: 'a label'),
250+
),
245251
),
246252
);
247253

@@ -271,7 +277,7 @@ void main() {
271277
await tester.pumpWidget(
272278
const Directionality(
273279
textDirection: TextDirection.ltr,
274-
child: Center(child: Icon(Icons.time_to_leave)),
280+
child: Center(child: Icon(kTimeToLeaveIcon)),
275281
),
276282
);
277283

@@ -280,7 +286,7 @@ void main() {
280286
await tester.pumpWidget(
281287
const Directionality(
282288
textDirection: TextDirection.ltr,
283-
child: Center(child: Icon(Icons.time_to_leave, semanticLabel: 'a label')),
289+
child: Center(child: Icon(kTimeToLeaveIcon, semanticLabel: 'a label')),
284290
),
285291
);
286292

@@ -310,7 +316,7 @@ void main() {
310316
WidgetTester tester,
311317
) async {
312318
await tester.pumpWidget(
313-
const Directionality(textDirection: TextDirection.ltr, child: Icon(Icons.abc)),
319+
const Directionality(textDirection: TextDirection.ltr, child: Icon(kAbcIcon)),
314320
);
315321

316322
RichText text = tester.widget(find.byType(RichText));
@@ -324,7 +330,7 @@ void main() {
324330
await tester.pumpWidget(
325331
const Directionality(
326332
textDirection: TextDirection.ltr,
327-
child: Icon(Icons.abc, fill: 0.5, weight: 300, grade: 200, opticalSize: 48),
333+
child: Icon(kAbcIcon, fill: 0.5, weight: 300, grade: 200, opticalSize: 48),
328334
),
329335
);
330336

@@ -346,7 +352,7 @@ void main() {
346352
textDirection: TextDirection.ltr,
347353
child: IconTheme(
348354
data: IconThemeData(fill: 0.2, weight: 3.0, grade: 4.0, opticalSize: 5.0),
349-
child: Icon(Icons.abc),
355+
child: Icon(kAbcIcon),
350356
),
351357
),
352358
);
@@ -368,7 +374,7 @@ void main() {
368374
textDirection: TextDirection.ltr,
369375
child: IconTheme(
370376
data: IconThemeData(fill: 0.2, weight: 3.0, grade: 4.0, opticalSize: 5.0),
371-
child: Icon(Icons.abc, fill: 0.6, weight: 7.0, grade: 8.0, opticalSize: 9.0),
377+
child: Icon(kAbcIcon, fill: 0.6, weight: 7.0, grade: 8.0, opticalSize: 9.0),
372378
),
373379
),
374380
);
@@ -404,19 +410,19 @@ void main() {
404410
});
405411

406412
test('Throws if given invalid values', () {
407-
expect(() => Icon(Icons.abc, fill: -0.1), throwsAssertionError);
408-
expect(() => Icon(Icons.abc, fill: 1.1), throwsAssertionError);
409-
expect(() => Icon(Icons.abc, weight: -0.1), throwsAssertionError);
410-
expect(() => Icon(Icons.abc, weight: 0.0), throwsAssertionError);
411-
expect(() => Icon(Icons.abc, opticalSize: -0.1), throwsAssertionError);
412-
expect(() => Icon(Icons.abc, opticalSize: 0), throwsAssertionError);
413+
expect(() => Icon(kAbcIcon, fill: -0.1), throwsAssertionError);
414+
expect(() => Icon(kAbcIcon, fill: 1.1), throwsAssertionError);
415+
expect(() => Icon(kAbcIcon, weight: -0.1), throwsAssertionError);
416+
expect(() => Icon(kAbcIcon, weight: 0.0), throwsAssertionError);
417+
expect(() => Icon(kAbcIcon, opticalSize: -0.1), throwsAssertionError);
418+
expect(() => Icon(kAbcIcon, opticalSize: 0), throwsAssertionError);
413419
});
414420

415421
testWidgets('Icon does not crash at zero area', (WidgetTester tester) async {
416422
await tester.pumpWidget(
417423
const Directionality(
418424
textDirection: TextDirection.ltr,
419-
child: Center(child: SizedBox.shrink(child: Icon(Icons.save))),
425+
child: Center(child: SizedBox.shrink(child: Icon(kSaveIcon))),
420426
),
421427
);
422428
expect(tester.getSize(find.byType(Icon)), Size.zero);

packages/flutter/test/widgets/list_wheel_scroll_view_test.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
library;
99

1010
import 'package:flutter/foundation.dart';
11-
import 'package:flutter/material.dart';
1211
import 'package:flutter/rendering.dart';
12+
import 'package:flutter/widgets.dart';
1313
import 'package:flutter_test/flutter_test.dart';
1414

1515
import '../rendering/rendering_tester.dart' show TestCallbackPainter, TestClipPaintingContext;
16+
import 'widgets_app_tester.dart';
1617

1718
void main() {
1819
testWidgets('ListWheelScrollView respects clipBehavior', (WidgetTester tester) async {
@@ -2045,9 +2046,9 @@ void main() {
20452046
'ListWheelScrollView in an AnimatedContainer with zero width and height does not throw an error',
20462047
(WidgetTester tester) async {
20472048
await tester.pumpWidget(
2048-
MaterialApp(
2049-
home: Scaffold(
2050-
body: AnimatedContainer(
2049+
TestWidgetsApp(
2050+
home: Align(
2051+
child: AnimatedContainer(
20512052
width: 0,
20522053
height: 0,
20532054
duration: Duration.zero,

packages/flutter/test/widgets/media_query_test.dart

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import 'dart:ui'
66
show Brightness, DisplayFeature, DisplayFeatureState, DisplayFeatureType, GestureSettings;
77

88
import 'package:flutter/gestures.dart';
9-
import 'package:flutter/material.dart';
9+
import 'package:flutter/widgets.dart';
1010
import 'package:flutter_test/flutter_test.dart';
1111

12+
import 'utils.dart';
13+
import 'widgets_app_tester.dart';
14+
1215
class _MediaQueryAspectCase {
1316
const _MediaQueryAspectCase(this.method, this.data);
1417
final void Function(BuildContext) method;
@@ -1694,15 +1697,15 @@ void main() {
16941697
children: <Widget>[
16951698
showSize,
16961699
showTextScaler,
1697-
ElevatedButton(
1700+
TestButton(
16981701
onPressed: () {
16991702
setState(() {
17001703
data = data.copyWith(size: Size(data.size.width + 100, data.size.height));
17011704
});
17021705
},
17031706
child: const Text('Increase width by 100'),
17041707
),
1705-
ElevatedButton(
1708+
TestButton(
17061709
onPressed: () {
17071710
setState(() {
17081711
data = data.copyWith(textScaler: TextScaler.noScaling);
@@ -1717,7 +1720,7 @@ void main() {
17171720
},
17181721
);
17191722

1720-
await tester.pumpWidget(MaterialApp(home: page));
1723+
await tester.pumpWidget(TestWidgetsApp(home: page));
17211724
expect(find.text('size: Size(800.0, 600.0)'), findsOneWidget);
17221725
expect(find.text('textScaler: linear (1.1x)'), findsOneWidget);
17231726
expect(sizeBuildCount, 1);
@@ -1760,15 +1763,15 @@ void main() {
17601763
child: ListView(
17611764
children: <Widget>[
17621765
builder,
1763-
ElevatedButton(
1766+
TestButton(
17641767
onPressed: () {
17651768
setState(() {
17661769
data = _MediaQueryAspectVariant.aspect!.data;
17671770
});
17681771
},
17691772
child: const Text('Change data'),
17701773
),
1771-
ElevatedButton(
1774+
TestButton(
17721775
onPressed: () {
17731776
setState(() {
17741777
data = data.copyWith();
@@ -1782,7 +1785,7 @@ void main() {
17821785
},
17831786
);
17841787

1785-
await tester.pumpWidget(MaterialApp(home: page));
1788+
await tester.pumpWidget(TestWidgetsApp(home: page));
17861789
expect(buildCount, 1);
17871790

17881791
await tester.tap(find.text('Copy data'));
@@ -2009,15 +2012,15 @@ void main() {
20092012
children: <Widget>[
20102013
showWidth,
20112014
showHeight,
2012-
ElevatedButton(
2015+
TestButton(
20132016
onPressed: () {
20142017
setState(() {
20152018
data = data.copyWith(size: Size(data.size.width + 100, data.size.height));
20162019
});
20172020
},
20182021
child: const Text('Increase width by 100'),
20192022
),
2020-
ElevatedButton(
2023+
TestButton(
20212024
onPressed: () {
20222025
setState(() {
20232026
data = data.copyWith(size: Size(data.size.width, data.size.height + 100));
@@ -2032,7 +2035,7 @@ void main() {
20322035
},
20332036
);
20342037

2035-
await tester.pumpWidget(MaterialApp(home: page));
2038+
await tester.pumpWidget(TestWidgetsApp(home: page));
20362039
expect(find.text('width: 800.0'), findsOneWidget);
20372040
expect(find.text('height: 600.0'), findsOneWidget);
20382041
expect(widthBuildCount, 1);

0 commit comments

Comments
 (0)