Remove double MaterialApp wrap from api samples (#150055)

The widget under test already contains a MaterialApp, so there's no need to wrap it again with one in the test. In fact, the additional MaterialApp could hide problems in the widget under test.
This commit is contained in:
Michael Goderbauer 2024-06-11 22:22:23 -07:00 committed by GitHub
parent 1f93809ad2
commit 962ae8a334
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 30 additions and 136 deletions

View File

@ -8,14 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Action Icon Buttons', (WidgetTester tester) async { testWidgets('Action Icon Buttons', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(const example.ActionIconThemeExampleApp());
const MaterialApp(
home: Scaffold(
body: example.ActionIconThemeExampleApp(),
),
),
);
expect(find.byType(DrawerButton), findsOneWidget); expect(find.byType(DrawerButton), findsOneWidget);
final Icon drawerButtonIcon = tester.widget( final Icon drawerButtonIcon = tester.widget(

View File

@ -10,11 +10,7 @@ void main() {
testWidgets('Show Adaptive Alert dialog', (WidgetTester tester) async { testWidgets('Show Adaptive Alert dialog', (WidgetTester tester) async {
const String dialogTitle = 'AlertDialog Title'; const String dialogTitle = 'AlertDialog Title';
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.AdaptiveAlertDialogApp(),
home: Scaffold(
body: example.AdaptiveAlertDialogApp(),
),
),
); );
expect(find.text(dialogTitle), findsNothing); expect(find.text(dialogTitle), findsNothing);

View File

@ -10,11 +10,7 @@ void main() {
testWidgets('Show Alert dialog', (WidgetTester tester) async { testWidgets('Show Alert dialog', (WidgetTester tester) async {
const String dialogTitle = 'AlertDialog Title'; const String dialogTitle = 'AlertDialog Title';
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.AlertDialogExampleApp(),
home: Scaffold(
body: example.AlertDialogExampleApp(),
),
),
); );
expect(find.text(dialogTitle), findsNothing); expect(find.text(dialogTitle), findsNothing);

View File

@ -10,11 +10,7 @@ void main() {
testWidgets('Show Alert dialog', (WidgetTester tester) async { testWidgets('Show Alert dialog', (WidgetTester tester) async {
const String dialogTitle = 'AlertDialog Title'; const String dialogTitle = 'AlertDialog Title';
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.AlertDialogExampleApp(),
home: Scaffold(
body: example.AlertDialogExampleApp(),
),
),
); );
expect(find.text(dialogTitle), findsNothing); expect(find.text(dialogTitle), findsNothing);

View File

@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/dialog/dialog.0.dart' as example; import 'package:flutter_api_samples/material/dialog/dialog.0.dart' as example;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@ -11,11 +10,7 @@ void main() {
const String dialogText = 'This is a typical dialog.'; const String dialogText = 'This is a typical dialog.';
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.DialogExampleApp(),
home: Scaffold(
body: example.DialogExampleApp(),
),
),
); );
expect(find.text(dialogText), findsNothing); expect(find.text(dialogText), findsNothing);
@ -33,11 +28,7 @@ void main() {
const String dialogText = 'This is a fullscreen dialog.'; const String dialogText = 'This is a fullscreen dialog.';
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.DialogExampleApp(),
home: Scaffold(
body: example.DialogExampleApp(),
),
),
); );
expect(find.text(dialogText), findsNothing); expect(find.text(dialogText), findsNothing);

View File

@ -10,11 +10,7 @@ void main() {
testWidgets('Show dialog', (WidgetTester tester) async { testWidgets('Show dialog', (WidgetTester tester) async {
const String dialogTitle = 'Basic dialog title'; const String dialogTitle = 'Basic dialog title';
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.ShowDialogExampleApp(),
home: Scaffold(
body: example.ShowDialogExampleApp(),
),
),
); );
expect(find.text(dialogTitle), findsNothing); expect(find.text(dialogTitle), findsNothing);

View File

@ -10,11 +10,7 @@ void main() {
testWidgets('Show dialog', (WidgetTester tester) async { testWidgets('Show dialog', (WidgetTester tester) async {
const String dialogTitle = 'Basic dialog title'; const String dialogTitle = 'Basic dialog title';
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.ShowDialogExampleApp(),
home: Scaffold(
body: example.ShowDialogExampleApp(),
),
),
); );
expect(find.text(dialogTitle), findsNothing); expect(find.text(dialogTitle), findsNothing);

View File

@ -10,11 +10,7 @@ void main() {
testWidgets('Show dialog', (WidgetTester tester) async { testWidgets('Show dialog', (WidgetTester tester) async {
const String dialogTitle = 'Basic dialog title'; const String dialogTitle = 'Basic dialog title';
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.ShowDialogExampleApp(),
home: Scaffold(
body: example.ShowDialogExampleApp(),
),
),
); );
expect(find.text(dialogTitle), findsNothing); expect(find.text(dialogTitle), findsNothing);

View File

@ -9,11 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Horizontal Divider', (WidgetTester tester) async { testWidgets('Horizontal Divider', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.DividerExampleApp(),
home: Scaffold(
body: example.DividerExampleApp(),
),
),
); );
expect(find.byType(Divider), findsOneWidget); expect(find.byType(Divider), findsOneWidget);

View File

@ -9,11 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Horizontal Divider', (WidgetTester tester) async { testWidgets('Horizontal Divider', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.DividerExampleApp(),
home: Scaffold(
body: example.DividerExampleApp(),
),
),
); );
expect(find.byType(Divider), findsOneWidget); expect(find.byType(Divider), findsOneWidget);

View File

@ -9,11 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Vertical Divider', (WidgetTester tester) async { testWidgets('Vertical Divider', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.VerticalDividerExampleApp(),
home: Scaffold(
body: example.VerticalDividerExampleApp(),
),
),
); );
expect(find.byType(VerticalDivider), findsOneWidget); expect(find.byType(VerticalDivider), findsOneWidget);

