diff --git a/packages/flutter/test/material/flexible_space_bar_collapse_mode_test.dart b/packages/flutter/test/material/flexible_space_bar_collapse_mode_test.dart index 6c3b6758fa..ebd7a21896 100644 --- a/packages/flutter/test/material/flexible_space_bar_collapse_mode_test.dart +++ b/packages/flutter/test/material/flexible_space_bar_collapse_mode_test.dart @@ -47,7 +47,7 @@ void main() { expect(topBeforeScroll.dy, equals(0.0)); expect(topAfterScroll.dy, equals(0.0)); - }, variant: TargetPlatformVariant(TargetPlatform.values.where((TargetPlatform value) => value != TargetPlatform.fuchsia).toSet())); + }, variant: TargetPlatformVariant.all(excluding: { TargetPlatform.fuchsia })); testWidgets('FlexibleSpaceBar collapse mode pin', (WidgetTester tester) async { await tester.pumpWidget( @@ -85,7 +85,7 @@ void main() { expect(topBeforeScroll.dy, equals(0.0)); expect(topAfterScroll.dy, equals(-100.0)); - }, variant: TargetPlatformVariant(TargetPlatform.values.where((TargetPlatform value) => value != TargetPlatform.fuchsia).toSet())); + }, variant: TargetPlatformVariant.all(excluding: { TargetPlatform.fuchsia })); testWidgets('FlexibleSpaceBar collapse mode parallax', (WidgetTester tester) async { await tester.pumpWidget( @@ -123,7 +123,7 @@ void main() { expect(topBeforeScroll.dy, equals(0.0)); expect(topAfterScroll.dy, lessThan(10.0)); expect(topAfterScroll.dy, greaterThan(-50.0)); - }, variant: TargetPlatformVariant(TargetPlatform.values.where((TargetPlatform value) => value != TargetPlatform.fuchsia).toSet())); + }, variant: TargetPlatformVariant.all(excluding: { TargetPlatform.fuchsia })); } Future slowDrag(WidgetTester tester, Key widget, Offset offset) async { diff --git a/packages/flutter/test/widgets/editable_text_cursor_test.dart b/packages/flutter/test/widgets/editable_text_cursor_test.dart index 9d9147cf6d..99c34cb191 100644 --- a/packages/flutter/test/widgets/editable_text_cursor_test.dart +++ b/packages/flutter/test/widgets/editable_text_cursor_test.dart @@ -234,7 +234,7 @@ void main() { await tester.pump(const Duration(milliseconds: 100)); expect(tester.hasRunningAnimations, false); } - }, variant: TargetPlatformVariant(TargetPlatform.values.toSet()..remove(TargetPlatform.iOS))); + }, variant: TargetPlatformVariant.all(excluding: { TargetPlatform.iOS })); testWidgets('Cursor does not animate on Android', (WidgetTester tester) async { final Color defaultCursorColor = Color(ThemeData.fallback().colorScheme.primary.value); diff --git a/packages/flutter/test/widgets/editable_text_shortcuts_test.dart b/packages/flutter/test/widgets/editable_text_shortcuts_test.dart index 36aefc5304..0661410a5b 100644 --- a/packages/flutter/test/widgets/editable_text_shortcuts_test.dart +++ b/packages/flutter/test/widgets/editable_text_shortcuts_test.dart @@ -138,7 +138,7 @@ void main() { group('Common text editing shortcuts: ', () { - final TargetPlatformVariant allExceptApple = TargetPlatformVariant(TargetPlatform.values.toSet()..removeAll([TargetPlatform.macOS, TargetPlatform.iOS])); + final TargetPlatformVariant allExceptApple = TargetPlatformVariant.all(excluding: {TargetPlatform.macOS, TargetPlatform.iOS}); group('backspace', () { const LogicalKeyboardKey trigger = LogicalKeyboardKey.backspace; @@ -1813,7 +1813,7 @@ void main() { }, skip: kIsWeb); // [intended] on web these keys are handled by the browser. group('Web does not accept', () { - final TargetPlatformVariant allExceptApple = TargetPlatformVariant(TargetPlatform.values.toSet()..removeAll([TargetPlatform.macOS, TargetPlatform.iOS])); + final TargetPlatformVariant allExceptApple = TargetPlatformVariant.all(excluding: { TargetPlatform.iOS, TargetPlatform.macOS }); const TargetPlatformVariant appleOnly = TargetPlatformVariant({ TargetPlatform.macOS, TargetPlatform.iOS }); group('macOS shortcuts', () { diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index 351acbba89..2b4149d88d 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -254,8 +254,11 @@ class TargetPlatformVariant extends TestVariant { const TargetPlatformVariant(this.values); /// Creates a [TargetPlatformVariant] that tests all values from - /// the [TargetPlatform] enum. - TargetPlatformVariant.all() : values = TargetPlatform.values.toSet(); + /// the [TargetPlatform] enum. If [excluding] is provided, will test all platforms + /// except those in [excluding]. + TargetPlatformVariant.all({ + Set excluding = const {}, + }) : values = TargetPlatform.values.toSet()..removeAll(excluding); /// Creates a [TargetPlatformVariant] that includes platforms that are /// considered desktop platforms. diff --git a/packages/flutter_test/test/widget_tester_test.dart b/packages/flutter_test/test/widget_tester_test.dart index efaec2bbf4..9d35cb61e6 100644 --- a/packages/flutter_test/test/widget_tester_test.dart +++ b/packages/flutter_test/test/widget_tester_test.dart @@ -720,13 +720,29 @@ void main() { expect(defaultTargetPlatform, equals(TargetPlatform.iOS)); }, variant: TargetPlatformVariant.only(TargetPlatform.iOS)); - testWidgets('TargetPlatformVariant.all tests run all variants', (WidgetTester tester) async { - if (debugDefaultTargetPlatformOverride == null) { - expect(numberOfVariationsRun, equals(TargetPlatform.values.length)); - } else { - numberOfVariationsRun += 1; - } - }, variant: TargetPlatformVariant.all()); + group('all', () { + testWidgets('TargetPlatformVariant.all tests run all variants', (WidgetTester tester) async { + if (debugDefaultTargetPlatformOverride == null) { + expect(numberOfVariationsRun, equals(TargetPlatform.values.length)); + } else { + numberOfVariationsRun += 1; + } + }, variant: TargetPlatformVariant.all()); + + const Set excludePlatforms = { TargetPlatform.android, TargetPlatform.linux }; + testWidgets('TargetPlatformVariant.all, excluding runs an all variants except those provided in excluding', (WidgetTester tester) async { + if (debugDefaultTargetPlatformOverride == null) { + expect(numberOfVariationsRun, equals(TargetPlatform.values.length - excludePlatforms.length)); + expect( + excludePlatforms, + isNot(contains(debugDefaultTargetPlatformOverride)), + reason: 'this test should not run on any platform in excludePlatforms' + ); + } else { + numberOfVariationsRun += 1; + } + }, variant: TargetPlatformVariant.all(excluding: excludePlatforms)); + }); testWidgets('TargetPlatformVariant.desktop + mobile contains all TargetPlatform values', (WidgetTester tester) async { final TargetPlatformVariant all = TargetPlatformVariant.all();