View File

@ -9,11 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Vertical Divider', (WidgetTester tester) async { testWidgets('Vertical Divider', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.VerticalDividerExampleApp(),
home: Scaffold(
body: example.VerticalDividerExampleApp(),
),
),
); );
expect(find.byType(VerticalDivider), findsOneWidget); expect(find.byType(VerticalDivider), findsOneWidget);

View File

@ -2,18 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/dropdown/dropdown_button.0.dart' as example; import 'package:flutter_api_samples/material/dropdown/dropdown_button.0.dart' as example;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Select an item from DropdownButton', (WidgetTester tester) async { testWidgets('Select an item from DropdownButton', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.DropdownButtonApp(),
home: Scaffold(
body: example.DropdownButtonApp(),
),
),
); );
expect(find.text('One'), findsOneWidget); expect(find.text('One'), findsOneWidget);

View File

@ -2,18 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/dropdown/dropdown_button.selected_item_builder.0.dart' as example; import 'package:flutter_api_samples/material/dropdown/dropdown_button.selected_item_builder.0.dart' as example;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Select an item from DropdownButton', (WidgetTester tester) async { testWidgets('Select an item from DropdownButton', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.DropdownButtonApp(),
home: Scaffold(
body: example.DropdownButtonApp(),
),
),
); );
expect(find.text('NYC'), findsOneWidget); expect(find.text('NYC'), findsOneWidget);

View File

@ -2,18 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/dropdown/dropdown_button.style.0.dart' as example; import 'package:flutter_api_samples/material/dropdown/dropdown_button.style.0.dart' as example;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Select an item from DropdownButton', (WidgetTester tester) async { testWidgets('Select an item from DropdownButton', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.DropdownButtonApp(),
home: Scaffold(
body: example.DropdownButtonApp(),
),
),
); );
expect(find.text('One'), findsOneWidget); expect(find.text('One'), findsOneWidget);

View File

@ -11,11 +11,7 @@ void main() {
const String menuItem = 'Item 1'; const String menuItem = 'Item 1';
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.PopupMenuApp(),
home: Scaffold(
body: example.PopupMenuApp(),
),
),
); );
expect(find.text(menuItem), findsNothing); expect(find.text(menuItem), findsNothing);

View File

@ -11,11 +11,7 @@ void main() {
const String menuItem = 'Item 1'; const String menuItem = 'Item 1';
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.PopupMenuApp(),
home: Scaffold(
body: example.PopupMenuApp(),
),
),
); );
expect(find.text(menuItem), findsNothing); expect(find.text(menuItem), findsNothing);

View File

@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/reorderable_list/reorderable_list_view.build_default_drag_handles.0.dart' import 'package:flutter_api_samples/material/reorderable_list/reorderable_list_view.build_default_drag_handles.0.dart'
as example; as example;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@ -19,9 +18,7 @@ void main() {
testWidgets('Reorder list item', (WidgetTester tester) async { testWidgets('Reorder list item', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.ReorderableApp(),
home: example.ReorderableApp(),
),
); );
expect(tester.getCenter(find.text('Item 3')).dy, 280.0); expect(tester.getCenter(find.text('Item 3')).dy, 280.0);

View File

@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/reorderable_list/reorderable_list_view.reorderable_list_view_builder.0.dart' import 'package:flutter_api_samples/material/reorderable_list/reorderable_list_view.reorderable_list_view_builder.0.dart'
as example; as example;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@ -19,9 +18,7 @@ void main() {
testWidgets('Reorder list item', (WidgetTester tester) async { testWidgets('Reorder list item', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.ReorderableApp(),
home: example.ReorderableApp(),
),
); );
expect(tester.getCenter(find.text('Item 3')).dy, 252.0); expect(tester.getCenter(find.text('Item 3')).dy, 252.0);

View File

@ -30,11 +30,7 @@ void main() {
]; ];
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.ShowTimePickerApp(),
home: Scaffold(
body: example.ShowTimePickerApp(),
),
),
); );
for (final String option in options) { for (final String option in options) {

View File

@ -13,11 +13,7 @@ void main() {
return tester.widget<TextButton>(find.widgetWithText(TextButton, text)); return tester.widget<TextButton>(find.widgetWithText(TextButton, text));
} }
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.ToggleButtonsExampleApp(),
home: Scaffold(
body: example.ToggleButtonsExampleApp(),
),
),
); );
TextButton firstButton = findButton('Apple'); TextButton firstButton = findButton('Apple');
@ -51,11 +47,7 @@ void main() {
return tester.widget<TextButton>(find.widgetWithText(TextButton, text)); return tester.widget<TextButton>(find.widgetWithText(TextButton, text));
} }
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.ToggleButtonsExampleApp(),
home: Scaffold(
body: example.ToggleButtonsExampleApp(),
),
),
); );
TextButton firstButton = findButton('Tomatoes'); TextButton firstButton = findButton('Tomatoes');
@ -90,11 +82,7 @@ void main() {
return tester.widget<TextButton>(find.widgetWithIcon(TextButton, iconData)); return tester.widget<TextButton>(find.widgetWithIcon(TextButton, iconData));
} }
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.ToggleButtonsExampleApp(),
home: Scaffold(
body: example.ToggleButtonsExampleApp(),
),
),
); );
TextButton firstButton = findButton(Icons.sunny); TextButton firstButton = findButton(Icons.sunny);

View File

@ -10,11 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('has four containers', (WidgetTester tester) async { testWidgets('has four containers', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( const example.CustomMultiChildLayoutApp(),
home: Scaffold(
body: example.CustomMultiChildLayoutApp(),
),
),
); );
final Finder containerFinder = find.byType(Container); final Finder containerFinder = find.byType(Container);
expect(containerFinder, findsNWidgets(4)); expect(containerFinder, findsNWidgets(4));

View File

@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('MouseRegion detects mouse entries, exists, and location', (WidgetTester tester) async { testWidgets('MouseRegion detects mouse entries, exists, and location', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp(home: example.MouseRegionApp()), const example.MouseRegionApp(),
); );
expect(find.text('0 Entries\n0 Exits'), findsOneWidget); expect(find.text('0 Entries\n0 Exits'), findsOneWidget);

View File

@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('MouseRegion detects mouse hover', (WidgetTester tester) async { testWidgets('MouseRegion detects mouse hover', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp(home: example.MouseRegionApp()), const example.MouseRegionApp(),
); );
Container container = tester.widget<Container>(find.byType(Container)); Container container = tester.widget<Container>(find.byType(Container));

View File

@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('MouseRegion update mouse hover with a delay', (WidgetTester tester) async { testWidgets('MouseRegion update mouse hover with a delay', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp(home: example.MouseRegionApp()), const example.MouseRegionApp(),
); );
expect(find.text('Not hovering'), findsOneWidget); expect(find.text('Not hovering'), findsOneWidget);

View File

@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/basic/offstage.0.dart' as example; import 'package:flutter_api_samples/widgets/basic/offstage.0.dart' as example;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Can off/on stage Flutter logo widget', (WidgetTester tester) async { testWidgets('Can off/on stage Flutter logo widget', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp(home: example.OffstageApp()), const example.OffstageApp(),
); );
// The Flutter logo is off stage and not visible. // The Flutter logo is off stage and not visible.

View File

@ -9,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('PhysicalShape is an ancestor of the text widget', (WidgetTester tester) async { testWidgets('PhysicalShape is an ancestor of the text widget', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp(home: example.PhysicalShapeApp()), const example.PhysicalShapeApp(),
); );
final PhysicalShape physicalShape = tester.widget<PhysicalShape>( final PhysicalShape physicalShape = tester.widget<PhysicalShape>(