From a5f8b64ef989946fad4411d25f913c938c1c09da Mon Sep 17 00:00:00 2001 From: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com> Date: Tue, 13 Jun 2023 14:21:13 -0700 Subject: [PATCH] Update unit tests in material library for Material 3 (#128725) Updates most of the unit tests in the packages/flutter/test/material folder so that they'll pass if ThemeData.useMaterial3 defaults to true. All of the tests have wired useMaterial3 to false and will need to be updated with a M3 version. related to #127064 --- .../flutter/test/material/about_test.dart | 36 +- .../test/material/app_builder_test.dart | 2 + packages/flutter/test/material/app_test.dart | 2 + .../test/material/autocomplete_test.dart | 2 +- .../test/material/banner_theme_test.dart | 2 + .../test/material/bottom_app_bar_test.dart | 16 +- .../material/bottom_app_bar_theme_test.dart | 11 +- .../material/bottom_navigation_bar_test.dart | 45 +- .../test/material/bottom_sheet_test.dart | 14 +- .../material/bottom_sheet_theme_test.dart | 7 +- .../material/calendar_date_picker_test.dart | 1 + .../material/checkbox_list_tile_test.dart | 32 +- packages/flutter/test/material/chip_test.dart | 16 +- .../test/material/chip_theme_test.dart | 10 +- .../test/material/choice_chip_test.dart | 2 +- .../test/material/circle_avatar_test.dart | 8 +- .../test/material/data_table_test.dart | 1 + .../test/material/date_picker_test.dart | 4 +- .../test/material/date_range_picker_test.dart | 6 +- .../test/material/dialog_theme_test.dart | 10 +- .../flutter/test/material/divider_test.dart | 12 +- .../test/material/divider_theme_test.dart | 14 +- .../flutter/test/material/drawer_test.dart | 1 + .../flutter/test/material/dropdown_test.dart | 90 ++-- .../test/material/expand_icon_test.dart | 4 +- .../test/material/expansion_panel_test.dart | 2 + .../test/material/expansion_tile_test.dart | 1 + .../test/material/filter_chip_test.dart | 7 +- .../flexible_space_bar_stretch_mode_test.dart | 1 + .../material/flexible_space_bar_test.dart | 10 +- .../test/material/inherited_theme_test.dart | 1 + .../flutter/test/material/ink_paint_test.dart | 30 +- .../test/material/ink_splash_test.dart | 1 + .../flutter/test/material/ink_well_test.dart | 414 ++++++++++-------- .../test/material/input_decorator_test.dart | 6 + .../flutter/test/material/list_tile_test.dart | 8 +- .../test/material/list_tile_theme_test.dart | 1 + .../test/material/menu_anchor_test.dart | 17 +- .../test/material/menu_bar_theme_test.dart | 2 + .../test/material/menu_style_test.dart | 1 + .../test/material/menu_theme_test.dart | 2 + .../material/mergeable_material_test.dart | 15 +- .../persistent_bottom_sheet_test.dart | 1 + .../test/material/popup_menu_test.dart | 5 + .../test/material/popup_menu_theme_test.dart | 4 +- .../test/material/range_slider_test.dart | 1 + .../test/material/refresh_indicator_test.dart | 1 + .../flutter/test/material/scaffold_test.dart | 9 +- .../flutter/test/material/scrollbar_test.dart | 76 ++-- .../test/material/scrollbar_theme_test.dart | 7 +- .../flutter/test/material/search_test.dart | 4 +- .../test/material/selection_area_test.dart | 1 + .../flutter/test/material/slider_test.dart | 5 +- .../test/material/slider_theme_test.dart | 10 +- .../flutter/test/material/snack_bar_test.dart | 18 +- packages/flutter/test/material/tabs_test.dart | 176 ++++---- .../test/material/text_field_test.dart | 394 ++++++++++------- .../test/material/text_form_field_test.dart | 3 +- .../test/material/text_selection_test.dart | 2 +- .../test/material/theme_data_test.dart | 18 +- .../flutter/test/material/tooltip_test.dart | 269 ++++++------ .../test/material/tooltip_theme_test.dart | 36 +- 62 files changed, 1127 insertions(+), 780 deletions(-) diff --git a/packages/flutter/test/material/about_test.dart b/packages/flutter/test/material/about_test.dart index 8c3dd366cfc..29cfdf5a372 100644 --- a/packages/flutter/test/material/about_test.dart +++ b/packages/flutter/test/material/about_test.dart @@ -63,6 +63,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), title: 'Pirate app', home: Scaffold( appBar: AppBar( @@ -167,8 +168,9 @@ void main() { }); await tester.pumpWidget( - const MaterialApp( - home: Center( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Center( child: LicensePage(), ), ), @@ -220,9 +222,10 @@ void main() { }); await tester.pumpWidget( - const MaterialApp( + MaterialApp( + theme: ThemeData(useMaterial3: false), title: 'Pirate app', - home: Center( + home: const Center( child: LicensePage( applicationName: 'LicensePage test app', applicationVersion: '0.1.2', @@ -298,6 +301,7 @@ void main() { await tester.pumpWidget( MaterialApp( theme: ThemeData( + useMaterial3: false, primaryTextTheme: const TextTheme( titleLarge: titleTextStyle, titleSmall: subtitleTextStyle, @@ -384,8 +388,9 @@ void main() { }); await tester.pumpWidget( - const MaterialApp( - home: MediaQuery( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const MediaQuery( data: MediaQueryData( padding: EdgeInsets.all(safeareaPadding), ), @@ -830,7 +835,7 @@ void main() { const Color cardColor = Color(0xFF654321); await tester.pumpWidget(MaterialApp( - theme: ThemeData.light().copyWith( + theme: ThemeData.light(useMaterial3: false).copyWith( scaffoldBackgroundColor: scaffoldColor, cardColor: cardColor, ), @@ -1051,7 +1056,12 @@ void main() { testWidgetsWithLeakTracking('Error handling test', (WidgetTester tester) async { LicenseRegistry.addLicense(() => Stream.error(Exception('Injected failure'))); - await tester.pumpWidget(const MaterialApp(home: Material(child: AboutListTile()))); + await tester.pumpWidget( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Material(child: AboutListTile()) + ) + ); await tester.tap(find.byType(ListTile)); await tester.pump(); await tester.pump(const Duration(seconds: 2)); @@ -1082,9 +1092,10 @@ void main() { await tester.binding.setSurfaceSize(defaultSize); await tester.pumpWidget( - const MaterialApp( + MaterialApp( + theme: ThemeData(useMaterial3: false), title: title, - home: Scaffold( + home: const Scaffold( body: Directionality( textDirection: textDirection, child: LicensePage(), @@ -1145,9 +1156,10 @@ void main() { await tester.binding.setSurfaceSize(defaultSize); await tester.pumpWidget( - const MaterialApp( + MaterialApp( + theme: ThemeData(useMaterial3: false), title: title, - home: Scaffold( + home: const Scaffold( body: Directionality( textDirection: textDirection, child: LicensePage(), diff --git a/packages/flutter/test/material/app_builder_test.dart b/packages/flutter/test/material/app_builder_test.dart index c63b84e16b2..851a88edcf8 100644 --- a/packages/flutter/test/material/app_builder_test.dart +++ b/packages/flutter/test/material/app_builder_test.dart @@ -10,6 +10,7 @@ void main() { final List log = []; final Widget app = MaterialApp( theme: ThemeData( + useMaterial3: false, primarySwatch: Colors.green, ), home: const Placeholder(), @@ -42,6 +43,7 @@ void main() { await tester.pumpWidget( MaterialApp( theme: ThemeData( + useMaterial3: false, primarySwatch: Colors.yellow, ), home: Builder( diff --git a/packages/flutter/test/material/app_test.dart b/packages/flutter/test/material/app_test.dart index 59ba965cd74..734aa878be7 100644 --- a/packages/flutter/test/material/app_test.dart +++ b/packages/flutter/test/material/app_test.dart @@ -995,6 +995,7 @@ void main() { const Color secondaryColor = Color(0xff008800); final Color glowSecondaryColor = secondaryColor.withOpacity(0.05); final ThemeData theme = ThemeData.from( + useMaterial3: false, colorScheme: const ColorScheme.light().copyWith(secondary: secondaryColor), ); await tester.pumpWidget( @@ -1264,6 +1265,7 @@ void main() { testWidgets('ScrollBehavior default android overscroll indicator', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), scrollBehavior: const MaterialScrollBehavior(), home: ListView( children: const [ diff --git a/packages/flutter/test/material/autocomplete_test.dart b/packages/flutter/test/material/autocomplete_test.dart index ab77b522ec6..ad33efd68c6 100644 --- a/packages/flutter/test/material/autocomplete_test.dart +++ b/packages/flutter/test/material/autocomplete_test.dart @@ -459,7 +459,7 @@ void main() { const Color highlightColor = Color(0xFF112233); await tester.pumpWidget( MaterialApp( - theme: ThemeData.light().copyWith( + theme: ThemeData.light(useMaterial3: false).copyWith( focusColor: highlightColor, ), home: Scaffold( diff --git a/packages/flutter/test/material/banner_theme_test.dart b/packages/flutter/test/material/banner_theme_test.dart index dec53df6f7d..4fd5f3a05c3 100644 --- a/packages/flutter/test/material/banner_theme_test.dart +++ b/packages/flutter/test/material/banner_theme_test.dart @@ -457,6 +457,7 @@ void main() { const String contentText = 'Content'; await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: MaterialBanner( content: const Text(contentText), @@ -503,6 +504,7 @@ void main() { const Key tapTarget = Key('tap-target'); await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Builder( builder: (BuildContext context) { diff --git a/packages/flutter/test/material/bottom_app_bar_test.dart b/packages/flutter/test/material/bottom_app_bar_test.dart index 6e5075b5357..5e2c9c82a6f 100644 --- a/packages/flutter/test/material/bottom_app_bar_test.dart +++ b/packages/flutter/test/material/bottom_app_bar_test.dart @@ -120,6 +120,7 @@ void main() { child: RepaintBoundary( key: key, child: MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( floatingActionButton: FloatingActionButton( onPressed: () { }, @@ -217,9 +218,10 @@ void main() { expect(babRect, const Rect.fromLTRB(240, 520, 560, 600)); }); - testWidgets('color defaults to Theme.bottomAppBarColor', (WidgetTester tester) async { + testWidgets('color defaults to Theme.bottomAppBarColor in M2', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Builder( builder: (BuildContext context) { return Theme( @@ -245,6 +247,7 @@ void main() { testWidgets('color overrides theme color', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Builder( builder: (BuildContext context) { return Theme( @@ -324,7 +327,7 @@ void main() { testWidgets('dark theme applies an elevation overlay color', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData.from(colorScheme: const ColorScheme.dark()), + theme: ThemeData.from(useMaterial3: false, colorScheme: const ColorScheme.dark()), home: Scaffold( bottomNavigationBar: BottomAppBar( color: const ColorScheme.dark().surface, @@ -508,8 +511,9 @@ void main() { testWidgets('observes safe area', (WidgetTester tester) async { await tester.pumpWidget( - const MaterialApp( - home: MediaQuery( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const MediaQuery( data: MediaQueryData( padding: EdgeInsets.all(50.0), ), @@ -566,8 +570,10 @@ void main() { testWidgets('BottomAppBar with shape when Scaffold.bottomNavigationBar == null', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/80878 + final ThemeData theme = ThemeData(); await tester.pumpWidget( MaterialApp( + theme: theme, home: Scaffold( floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, floatingActionButton: FloatingActionButton( @@ -595,7 +601,7 @@ void main() { ); expect(tester.getRect(find.byType(FloatingActionButton)), const Rect.fromLTRB(372, 528, 428, 584)); - expect(tester.getSize(find.byType(BottomAppBar)), const Size(800, 50)); + expect(tester.getSize(find.byType(BottomAppBar)), theme.useMaterial3 ? const Size(800, 80) : const Size(800, 50)); }); testWidgets('notch with margin and top padding, home safe area', (WidgetTester tester) async { diff --git a/packages/flutter/test/material/bottom_app_bar_theme_test.dart b/packages/flutter/test/material/bottom_app_bar_theme_test.dart index e3a811f5a56..bd08943f425 100644 --- a/packages/flutter/test/material/bottom_app_bar_theme_test.dart +++ b/packages/flutter/test/material/bottom_app_bar_theme_test.dart @@ -36,6 +36,7 @@ void main() { await tester.pumpWidget(MaterialApp( theme: ThemeData( + useMaterial3: false, bottomAppBarTheme: theme, bottomAppBarColor: themeColor ), @@ -53,6 +54,7 @@ void main() { await tester.pumpWidget(MaterialApp( theme: ThemeData( + useMaterial3: false, bottomAppBarTheme: theme, bottomAppBarColor: themeColor ), @@ -67,7 +69,7 @@ void main() { const Color themeColor = Colors.white10; await tester.pumpWidget(MaterialApp( - theme: ThemeData(bottomAppBarColor: themeColor), + theme: ThemeData(useMaterial3: false, bottomAppBarColor: themeColor), home: const Scaffold(body: BottomAppBar()), )); @@ -77,7 +79,7 @@ void main() { testWidgets('BAB color - Default', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( - theme: ThemeData(), + theme: ThemeData(useMaterial3: false), home: const Scaffold(body: BottomAppBar()), )); @@ -102,8 +104,9 @@ void main() { }); testWidgets('BAB theme does not affect defaults', (WidgetTester tester) async { - await tester.pumpWidget(const MaterialApp( - home: Scaffold(body: BottomAppBar()), + await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Scaffold(body: BottomAppBar()), )); final PhysicalShape widget = _getBabRenderObject(tester); diff --git a/packages/flutter/test/material/bottom_navigation_bar_test.dart b/packages/flutter/test/material/bottom_navigation_bar_test.dart index 5bb0592ee20..a73239ad9c4 100644 --- a/packages/flutter/test/material/bottom_navigation_bar_test.dart +++ b/packages/flutter/test/material/bottom_navigation_bar_test.dart @@ -52,6 +52,7 @@ void main() { testWidgets('BottomNavigationBar content test', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( bottomNavigationBar: BottomNavigationBar( items: const [ @@ -81,7 +82,7 @@ void main() { await tester.pumpWidget( MaterialApp( - theme: ThemeData.light().copyWith( + theme: ThemeData.light(useMaterial3: false).copyWith( colorScheme: const ColorScheme.light().copyWith(primary: primaryColor), unselectedWidgetColor: unselectedWidgetColor, ), @@ -413,6 +414,7 @@ void main() { testWidgets('Shifting BottomNavigationBar defaults', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( bottomNavigationBar: BottomNavigationBar( type: BottomNavigationBarType.shifting, @@ -991,6 +993,7 @@ void main() { testWidgets('BottomNavigationBar adds bottom padding to height', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: MediaQuery( data: const MediaQueryData(viewPadding: EdgeInsets.only(bottom: 40.0)), child: Scaffold( @@ -1323,6 +1326,7 @@ void main() { testWidgets('BottomNavigationBar responds to textScaleFactor', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( bottomNavigationBar: BottomNavigationBar( type: BottomNavigationBarType.fixed, @@ -1396,6 +1400,7 @@ void main() { testWidgets('BottomNavigationBar does not grow with textScaleFactor when labels are provided', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( bottomNavigationBar: BottomNavigationBar( type: BottomNavigationBarType.fixed, @@ -1484,19 +1489,22 @@ void main() { onGenerateRoute: (RouteSettings settings) { return MaterialPageRoute( builder: (BuildContext context) { - return Scaffold( - bottomNavigationBar: BottomNavigationBar( - items: const [ - BottomNavigationBarItem( - label: label, - icon: Icon(Icons.ac_unit), - tooltip: label, - ), - BottomNavigationBarItem( - label: 'B', - icon: Icon(Icons.battery_alert), - ), - ], + return MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Scaffold( + bottomNavigationBar: BottomNavigationBar( + items: const [ + BottomNavigationBarItem( + label: label, + icon: Icon(Icons.ac_unit), + tooltip: label, + ), + BottomNavigationBarItem( + label: 'B', + icon: Icon(Icons.battery_alert), + ), + ], + ), ), ); }, @@ -1566,6 +1574,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( bottomNavigationBar: BottomNavigationBar( items: [ @@ -1595,6 +1604,7 @@ void main() { testWidgets('BottomNavigationBar paints circles', (WidgetTester tester) async { await tester.pumpWidget( boilerplate( + useMaterial3: false, textDirection: TextDirection.ltr, bottomNavigationBar: BottomNavigationBar( items: const [ @@ -1924,6 +1934,7 @@ void main() { Widget runTest() { int currentIndex = 0; return MaterialApp( + theme: ThemeData(useMaterial3: false), home: StatefulBuilder( builder: (BuildContext context, StateSetter setState) { return Scaffold( @@ -2363,6 +2374,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Builder( builder: (BuildContext context) { return Scaffold( @@ -2410,6 +2422,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Builder( builder: (BuildContext context) { return Scaffold( @@ -2455,6 +2468,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Builder( builder: (BuildContext context) { return Scaffold( @@ -2490,8 +2504,9 @@ void main() { }); } -Widget boilerplate({ Widget? bottomNavigationBar, required TextDirection textDirection }) { +Widget boilerplate({ Widget? bottomNavigationBar, required TextDirection textDirection, bool? useMaterial3 }) { return MaterialApp( + theme: ThemeData(useMaterial3: useMaterial3), home: Localizations( locale: const Locale('en', 'US'), delegates: const >[ diff --git a/packages/flutter/test/material/bottom_sheet_test.dart b/packages/flutter/test/material/bottom_sheet_test.dart index 8db476a5bd7..b6e5db84011 100644 --- a/packages/flutter/test/material/bottom_sheet_test.dart +++ b/packages/flutter/test/material/bottom_sheet_test.dart @@ -979,6 +979,7 @@ void main() { final GlobalKey scaffoldKey = GlobalKey(); await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( key: scaffoldKey, body: const Center(child: Text('body')), @@ -1180,6 +1181,7 @@ void main() { testWidgets('showModalBottomSheet does not use root Navigator by default', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Navigator(onGenerateRoute: (RouteSettings settings) => MaterialPageRoute(builder: (_) { return const _TestPage(); @@ -1804,8 +1806,9 @@ void main() { }); testWidgets('No constraints by default for bottomSheet property', (WidgetTester tester) async { - await tester.pumpWidget(const MaterialApp( - home: Scaffold( + await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Scaffold( body: Center(child: Text('body')), bottomSheet: Text('BottomSheet'), ), @@ -1819,6 +1822,7 @@ void main() { testWidgets('No constraints by default for showBottomSheet', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Builder(builder: (BuildContext context) { return Center( @@ -1846,6 +1850,7 @@ void main() { testWidgets('No constraints by default for showModalBottomSheet', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Builder(builder: (BuildContext context) { return Center( @@ -1875,6 +1880,7 @@ void main() { testWidgets('Theme constraints used for bottomSheet property', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( theme: ThemeData( + useMaterial3: false, bottomSheetTheme: const BottomSheetThemeData( constraints: BoxConstraints(maxWidth: 80), ), @@ -1902,6 +1908,7 @@ void main() { testWidgets('Theme constraints used for showBottomSheet', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( theme: ThemeData( + useMaterial3: false, bottomSheetTheme: const BottomSheetThemeData( constraints: BoxConstraints(maxWidth: 80), ), @@ -1935,6 +1942,7 @@ void main() { testWidgets('Theme constraints used for showModalBottomSheet', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( theme: ThemeData( + useMaterial3: false, bottomSheetTheme: const BottomSheetThemeData( constraints: BoxConstraints(maxWidth: 80), ), @@ -1969,6 +1977,7 @@ void main() { testWidgets('constraints param overrides theme for showBottomSheet', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( theme: ThemeData( + useMaterial3: false, bottomSheetTheme: const BottomSheetThemeData( constraints: BoxConstraints(maxWidth: 80), ), @@ -2003,6 +2012,7 @@ void main() { testWidgets('constraints param overrides theme for showModalBottomSheet', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( theme: ThemeData( + useMaterial3: false, bottomSheetTheme: const BottomSheetThemeData( constraints: BoxConstraints(maxWidth: 80), ), diff --git a/packages/flutter/test/material/bottom_sheet_theme_test.dart b/packages/flutter/test/material/bottom_sheet_theme_test.dart index 44a740584a9..7a965b59711 100644 --- a/packages/flutter/test/material/bottom_sheet_theme_test.dart +++ b/packages/flutter/test/material/bottom_sheet_theme_test.dart @@ -80,6 +80,7 @@ void main() { testWidgets('Passing no BottomSheetThemeData returns defaults', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: BottomSheet( onClosing: () {}, @@ -256,14 +257,14 @@ void main() { const Color darkShadowColor = Colors.purple; await tester.pumpWidget(MaterialApp( - theme: ThemeData.light().copyWith( + theme: ThemeData.light(useMaterial3: false).copyWith( bottomSheetTheme: const BottomSheetThemeData( elevation: lightElevation, backgroundColor: lightBackgroundColor, shadowColor: lightShadowColor, ), ), - darkTheme: ThemeData.dark().copyWith( + darkTheme: ThemeData.dark(useMaterial3: false).copyWith( bottomSheetTheme: const BottomSheetThemeData( elevation: darkElevation, backgroundColor: darkBackgroundColor, @@ -323,7 +324,7 @@ void main() { Widget bottomSheetWithElevations(BottomSheetThemeData bottomSheetTheme) { return MaterialApp( - theme: ThemeData(bottomSheetTheme: bottomSheetTheme), + theme: ThemeData(bottomSheetTheme: bottomSheetTheme, useMaterial3: false), home: Scaffold( body: Builder( builder: (BuildContext context) { diff --git a/packages/flutter/test/material/calendar_date_picker_test.dart b/packages/flutter/test/material/calendar_date_picker_test.dart index acc4c548159..971b227f24e 100644 --- a/packages/flutter/test/material/calendar_date_picker_test.dart +++ b/packages/flutter/test/material/calendar_date_picker_test.dart @@ -28,6 +28,7 @@ void main() { TextDirection textDirection = TextDirection.ltr, }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Directionality( textDirection: textDirection, diff --git a/packages/flutter/test/material/checkbox_list_tile_test.dart b/packages/flutter/test/material/checkbox_list_tile_test.dart index 247b01f4ece..5a7754e6884 100644 --- a/packages/flutter/test/material/checkbox_list_tile_test.dart +++ b/packages/flutter/test/material/checkbox_list_tile_test.dart @@ -42,11 +42,14 @@ void main() { Color checkBoxCheckColor = const Color(0xffFFFFFF); Widget buildFrame(Color? color) { - return wrap( - child: CheckboxListTile( - value: true, - checkColor: color, - onChanged: (bool? value) {}, + return MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: CheckboxListTile( + value: true, + checkColor: color, + onChanged: (bool? value) {}, + ), ), ); } @@ -730,14 +733,17 @@ void main() { const double splashRadius = 24.0; Widget buildCheckbox({bool active = false, bool useOverlay = true}) { - return wrap( - child: CheckboxListTile( - value: active, - onChanged: (_) { }, - fillColor: const MaterialStatePropertyAll(fillColor), - overlayColor: useOverlay ? MaterialStateProperty.resolveWith(getOverlayColor) : null, - hoverColor: hoverColor, - splashRadius: splashRadius, + return MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: CheckboxListTile( + value: active, + onChanged: (_) { }, + fillColor: const MaterialStatePropertyAll(fillColor), + overlayColor: useOverlay ? MaterialStateProperty.resolveWith(getOverlayColor) : null, + hoverColor: hoverColor, + splashRadius: splashRadius, + ), ), ); } diff --git a/packages/flutter/test/material/chip_test.dart b/packages/flutter/test/material/chip_test.dart index 46aa1ecf39d..53b54d8f58e 100644 --- a/packages/flutter/test/material/chip_test.dart +++ b/packages/flutter/test/material/chip_test.dart @@ -76,7 +76,7 @@ Widget wrapForChip({ Brightness brightness = Brightness.light, }) { return MaterialApp( - theme: ThemeData(brightness: brightness), + theme: ThemeData(brightness: brightness, useMaterial3: false), home: Directionality( textDirection: textDirection, child: MediaQuery( @@ -220,7 +220,7 @@ void main() { Widget buildFrame(Brightness brightness) { return MaterialApp( - theme: ThemeData(brightness: brightness), + theme: ThemeData(brightness: brightness, useMaterial3: false), home: Scaffold( body: Center( child: Builder( @@ -1689,6 +1689,7 @@ void main() { testWidgets('Chip uses ThemeData chip theme if present', (WidgetTester tester) async { final ThemeData theme = ThemeData( + useMaterial3: false, platform: TargetPlatform.android, primarySwatch: Colors.red, ); @@ -1792,7 +1793,7 @@ void main() { await tester.pumpWidget( wrapForChip( child: Theme( - data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.padded), + data: ThemeData(useMaterial3: false, materialTapTargetSize: MaterialTapTargetSize.padded), child: Center( child: RawChip( key: key1, @@ -1809,7 +1810,7 @@ void main() { await tester.pumpWidget( wrapForChip( child: Theme( - data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap), + data: ThemeData(useMaterial3: false, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap), child: Center( child: RawChip( key: key2, @@ -2466,6 +2467,7 @@ void main() { testWidgets('Chip elevation and shadow color work correctly', (WidgetTester tester) async { final ThemeData theme = ThemeData( + useMaterial3: false, platform: TargetPlatform.android, primarySwatch: Colors.red, ); @@ -2725,6 +2727,7 @@ void main() { Widget chipWidget({ bool enabled = true, bool selected = false }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Focus( focusNode: focusNode, @@ -2804,6 +2807,7 @@ void main() { Widget chipWidget({ bool enabled = true, bool selected = false }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Focus( focusNode: focusNode, @@ -2886,6 +2890,7 @@ void main() { Widget chipWidget({ bool enabled = true, bool selected = false }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Focus( focusNode: focusNode, @@ -2963,6 +2968,7 @@ void main() { Widget chipWidget({ bool enabled = true, bool selected = false }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Focus( focusNode: focusNode, @@ -3035,6 +3041,7 @@ void main() { Widget chipWidget({ bool enabled = true, bool selected = false }) { return MaterialApp( theme: ThemeData( + useMaterial3: false, chipTheme: ThemeData.light().chipTheme.copyWith( shape: themeShape, side: themeBorderSide, @@ -3071,6 +3078,7 @@ void main() { Future buildTest(VisualDensity visualDensity) async { return tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: Column( diff --git a/packages/flutter/test/material/chip_theme_test.dart b/packages/flutter/test/material/chip_theme_test.dart index 2ea2eb3f719..ae3b0d93a6d 100644 --- a/packages/flutter/test/material/chip_theme_test.dart +++ b/packages/flutter/test/material/chip_theme_test.dart @@ -147,7 +147,7 @@ void main() { await tester.pumpWidget( MaterialApp( - theme: ThemeData.light().copyWith( + theme: ThemeData.light(useMaterial3: false).copyWith( chipTheme: chipTheme, ), home: Directionality( @@ -193,7 +193,7 @@ void main() { await tester.pumpWidget( MaterialApp( - theme: ThemeData.light().copyWith( + theme: ThemeData.light(useMaterial3: false).copyWith( chipTheme: shadowedChipTheme, ), home: ChipTheme( @@ -242,6 +242,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: ChipTheme( data: shadowedChipTheme, child: Builder( @@ -654,6 +655,7 @@ void main() { Widget chipWidget({ bool selected = false }) { return MaterialApp( theme: ThemeData( + useMaterial3: false, chipTheme: ThemeData.light().chipTheme.copyWith( side: MaterialStateBorderSide.resolveWith(getBorderSide), ), @@ -699,7 +701,7 @@ void main() { Widget chipWidget({ bool selected = false }) { return MaterialApp( - theme: ThemeData(chipTheme: chipTheme), + theme: ThemeData(useMaterial3: false, chipTheme: chipTheme), home: Scaffold( body: ChoiceChip( label: const Text('Chip'), @@ -739,7 +741,7 @@ void main() { Widget chipWidget({ bool selected = false }) { return MaterialApp( - theme: ThemeData(chipTheme: chipTheme), + theme: ThemeData(useMaterial3: false, chipTheme: chipTheme), home: Scaffold( body: ChoiceChip( label: const Text('Chip'), diff --git a/packages/flutter/test/material/choice_chip_test.dart b/packages/flutter/test/material/choice_chip_test.dart index 1d8da36934a..981d2b29360 100644 --- a/packages/flutter/test/material/choice_chip_test.dart +++ b/packages/flutter/test/material/choice_chip_test.dart @@ -403,7 +403,7 @@ void main() { testWidgets('ChoiceChip defaults', (WidgetTester tester) async { Widget buildFrame(Brightness brightness) { return MaterialApp( - theme: ThemeData(brightness: brightness), + theme: ThemeData(useMaterial3: false, brightness: brightness), home: const Scaffold( body: Center( child: ChoiceChip( diff --git a/packages/flutter/test/material/circle_avatar_test.dart b/packages/flutter/test/material/circle_avatar_test.dart index f05a1026905..bf4ffe919d0 100644 --- a/packages/flutter/test/material/circle_avatar_test.dart +++ b/packages/flutter/test/material/circle_avatar_test.dart @@ -287,7 +287,7 @@ void main() { // can be deleted. testWidgets('CircleAvatar default colors with light theme', (WidgetTester tester) async { - final ThemeData theme = ThemeData(primaryColor: Colors.grey.shade100); + final ThemeData theme = ThemeData(useMaterial3: false, primaryColor: Colors.grey.shade100); await tester.pumpWidget( wrap( child: Theme( @@ -309,7 +309,7 @@ void main() { }); testWidgets('CircleAvatar default colors with dark theme', (WidgetTester tester) async { - final ThemeData theme = ThemeData(primaryColor: Colors.grey.shade800); + final ThemeData theme = ThemeData(useMaterial3: false, primaryColor: Colors.grey.shade800); await tester.pumpWidget( wrap( child: Theme( @@ -337,7 +337,9 @@ Widget wrap({ required Widget child }) { textDirection: TextDirection.ltr, child: MediaQuery( data: const MediaQueryData(), - child: Center(child: child), + child: MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Center(child: child)), ), ); } diff --git a/packages/flutter/test/material/data_table_test.dart b/packages/flutter/test/material/data_table_test.dart index 6918f5c3cc8..4e9d0af6e9f 100644 --- a/packages/flutter/test/material/data_table_test.dart +++ b/packages/flutter/test/material/data_table_test.dart @@ -1680,6 +1680,7 @@ void main() { } await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material(child: buildTable()), )); diff --git a/packages/flutter/test/material/date_picker_test.dart b/packages/flutter/test/material/date_picker_test.dart index edaccd0d68e..a7281b85ebe 100644 --- a/packages/flutter/test/material/date_picker_test.dart +++ b/packages/flutter/test/material/date_picker_test.dart @@ -382,6 +382,7 @@ void main() { ); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Center( child: Builder( builder: (BuildContext context) { @@ -417,7 +418,7 @@ void main() { ); await tester.pumpWidget( MaterialApp( - theme: ThemeData.fallback().copyWith(dialogTheme: customDialogTheme), + theme: ThemeData.fallback(useMaterial3: false).copyWith(dialogTheme: customDialogTheme), home: Center( child: Builder( builder: (BuildContext context) { @@ -447,6 +448,7 @@ void main() { testWidgets('OK Cancel button layout', (WidgetTester tester) async { Widget buildFrame(TextDirection textDirection) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: Builder( diff --git a/packages/flutter/test/material/date_range_picker_test.dart b/packages/flutter/test/material/date_range_picker_test.dart index 9ec2e684dab..6feafa939d7 100644 --- a/packages/flutter/test/material/date_range_picker_test.dart +++ b/packages/flutter/test/material/date_range_picker_test.dart @@ -504,6 +504,7 @@ void main() { testWidgets('OK Cancel button layout', (WidgetTester tester) async { Widget buildFrame(TextDirection textDirection) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: Builder( @@ -1062,9 +1063,10 @@ void main() { testWidgets('DatePickerDialog is state restorable', (WidgetTester tester) async { await tester.pumpWidget( - const MaterialApp( + MaterialApp( + theme: ThemeData(useMaterial3: false), restorationScopeId: 'app', - home: _RestorableDateRangePickerDialogTestWidget(), + home: const _RestorableDateRangePickerDialogTestWidget(), ), ); diff --git a/packages/flutter/test/material/dialog_theme_test.dart b/packages/flutter/test/material/dialog_theme_test.dart index f02bd471e9e..f215649d482 100644 --- a/packages/flutter/test/material/dialog_theme_test.dart +++ b/packages/flutter/test/material/dialog_theme_test.dart @@ -171,7 +171,7 @@ void main() { actions: [ ], alignment: Alignment.topRight, ); - final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(alignment: Alignment.bottomLeft)); + final ThemeData theme = ThemeData(useMaterial3: false, dialogTheme: const DialogTheme(alignment: Alignment.bottomLeft)); await tester.pumpWidget( _appWithDialog(tester, dialog, theme: theme), @@ -193,7 +193,7 @@ void main() { title: Text('Title'), actions: [ ], ); - final ThemeData theme = ThemeData(dialogTheme: const DialogTheme(shape: customBorder)); + final ThemeData theme = ThemeData(useMaterial3: false, dialogTheme: const DialogTheme(shape: customBorder)); await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme)); await tester.tap(find.text('X')); @@ -248,7 +248,7 @@ void main() { testWidgets('Custom Icon Color - Theme - lowest preference', (WidgetTester tester) async { const Color iconThemeColor = Colors.yellow; - final ThemeData theme = ThemeData(iconTheme: const IconThemeData(color: iconThemeColor)); + final ThemeData theme = ThemeData(useMaterial3: false, iconTheme: const IconThemeData(color: iconThemeColor)); const AlertDialog dialog = AlertDialog( icon: Icon(Icons.ac_unit), actions: [ ], @@ -320,7 +320,7 @@ void main() { title: Text(titleText), actions: [ ], ); - final ThemeData theme = ThemeData(textTheme: const TextTheme(titleLarge: titleTextStyle)); + final ThemeData theme = ThemeData(useMaterial3: false, textTheme: const TextTheme(titleLarge: titleTextStyle)); await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme)); await tester.tap(find.text('X')); @@ -419,7 +419,7 @@ void main() { content: Text(contentText), actions: [ ], ); - final ThemeData theme = ThemeData(textTheme: const TextTheme(titleMedium: contentTextStyle)); + final ThemeData theme = ThemeData(useMaterial3: false, textTheme: const TextTheme(titleMedium: contentTextStyle)); await tester.pumpWidget(_appWithDialog(tester, dialog, theme: theme)); await tester.tap(find.text('X')); diff --git a/packages/flutter/test/material/divider_test.dart b/packages/flutter/test/material/divider_test.dart index 10681474cc1..71367678083 100644 --- a/packages/flutter/test/material/divider_test.dart +++ b/packages/flutter/test/material/divider_test.dart @@ -9,9 +9,9 @@ import '../rendering/mock_canvas.dart'; void main() { testWidgets('Divider control test', (WidgetTester tester) async { await tester.pumpWidget( - const Directionality( - textDirection: TextDirection.ltr, - child: Center( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Center( child: Divider(), ), ), @@ -94,9 +94,9 @@ void main() { testWidgets('Vertical Divider Test', (WidgetTester tester) async { await tester.pumpWidget( - const Directionality( - textDirection: TextDirection.ltr, - child: Center( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Center( child: VerticalDivider(), ), ), diff --git a/packages/flutter/test/material/divider_theme_test.dart b/packages/flutter/test/material/divider_theme_test.dart index cca3c1d631e..49afe07313a 100644 --- a/packages/flutter/test/material/divider_theme_test.dart +++ b/packages/flutter/test/material/divider_theme_test.dart @@ -272,8 +272,9 @@ void main() { group('Horizontal Divider', () { testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async { - await tester.pumpWidget(const MaterialApp( - home: Scaffold( + await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Scaffold( body: Divider(), ), )); @@ -285,7 +286,7 @@ void main() { final BoxDecoration decoration = container.decoration! as BoxDecoration; expect(decoration.border!.bottom.width, 0.0); - final ThemeData theme = ThemeData(); + final ThemeData theme = ThemeData(useMaterial3: false); expect(decoration.border!.bottom.color, theme.dividerColor); final Rect dividerRect = tester.getRect(find.byType(Divider)); @@ -314,8 +315,9 @@ void main() { group('Vertical Divider', () { testWidgets('Passing no DividerThemeData returns defaults', (WidgetTester tester) async { - await tester.pumpWidget(const MaterialApp( - home: Scaffold( + await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Scaffold( body: VerticalDivider(), ), )); @@ -328,7 +330,7 @@ void main() { final Border border = decoration.border! as Border; expect(border.left.width, 0.0); - final ThemeData theme = ThemeData(); + final ThemeData theme = ThemeData(useMaterial3: false); expect(border.left.color, theme.dividerColor); final Rect dividerRect = tester.getRect(find.byType(VerticalDivider)); diff --git a/packages/flutter/test/material/drawer_test.dart b/packages/flutter/test/material/drawer_test.dart index e683d38834a..faf3c2522bb 100644 --- a/packages/flutter/test/material/drawer_test.dart +++ b/packages/flutter/test/material/drawer_test.dart @@ -14,6 +14,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( drawer: Drawer( child: ListView( diff --git a/packages/flutter/test/material/dropdown_test.dart b/packages/flutter/test/material/dropdown_test.dart index cb53f4a1796..d2a3c9d14f8 100644 --- a/packages/flutter/test/material/dropdown_test.dart +++ b/packages/flutter/test/material/dropdown_test.dart @@ -16,6 +16,7 @@ library; import 'dart:math' as math; import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; @@ -161,39 +162,43 @@ Widget buildFrame({ double? menuMaxHeight, EdgeInsetsGeometry? padding, Alignment dropdownAlignment = Alignment.center, + bool? useMaterial3, }) { - return TestApp( - textDirection: textDirection, - mediaSize: mediaSize, - child: Material( - child: Align( - alignment: dropdownAlignment, - child: RepaintBoundary( - child: buildDropdown( - isFormField: isFormField, - buttonKey: buttonKey, - value: value, - hint: hint, - disabledHint: disabledHint, - onChanged: onChanged, - onTap: onTap, - icon: icon, - iconSize: iconSize, - iconDisabledColor: iconDisabledColor, - iconEnabledColor: iconEnabledColor, - isDense: isDense, - isExpanded: isExpanded, - underline: underline, - focusNode: focusNode, - autofocus: autofocus, - focusColor: focusColor, - dropdownColor: dropdownColor, - items: items, - selectedItemBuilder: selectedItemBuilder, - itemHeight: itemHeight, - alignment: alignment, - menuMaxHeight: menuMaxHeight, - padding: padding, + return Theme( + data: ThemeData(useMaterial3: useMaterial3), + child: TestApp( + textDirection: textDirection, + mediaSize: mediaSize, + child: Material( + child: Align( + alignment: dropdownAlignment, + child: RepaintBoundary( + child: buildDropdown( + isFormField: isFormField, + buttonKey: buttonKey, + value: value, + hint: hint, + disabledHint: disabledHint, + onChanged: onChanged, + onTap: onTap, + icon: icon, + iconSize: iconSize, + iconDisabledColor: iconDisabledColor, + iconEnabledColor: iconEnabledColor, + isDense: isDense, + isExpanded: isExpanded, + underline: underline, + focusNode: focusNode, + autofocus: autofocus, + focusColor: focusColor, + dropdownColor: dropdownColor, + items: items, + selectedItemBuilder: selectedItemBuilder, + itemHeight: itemHeight, + alignment: alignment, + menuMaxHeight: menuMaxHeight, + padding: padding, + ), ), ), ), @@ -207,6 +212,7 @@ Widget buildDropdownWithHint({ bool enableSelectedItemBuilder = false, }){ return buildFrame( + useMaterial3: false, mediaSize: const Size(800, 600), itemHeight: 100.0, alignment: alignment, @@ -286,6 +292,7 @@ Future checkDropdownColor(WidgetTester tester, {Color? color, bool isFormF const String text = 'foo'; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: isFormField ? Form( @@ -335,7 +342,7 @@ Future checkDropdownColor(WidgetTester tester, {Color? color, bool isFormF void main() { testWidgets('Default dropdown golden', (WidgetTester tester) async { final Key buttonKey = UniqueKey(); - Widget build() => buildFrame(buttonKey: buttonKey, onChanged: onChanged); + Widget build() => buildFrame(buttonKey: buttonKey, onChanged: onChanged, useMaterial3: false); await tester.pumpWidget(build()); final Finder buttonFinder = find.byKey(buttonKey); assert(tester.renderObject(buttonFinder).attached); @@ -347,7 +354,7 @@ void main() { testWidgets('Expanded dropdown golden', (WidgetTester tester) async { final Key buttonKey = UniqueKey(); - Widget build() => buildFrame(buttonKey: buttonKey, isExpanded: true, onChanged: onChanged); + Widget build() => buildFrame(buttonKey: buttonKey, isExpanded: true, onChanged: onChanged, useMaterial3: false); await tester.pumpWidget(build()); final Finder buttonFinder = find.byKey(buttonKey); assert(tester.renderObject(buttonFinder).attached); @@ -609,6 +616,7 @@ void main() { // Regression test for https://github.com/flutter/flutter/issues/66870 await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( appBar: AppBar(), body: Column( @@ -697,7 +705,7 @@ void main() { testWidgets('Dropdown button aligns selected menu item ($textDirection)', (WidgetTester tester) async { final Key buttonKey = UniqueKey(); - Widget build() => buildFrame(buttonKey: buttonKey, textDirection: textDirection, onChanged: onChanged); + Widget build() => buildFrame(buttonKey: buttonKey, textDirection: textDirection, onChanged: onChanged, useMaterial3: false); await tester.pumpWidget(build()); final RenderBox buttonBox = tester.renderObject(find.byKey(buttonKey)); @@ -2382,12 +2390,12 @@ void main() { tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; final UniqueKey buttonKey = UniqueKey(); final FocusNode focusNode = FocusNode(debugLabel: 'DropdownButton'); - await tester.pumpWidget(buildFrame(buttonKey: buttonKey, onChanged: onChanged, focusNode: focusNode, autofocus: true)); + await tester.pumpWidget(buildFrame(buttonKey: buttonKey, onChanged: onChanged, focusNode: focusNode, autofocus: true, useMaterial3: false)); await tester.pumpAndSettle(); // Pump a frame for autofocus to take effect. expect(focusNode.hasPrimaryFocus, isTrue); expect(find.byType(Material), paints..rect(rect: const Rect.fromLTRB(348.0, 276.0, 452.0, 324.0), color: const Color(0x1f000000))); - await tester.pumpWidget(buildFrame(buttonKey: buttonKey, onChanged: onChanged, focusNode: focusNode, focusColor: const Color(0xff00ff00))); + await tester.pumpWidget(buildFrame(buttonKey: buttonKey, onChanged: onChanged, focusNode: focusNode, focusColor: const Color(0xff00ff00), useMaterial3: false)); await tester.pumpAndSettle(); // Pump a frame for autofocus to take effect. expect(find.byType(Material), paints..rect(rect: const Rect.fromLTRB(348.0, 276.0, 452.0, 324.0), color: const Color(0x1f00ff00))); }); @@ -2696,6 +2704,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Center( child: StatefulBuilder( @@ -3169,6 +3178,7 @@ void main() { final UniqueKey itemKey = UniqueKey(); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Center( child: DropdownButton( @@ -3504,8 +3514,9 @@ void main() { await tester.pumpAndSettle(); // finish the menu animation // The inherited ScrollBehavior should not apply Scrollbars since they are - // already built in to the widget. - expect(find.byType(CupertinoScrollbar), findsNothing); + // already built in to the widget. For iOS platform, ScrollBar directly returns + // CupertinoScrollbar + expect(find.byType(CupertinoScrollbar), debugDefaultTargetPlatformOverride == TargetPlatform.iOS ? findsOneWidget : findsNothing); expect(find.byType(Scrollbar), findsOneWidget); expect(find.byType(RawScrollbar), findsNothing); @@ -3516,6 +3527,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Center( child: DropdownButton( diff --git a/packages/flutter/test/material/expand_icon_test.dart b/packages/flutter/test/material/expand_icon_test.dart index 8acf7071c16..4d795da9adb 100644 --- a/packages/flutter/test/material/expand_icon_test.dart +++ b/packages/flutter/test/material/expand_icon_test.dart @@ -77,6 +77,7 @@ void main() { IconTheme iconTheme; // Light mode test await tester.pumpWidget(wrap( + theme: ThemeData(useMaterial3: false), child: const ExpandIcon(onPressed: null), )); await tester.pumpAndSettle(); @@ -87,7 +88,7 @@ void main() { // Dark mode test await tester.pumpWidget(wrap( child: const ExpandIcon(onPressed: null), - theme: ThemeData(brightness: Brightness.dark), + theme: ThemeData(useMaterial3: false, brightness: Brightness.dark), )); await tester.pumpAndSettle(); @@ -176,6 +177,7 @@ void main() { final SemanticsHandle handle = tester.ensureSemantics(); const DefaultMaterialLocalizations localizations = DefaultMaterialLocalizations(); await tester.pumpWidget(wrap( + theme: ThemeData(useMaterial3: false), child: ExpandIcon( isExpanded: true, onPressed: (bool _) { }, diff --git a/packages/flutter/test/material/expansion_panel_test.dart b/packages/flutter/test/material/expansion_panel_test.dart index b699647ff5a..7c2fc32a49b 100644 --- a/packages/flutter/test/material/expansion_panel_test.dart +++ b/packages/flutter/test/material/expansion_panel_test.dart @@ -183,6 +183,7 @@ void main() { final Key headerKey = UniqueKey(); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: ExpansionPanelListSemanticsTest(headerKey: headerKey), ), ); @@ -1024,6 +1025,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: SingleChildScrollView( child: expansionList, ), diff --git a/packages/flutter/test/material/expansion_tile_test.dart b/packages/flutter/test/material/expansion_tile_test.dart index f5694947361..9d6fba1a420 100644 --- a/packages/flutter/test/material/expansion_tile_test.dart +++ b/packages/flutter/test/material/expansion_tile_test.dart @@ -167,6 +167,7 @@ void main() { await tester.pumpWidget( MaterialApp( theme: ThemeData( + useMaterial3: false, colorScheme: ColorScheme.fromSwatch().copyWith(primary: foregroundColor), unselectedWidgetColor: unselectedWidgetColor, textTheme: const TextTheme(titleMedium: TextStyle(color: headerColor)), diff --git a/packages/flutter/test/material/filter_chip_test.dart b/packages/flutter/test/material/filter_chip_test.dart index 9e62544b825..94c19e1d52d 100644 --- a/packages/flutter/test/material/filter_chip_test.dart +++ b/packages/flutter/test/material/filter_chip_test.dart @@ -13,9 +13,10 @@ Widget wrapForChip({ TextDirection textDirection = TextDirection.ltr, double textScaleFactor = 1.0, Brightness brightness = Brightness.light, + bool? useMaterial3, }) { return MaterialApp( - theme: ThemeData(brightness: brightness), + theme: ThemeData(brightness: brightness, useMaterial3: useMaterial3), home: Directionality( textDirection: textDirection, child: MediaQuery( @@ -31,9 +32,11 @@ Future pumpCheckmarkChip( required Widget chip, Color? themeColor, Brightness brightness = Brightness.light, + ThemeData? theme, }) async { await tester.pumpWidget( wrapForChip( + useMaterial3: false, brightness: brightness, child: Builder( builder: (BuildContext context) { @@ -385,6 +388,7 @@ void main() { testWidgets('Filter chip check mark color is determined by platform brightness when light', (WidgetTester tester) async { await pumpCheckmarkChip( + theme: ThemeData(useMaterial3: false), tester, chip: selectedFilterChip(), ); @@ -400,6 +404,7 @@ void main() { tester, chip: selectedFilterChip(), brightness: Brightness.dark, + theme: ThemeData(useMaterial3: false), ); expectCheckmarkColor( diff --git a/packages/flutter/test/material/flexible_space_bar_stretch_mode_test.dart b/packages/flutter/test/material/flexible_space_bar_stretch_mode_test.dart index d43165dd4e5..86efe7056f7 100644 --- a/packages/flutter/test/material/flexible_space_bar_stretch_mode_test.dart +++ b/packages/flutter/test/material/flexible_space_bar_stretch_mode_test.dart @@ -53,6 +53,7 @@ void main() { testWidgets('FlexibleSpaceBar stretch mode blurBackground', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: CustomScrollView( physics: const BouncingScrollPhysics(), diff --git a/packages/flutter/test/material/flexible_space_bar_test.dart b/packages/flutter/test/material/flexible_space_bar_test.dart index f5374a958f7..73c4ed8aff5 100644 --- a/packages/flutter/test/material/flexible_space_bar_test.dart +++ b/packages/flutter/test/material/flexible_space_bar_test.dart @@ -81,6 +81,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: CustomScrollView( key: dragTarget, @@ -172,6 +173,7 @@ void main() { const double expandedHeight = 200; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: CustomScrollView( slivers: [ @@ -438,6 +440,7 @@ void main() { late double width; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Builder( builder: (BuildContext context) { @@ -486,6 +489,7 @@ void main() { const double expandedTitleScale = 3.0; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: CustomScrollView( slivers: [ @@ -555,6 +559,7 @@ void main() { const double height = 300.0; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: CustomScrollView( slivers: [ @@ -615,6 +620,7 @@ void main() { const double expandedTitleScale = 3.0; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: CustomScrollView( slivers: [ @@ -674,7 +680,7 @@ void main() { testWidgets('FlexibleSpaceBar test titlePadding defaults', (WidgetTester tester) async { Widget buildFrame(TargetPlatform platform, bool? centerTitle) { return MaterialApp( - theme: ThemeData(platform: platform), + theme: ThemeData(platform: platform, useMaterial3: false), home: Scaffold( appBar: AppBar( flexibleSpace: FlexibleSpaceBar( @@ -724,7 +730,7 @@ void main() { testWidgets('FlexibleSpaceBar test titlePadding override', (WidgetTester tester) async { Widget buildFrame(TargetPlatform platform, bool? centerTitle) { return MaterialApp( - theme: ThemeData(platform: platform), + theme: ThemeData(platform: platform, useMaterial3: false), home: Scaffold( appBar: AppBar( flexibleSpace: FlexibleSpaceBar( diff --git a/packages/flutter/test/material/inherited_theme_test.dart b/packages/flutter/test/material/inherited_theme_test.dart index ee8f3635e86..9cffa4706e7 100644 --- a/packages/flutter/test/material/inherited_theme_test.dart +++ b/packages/flutter/test/material/inherited_theme_test.dart @@ -99,6 +99,7 @@ void main() { Widget buildFrame() { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: PopupMenuTheme( data: const PopupMenuThemeData( diff --git a/packages/flutter/test/material/ink_paint_test.dart b/packages/flutter/test/material/ink_paint_test.dart index f6cba22839f..e62cc7b7107 100644 --- a/packages/flutter/test/material/ink_paint_test.dart +++ b/packages/flutter/test/material/ink_paint_test.dart @@ -59,9 +59,9 @@ void main() { const BorderRadius borderRadius = BorderRadius.all(Radius.circular(6.0)); await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Material( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( child: Center( child: SizedBox( width: 200.0, @@ -190,9 +190,9 @@ void main() { testWidgets('Does the Ink widget render anything', (WidgetTester tester) async { await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Material( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( child: Center( child: Ink( color: Colors.blue, @@ -222,9 +222,9 @@ void main() { ); await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Material( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( child: Center( child: Ink( color: Colors.red, @@ -250,9 +250,9 @@ void main() { ); await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Material( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( child: Center( child: InkWell( // this is at a different depth in the tree so it's now a new InkWell splashColor: Colors.green, @@ -518,9 +518,9 @@ void main() { const Color splashColor = Color(0xff00ff00); Widget buildWidget({InteractiveInkFeatureFactory? splashFactory}) { - return Directionality( - textDirection: TextDirection.ltr, - child: Material( + return MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( child: Center( child: SizedBox( width: 100.0, diff --git a/packages/flutter/test/material/ink_splash_test.dart b/packages/flutter/test/material/ink_splash_test.dart index c0886c5d51c..f178004ebce 100644 --- a/packages/flutter/test/material/ink_splash_test.dart +++ b/packages/flutter/test/material/ink_splash_test.dart @@ -30,6 +30,7 @@ void main() { testWidgets('InkWell with NoSplash splashFactory paints nothing', (WidgetTester tester) async { Widget buildFrame({ InteractiveInkFeatureFactory? splashFactory }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Center( child: Material( diff --git a/packages/flutter/test/material/ink_well_test.dart b/packages/flutter/test/material/ink_well_test.dart index 26110554c7c..60d64ed420d 100644 --- a/packages/flutter/test/material/ink_well_test.dart +++ b/packages/flutter/test/material/ink_well_test.dart @@ -338,23 +338,26 @@ void main() { FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTouch; final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus'); const Color splashColor = Color(0xffff0000); - await tester.pumpWidget(Material( - child: Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: Focus( - focusNode: focusNode, - child: SizedBox( - width: 100, - height: 100, - child: InkWell( - hoverColor: const Color(0xff00ff00), - splashColor: splashColor, - focusColor: const Color(0xff0000ff), - highlightColor: const Color(0xf00fffff), - onTap: () { }, - onLongPress: () { }, - onHover: (bool hover) { }, + await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Focus( + focusNode: focusNode, + child: SizedBox( + width: 100, + height: 100, + child: InkWell( + hoverColor: const Color(0xff00ff00), + splashColor: splashColor, + focusColor: const Color(0xff0000ff), + highlightColor: const Color(0xf00fffff), + onTap: () { }, + onLongPress: () { }, + onHover: (bool hover) { }, + ), ), ), ), @@ -376,31 +379,34 @@ void main() { FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTouch; final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus'); const Color splashColor = Color(0xffff0000); - await tester.pumpWidget(Material( - child: Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: Focus( - focusNode: focusNode, - child: SizedBox( - width: 100, - height: 100, - child: InkWell( - overlayColor: MaterialStateProperty.resolveWith((Set states) { - if (states.contains(MaterialState.hovered)) { - return const Color(0xff00ff00); - } - if (states.contains(MaterialState.focused)) { - return const Color(0xff0000ff); - } - if (states.contains(MaterialState.pressed)) { - return splashColor; - } - return const Color(0xffbadbad); // Shouldn't happen. - }), - onTap: () { }, - onLongPress: () { }, - onHover: (bool hover) { }, + await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: Focus( + focusNode: focusNode, + child: SizedBox( + width: 100, + height: 100, + child: InkWell( + overlayColor: MaterialStateProperty.resolveWith((Set states) { + if (states.contains(MaterialState.hovered)) { + return const Color(0xff00ff00); + } + if (states.contains(MaterialState.focused)) { + return const Color(0xff0000ff); + } + if (states.contains(MaterialState.pressed)) { + return splashColor; + } + return const Color(0xffbadbad); // Shouldn't happen. + }), + onTap: () { }, + onLongPress: () { }, + onHover: (bool hover) { }, + ), ), ), ), @@ -820,19 +826,22 @@ testWidgets('InkResponse radius can be updated', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/121626. final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus'); Widget boilerplate(BorderRadius borderRadius) { - return Material( - child: Directionality( - textDirection: TextDirection.ltr, - child: Align( - alignment: Alignment.topLeft, - child: SizedBox( - width: 100, - height: 100, - child: MouseRegion( - child: InkWell( - focusNode: focusNode, - customBorder: RoundedRectangleBorder(borderRadius: borderRadius), - onTap: () { }, + return MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + width: 100, + height: 100, + child: MouseRegion( + child: InkWell( + focusNode: focusNode, + customBorder: RoundedRectangleBorder(borderRadius: borderRadius), + onTap: () { }, + ), ), ), ), @@ -1108,9 +1117,9 @@ testWidgets('InkResponse radius can be updated', (WidgetTester tester) async { testWidgets('splashing survives scrolling when keep-alive is enabled', (WidgetTester tester) async { Future runTest(bool keepAlive) async { await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Material( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( child: CompositedTransformFollower( // forces a layer, which makes the paints easier to separate out link: LayerLink(), @@ -1325,16 +1334,19 @@ testWidgets('InkResponse radius can be updated', (WidgetTester tester) async { } await tester.pumpWidget( - Material( - child: Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: paddedInkWell( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Center( child: paddedInkWell( - key: middleKey, child: paddedInkWell( - key: innerKey, - child: const SizedBox(width: 50, height: 50), + key: middleKey, + child: paddedInkWell( + key: innerKey, + child: const SizedBox(width: 50, height: 50), + ), ), ), ), @@ -1391,24 +1403,27 @@ testWidgets('InkResponse radius can be updated', (WidgetTester tester) async { } await tester.pumpWidget( - Material( - child: Directionality( - textDirection: TextDirection.ltr, - child: Align( - alignment: Alignment.topLeft, - child: SizedBox( - width: 200, - height: 100, - child: Row( - children: [ - paddedInkWell( - key: middleKey, - child: paddedInkWell( - key: innerKey, + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + width: 200, + height: 100, + child: Row( + children: [ + paddedInkWell( + key: middleKey, + child: paddedInkWell( + key: innerKey, + ), ), - ), - const SizedBox(), - ], + const SizedBox(), + ], + ), ), ), ), @@ -1424,23 +1439,26 @@ testWidgets('InkResponse radius can be updated', (WidgetTester tester) async { // Reparent parent await tester.pumpWidget( - Material( - child: Directionality( - textDirection: TextDirection.ltr, - child: Align( - alignment: Alignment.topLeft, - child: SizedBox( - width: 200, - height: 100, - child: Row( - children: [ - paddedInkWell( - key: innerKey, - ), - paddedInkWell( - key: middleKey, - ), - ], + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + width: 200, + height: 100, + child: Row( + children: [ + paddedInkWell( + key: innerKey, + ), + paddedInkWell( + key: middleKey, + ), + ], + ), ), ), ), @@ -1479,16 +1497,19 @@ testWidgets('InkResponse radius can be updated', (WidgetTester tester) async { } await tester.pumpWidget( - Material( - child: Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: paddedInkWell( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Center( child: paddedInkWell( - key: middleKey, child: paddedInkWell( - key: innerKey, - child: const SizedBox(width: 50, height: 50), + key: middleKey, + child: paddedInkWell( + key: innerKey, + child: const SizedBox(width: 50, height: 50), + ), ), ), ), @@ -1514,39 +1535,42 @@ testWidgets('InkResponse radius can be updated', (WidgetTester tester) async { final GlobalKey leftKey = GlobalKey(); final GlobalKey rightKey = GlobalKey(); await tester.pumpWidget( - Material( - child: Directionality( - textDirection: TextDirection.ltr, - child: Center( - child: SizedBox( - width: 100, - height: 100, - child: InkWell( - key: parentKey, - onTap: () {}, - child: Center( - child: SizedBox( - width: 100, - height: 50, - child: Row( - children: [ - SizedBox( - width: 50, - height: 50, - child: InkWell( - key: leftKey, - onTap: () {}, + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Center( + child: SizedBox( + width: 100, + height: 100, + child: InkWell( + key: parentKey, + onTap: () {}, + child: Center( + child: SizedBox( + width: 100, + height: 50, + child: Row( + children: [ + SizedBox( + width: 50, + height: 50, + child: InkWell( + key: leftKey, + onTap: () {}, + ), ), - ), - SizedBox( - width: 50, - height: 50, - child: InkWell( - key: rightKey, - onTap: () {}, + SizedBox( + width: 50, + height: 50, + child: InkWell( + key: rightKey, + onTap: () {}, + ), ), - ), - ], + ], + ), ), ), ), @@ -1610,47 +1634,50 @@ testWidgets('InkResponse radius can be updated', (WidgetTester tester) async { Widget? leftChild, Widget? rightChild, }) { - return Material( - child: Directionality( - textDirection: TextDirection.ltr, - child: Align( - alignment: Alignment.topLeft, - child: SizedBox( - width: leftWidth+rightWidth, - height: 100, - child: Row( - children: [ - SizedBox( - width: leftWidth, - height: 100, - child: InkWell( - key: leftKey, - onTap: () {}, - child: Center( - child: SizedBox( - width: leftWidth, - height: 50, - child: leftChild, + return MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + width: leftWidth+rightWidth, + height: 100, + child: Row( + children: [ + SizedBox( + width: leftWidth, + height: 100, + child: InkWell( + key: leftKey, + onTap: () {}, + child: Center( + child: SizedBox( + width: leftWidth, + height: 50, + child: leftChild, + ), ), ), ), - ), - SizedBox( - width: rightWidth, - height: 100, - child: InkWell( - key: rightKey, - onTap: () {}, - child: Center( - child: SizedBox( - width: leftWidth, - height: 50, - child: rightChild, + SizedBox( + width: rightWidth, + height: 100, + child: InkWell( + key: rightKey, + onTap: () {}, + child: Center( + child: SizedBox( + width: leftWidth, + height: 50, + child: rightChild, + ), ), ), ), - ), - ], + ], + ), ), ), ), @@ -1714,24 +1741,27 @@ testWidgets('InkResponse radius can be updated', (WidgetTester tester) async { testWidgets("Ink wells's splash starts before tap is confirmed and disappear after tap is canceled", (WidgetTester tester) async { final GlobalKey innerKey = GlobalKey(); await tester.pumpWidget( - Material( - child: Directionality( - textDirection: TextDirection.ltr, - child: GestureDetector( - onHorizontalDragStart: (_) {}, - child: Center( - child: SizedBox( - width: 100, - height: 100, - child: InkWell( - onTap: () {}, - child: Center( - child: SizedBox( - width: 50, - height: 50, - child: InkWell( - key: innerKey, - onTap: () {}, + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: Directionality( + textDirection: TextDirection.ltr, + child: GestureDetector( + onHorizontalDragStart: (_) {}, + child: Center( + child: SizedBox( + width: 100, + height: 100, + child: InkWell( + onTap: () {}, + child: Center( + child: SizedBox( + width: 50, + height: 50, + child: InkWell( + key: innerKey, + onTap: () {}, + ), ), ), ), diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index ba9930a2f57..c5767468720 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -36,6 +36,7 @@ Widget buildInputDecorator({ ), }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Builder( builder: (BuildContext context) { @@ -787,6 +788,7 @@ void main() { final TextEditingController controller = TextEditingController(); Widget buildFrame(bool alignLabelWithHint) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Directionality( textDirection: TextDirection.ltr, @@ -837,6 +839,7 @@ void main() { final TextEditingController controller = TextEditingController(); Widget buildFrame(bool alignLabelWithHint) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Directionality( textDirection: TextDirection.ltr, @@ -888,6 +891,7 @@ void main() { final TextEditingController controller = TextEditingController(); Widget buildFrame(bool alignLabelWithHint) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Directionality( textDirection: TextDirection.ltr, @@ -939,6 +943,7 @@ void main() { final TextEditingController controller = TextEditingController(); Widget buildFrame(bool alignLabelWithHint) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Directionality( textDirection: TextDirection.ltr, @@ -5714,6 +5719,7 @@ void main() { late StateSetter setState; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: StatefulBuilder( builder: (BuildContext context, StateSetter setter) { setState = setter; diff --git a/packages/flutter/test/material/list_tile_test.dart b/packages/flutter/test/material/list_tile_test.dart index 3b1dca818e5..d18beb02620 100644 --- a/packages/flutter/test/material/list_tile_test.dart +++ b/packages/flutter/test/material/list_tile_test.dart @@ -991,6 +991,7 @@ void main() { testWidgets('ListTile can be splashed and has correct splash color', (WidgetTester tester) async { final Widget buildApp = MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: SizedBox( @@ -1279,6 +1280,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: ListTile( @@ -1807,6 +1809,7 @@ void main() { bool selected = false, }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: Builder( @@ -3571,6 +3574,7 @@ void main() { }); testWidgets('ListTile text color', (WidgetTester tester) async { + final ThemeData theme = ThemeData(useMaterial3: false); Widget buildFrame({ bool dense = false, bool enabled = true, @@ -3578,7 +3582,7 @@ void main() { ListTileStyle? style, }) { return MaterialApp( - theme: ThemeData(useMaterial3: false), + theme: theme, home: Material( child: Center( child: Builder( @@ -3600,8 +3604,6 @@ void main() { ); } - final ThemeData theme = ThemeData(); - // ListTile - ListTileStyle.list (default). await tester.pumpWidget(buildFrame()); RenderParagraph leading = _getTextRenderObject(tester, 'leading'); diff --git a/packages/flutter/test/material/list_tile_theme_test.dart b/packages/flutter/test/material/list_tile_theme_test.dart index 53273095f10..c18921ba8f9 100644 --- a/packages/flutter/test/material/list_tile_theme_test.dart +++ b/packages/flutter/test/material/list_tile_theme_test.dart @@ -215,6 +215,7 @@ void main() { Color? textColor, }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: ListTileTheme( diff --git a/packages/flutter/test/material/menu_anchor_test.dart b/packages/flutter/test/material/menu_anchor_test.dart index 5e523b05f88..6e3441ea874 100644 --- a/packages/flutter/test/material/menu_anchor_test.dart +++ b/packages/flutter/test/material/menu_anchor_test.dart @@ -82,6 +82,7 @@ void main() { }) { final FocusNode focusNode = FocusNode(); return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Directionality( textDirection: textDirection, @@ -145,7 +146,7 @@ void main() { testWidgets('Menu responds to density changes', (WidgetTester tester) async { Widget buildMenu({VisualDensity? visualDensity = VisualDensity.standard}) { return MaterialApp( - theme: ThemeData(visualDensity: visualDensity), + theme: ThemeData(visualDensity: visualDensity, useMaterial3: false), home: Material( child: Column( children: [ @@ -542,6 +543,7 @@ void main() { testWidgets('geometry', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Column( children: [ @@ -606,6 +608,7 @@ void main() { testWidgets('geometry with RTL direction', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Directionality( textDirection: TextDirection.rtl, @@ -815,6 +818,7 @@ void main() { Padding( padding: const EdgeInsets.all(10.0), child: MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Column( children: [ @@ -867,6 +871,7 @@ void main() { Padding( padding: const EdgeInsets.all(10.0), child: MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Directionality( textDirection: TextDirection.rtl, @@ -2295,6 +2300,7 @@ void main() { await changeSurfaceSize(tester, const Size(800, 600)); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Column( children: [ @@ -2338,6 +2344,7 @@ void main() { await changeSurfaceSize(tester, const Size(800, 600)); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Directionality( textDirection: TextDirection.rtl, child: Material( @@ -2384,6 +2391,7 @@ void main() { await changeSurfaceSize(tester, const Size(300, 300)); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Builder( builder: (BuildContext context) { return Directionality( @@ -2428,6 +2436,7 @@ void main() { await changeSurfaceSize(tester, const Size(300, 300)); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Builder( builder: (BuildContext context) { return Directionality( @@ -2472,6 +2481,7 @@ void main() { await changeSurfaceSize(tester, const Size(800, 600)); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Builder( builder: (BuildContext context) { return Directionality( @@ -2548,6 +2558,7 @@ void main() { await changeSurfaceSize(tester, const Size(800, 600)); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Builder( builder: (BuildContext context) { return Directionality( @@ -2624,6 +2635,7 @@ void main() { await changeSurfaceSize(tester, const Size(800, 600)); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Builder( builder: (BuildContext context) { return Directionality( @@ -2675,6 +2687,7 @@ void main() { await changeSurfaceSize(tester, const Size(800, 600)); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Builder( builder: (BuildContext context) { return Directionality( @@ -2730,7 +2743,7 @@ void main() { }) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData.light().copyWith(visualDensity: visualDensity), + theme: ThemeData.light(useMaterial3: false).copyWith(visualDensity: visualDensity), home: Directionality( textDirection: textDirection, child: Material( diff --git a/packages/flutter/test/material/menu_bar_theme_test.dart b/packages/flutter/test/material/menu_bar_theme_test.dart index c8d4aa6c2d3..003ff987ed2 100644 --- a/packages/flutter/test/material/menu_bar_theme_test.dart +++ b/packages/flutter/test/material/menu_bar_theme_test.dart @@ -55,6 +55,7 @@ void main() { testWidgets('theme is honored', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Builder(builder: (BuildContext context) { return MenuTheme( @@ -107,6 +108,7 @@ void main() { testWidgets('Constructor parameters override theme parameters', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Builder( builder: (BuildContext context) { diff --git a/packages/flutter/test/material/menu_style_test.dart b/packages/flutter/test/material/menu_style_test.dart index 482dbe39b1d..9f1de888553 100644 --- a/packages/flutter/test/material/menu_style_test.dart +++ b/packages/flutter/test/material/menu_style_test.dart @@ -239,6 +239,7 @@ void main() { testWidgets('visual density', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Column( children: [ diff --git a/packages/flutter/test/material/menu_theme_test.dart b/packages/flutter/test/material/menu_theme_test.dart index 52fa532db60..f6fb5d324e3 100644 --- a/packages/flutter/test/material/menu_theme_test.dart +++ b/packages/flutter/test/material/menu_theme_test.dart @@ -55,6 +55,7 @@ void main() { testWidgets('theme is honored', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Builder(builder: (BuildContext context) { return MenuBarTheme( @@ -107,6 +108,7 @@ void main() { testWidgets('Constructor parameters override theme parameters', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Builder( builder: (BuildContext context) { diff --git a/packages/flutter/test/material/mergeable_material_test.dart b/packages/flutter/test/material/mergeable_material_test.dart index 6ae2d3b4661..2e37bff2a26 100644 --- a/packages/flutter/test/material/mergeable_material_test.dart +++ b/packages/flutter/test/material/mergeable_material_test.dart @@ -202,8 +202,9 @@ void main() { testWidgets('MergeableMaterial paints shadows', (WidgetTester tester) async { debugDisableShadows = false; await tester.pumpWidget( - const MaterialApp( - home: Scaffold( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Scaffold( body: SingleChildScrollView( child: MergeableMaterial( children: [ @@ -1100,8 +1101,9 @@ void main() { testWidgets('MergeableMaterial dividers', (WidgetTester tester) async { await tester.pumpWidget( - const MaterialApp( - home: Scaffold( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Scaffold( body: SingleChildScrollView( child: MergeableMaterial( hasDividers: true, @@ -1157,8 +1159,9 @@ void main() { expect(isDivider(boxes[offset + 3], true, false), isTrue); await tester.pumpWidget( - const MaterialApp( - home: Scaffold( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Scaffold( body: SingleChildScrollView( child: MergeableMaterial( hasDividers: true, diff --git a/packages/flutter/test/material/persistent_bottom_sheet_test.dart b/packages/flutter/test/material/persistent_bottom_sheet_test.dart index 670a3d11050..8c51e01ef03 100644 --- a/packages/flutter/test/material/persistent_bottom_sheet_test.dart +++ b/packages/flutter/test/material/persistent_bottom_sheet_test.dart @@ -534,6 +534,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: const Placeholder(), bottomSheet: Container( diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index fda95a5b4d9..13c24d0b8f0 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -1560,6 +1560,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Center( child: PopupMenuButton( @@ -1774,6 +1775,7 @@ void main() { double fontSize = 24, }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), builder: (BuildContext context, Widget? child) { return Directionality( textDirection: textDirection, @@ -2363,6 +2365,7 @@ void main() { Widget buildFrame(double width, double height) { return MaterialApp( + theme: ThemeData(useMaterial3: false), builder: (BuildContext context, Widget? child) { return MediaQuery( data: const MediaQueryData( @@ -2422,6 +2425,7 @@ void main() { Widget buildFrame(double width, double height) { return MaterialApp( + theme: ThemeData(useMaterial3: false), builder: (BuildContext context, Widget? child) { return MediaQuery( data: const MediaQueryData( @@ -2710,6 +2714,7 @@ void main() { Future buildFrameWithoutChild({double? splashRadius}) { return tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Center( child: PopupMenuButton( diff --git a/packages/flutter/test/material/popup_menu_theme_test.dart b/packages/flutter/test/material/popup_menu_theme_test.dart index a9f214f7b6c..4b37dedb96a 100644 --- a/packages/flutter/test/material/popup_menu_theme_test.dart +++ b/packages/flutter/test/material/popup_menu_theme_test.dart @@ -409,7 +409,7 @@ void main() { final Key popupButtonApp = UniqueKey(); final Key enabledPopupItemKey = UniqueKey(); final Key disabledPopupItemKey = UniqueKey(); - final ThemeData theme = ThemeData(); + final ThemeData theme = ThemeData(useMaterial3: false); await tester.pumpWidget(MaterialApp( theme: theme, @@ -511,7 +511,7 @@ void main() { final Key disabledPopupItemKey = UniqueKey(); await tester.pumpWidget(MaterialApp( - theme: ThemeData(popupMenuTheme: popupMenuTheme), + theme: ThemeData(popupMenuTheme: popupMenuTheme, useMaterial3: false), key: popupButtonApp, home: Material( child: Column( diff --git a/packages/flutter/test/material/range_slider_test.dart b/packages/flutter/test/material/range_slider_test.dart index be9b021f881..12c5eabdbb6 100644 --- a/packages/flutter/test/material/range_slider_test.dart +++ b/packages/flutter/test/material/range_slider_test.dart @@ -1407,6 +1407,7 @@ void main() { values = newValues; } return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( // The builder is used to pass the context from the MaterialApp widget // to the [Navigator]. This context is required in order for the diff --git a/packages/flutter/test/material/refresh_indicator_test.dart b/packages/flutter/test/material/refresh_indicator_test.dart index d1cd626be18..9a2248204d9 100644 --- a/packages/flutter/test/material/refresh_indicator_test.dart +++ b/packages/flutter/test/material/refresh_indicator_test.dart @@ -959,6 +959,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: RefreshIndicator( onRefresh: refresh, child: Builder( diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index acba2128531..b204a7073a5 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -581,7 +581,7 @@ void main() { await tester.pumpWidget( MaterialApp( - theme: ThemeData(platform: TargetPlatform.android), + theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false), home: Scaffold( appBar: AppBar( title: const Text('Title'), @@ -746,6 +746,7 @@ void main() { // Regression test for https://github.com/flutter/flutter/pull/92039 await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: MediaQuery( data: const MediaQueryData( // Representing a navigational notch at the bottom of the screen @@ -991,9 +992,9 @@ void main() { late double mediaQueryBottom; Widget buildFrame({ required bool extendBody, bool? resizeToAvoidBottomInset, double viewInsetBottom = 0.0 }) { - return Directionality( - textDirection: TextDirection.ltr, - child: MediaQuery( + return MaterialApp( + theme: ThemeData(useMaterial3: false), + home: MediaQuery( data: MediaQueryData( viewInsets: EdgeInsets.only(bottom: viewInsetBottom), ), diff --git a/packages/flutter/test/material/scrollbar_test.dart b/packages/flutter/test/material/scrollbar_test.dart index 5dd5edf12d7..44addd4fc5c 100644 --- a/packages/flutter/test/material/scrollbar_test.dart +++ b/packages/flutter/test/material/scrollbar_test.dart @@ -851,6 +851,7 @@ void main() { final ScrollController scrollController = ScrollController(); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: PrimaryScrollController( controller: scrollController, child: Scrollbar( @@ -942,6 +943,7 @@ void main() { await tester.pumpWidget( MaterialApp( theme: ThemeData( + useMaterial3: false, scrollbarTheme: ScrollbarThemeData(thumbVisibility: MaterialStateProperty.all(true)), ), home: const SingleChildScrollView( @@ -988,10 +990,13 @@ void main() { testWidgets('Hover animation is not triggered by tap gestures', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData(scrollbarTheme: ScrollbarThemeData( - thumbVisibility: MaterialStateProperty.all(true), - showTrackOnHover: true, - )), + theme: ThemeData( + useMaterial3: false, + scrollbarTheme: ScrollbarThemeData( + thumbVisibility: MaterialStateProperty.all(true), + showTrackOnHover: true, + ), + ), home: const SingleChildScrollView( child: SizedBox(width: 4000.0, height: 4000.0), ), @@ -1060,19 +1065,22 @@ void main() { testWidgets('ScrollbarThemeData.thickness replaces hoverThickness', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData(scrollbarTheme: ScrollbarThemeData( - thumbVisibility: MaterialStateProperty.resolveWith((Set states) => true), - trackVisibility: MaterialStateProperty.resolveWith((Set states) { - return states.contains(MaterialState.hovered); - }), - thickness: MaterialStateProperty.resolveWith((Set states) { - if (states.contains(MaterialState.hovered)) { - return 40.0; - } - // Default thickness - return 8.0; - }), - )), + theme: ThemeData( + useMaterial3: false, + scrollbarTheme: ScrollbarThemeData( + thumbVisibility: MaterialStateProperty.resolveWith((Set states) => true), + trackVisibility: MaterialStateProperty.resolveWith((Set states) { + return states.contains(MaterialState.hovered); + }), + thickness: MaterialStateProperty.resolveWith((Set states) { + if (states.contains(MaterialState.hovered)) { + return 40.0; + } + // Default thickness + return 8.0; + }), + ), + ), home: const SingleChildScrollView( child: SizedBox(width: 4000.0, height: 4000.0), ), @@ -1129,15 +1137,18 @@ void main() { testWidgets('ScrollbarThemeData.trackVisibility replaces showTrackOnHover', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData(scrollbarTheme: ScrollbarThemeData( - thumbVisibility: MaterialStateProperty.all(true), - trackVisibility: MaterialStateProperty.resolveWith((Set states) { - if (states.contains(MaterialState.hovered)) { - return true; - } - return false; - }), - )), + theme: ThemeData( + useMaterial3: false, + scrollbarTheme: ScrollbarThemeData( + thumbVisibility: MaterialStateProperty.all(true), + trackVisibility: MaterialStateProperty.resolveWith((Set states) { + if (states.contains(MaterialState.hovered)) { + return true; + } + return false; + }), + ), + ), home: const SingleChildScrollView( child: SizedBox(width: 4000.0, height: 4000.0), ), @@ -1194,10 +1205,13 @@ void main() { testWidgets('Scrollbar showTrackOnHover', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData(scrollbarTheme: ScrollbarThemeData( - thumbVisibility: MaterialStateProperty.all(true), - showTrackOnHover: true, - )), + theme: ThemeData( + useMaterial3: false, + scrollbarTheme: ScrollbarThemeData( + thumbVisibility: MaterialStateProperty.all(true), + showTrackOnHover: true, + ), + ), home: const SingleChildScrollView( child: SizedBox(width: 4000.0, height: 4000.0), ), @@ -1387,6 +1401,7 @@ void main() { final ScrollController scrollController = ScrollController(); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: PrimaryScrollController( controller: scrollController, child: Scrollbar( @@ -1550,6 +1565,7 @@ void main() { final ScrollController scrollController = ScrollController(); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: PrimaryScrollController( controller: scrollController, child: Scrollbar( diff --git a/packages/flutter/test/material/scrollbar_theme_test.dart b/packages/flutter/test/material/scrollbar_theme_test.dart index c38beef080e..50c6ba74f6a 100644 --- a/packages/flutter/test/material/scrollbar_theme_test.dart +++ b/packages/flutter/test/material/scrollbar_theme_test.dart @@ -35,6 +35,7 @@ void main() { final ScrollController scrollController = ScrollController(); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: ScrollConfiguration( behavior: const NoScrollbarBehavior(), child: Scrollbar( @@ -259,7 +260,7 @@ void main() { testWidgets('ScrollbarTheme can disable gestures', (WidgetTester tester) async { final ScrollController scrollController = ScrollController(); await tester.pumpWidget(MaterialApp( - theme: ThemeData(scrollbarTheme: const ScrollbarThemeData(interactive: false)), + theme: ThemeData(useMaterial3: false, scrollbarTheme: const ScrollbarThemeData(interactive: false)), home: Scrollbar( thumbVisibility: true, controller: scrollController, @@ -306,7 +307,7 @@ void main() { testWidgets('Scrollbar.interactive takes priority over ScrollbarTheme', (WidgetTester tester) async { final ScrollController scrollController = ScrollController(); await tester.pumpWidget(MaterialApp( - theme: ThemeData(scrollbarTheme: const ScrollbarThemeData(interactive: false)), + theme: ThemeData(useMaterial3: false, scrollbarTheme: const ScrollbarThemeData(interactive: false)), home: Scrollbar( interactive: true, thumbVisibility: true, @@ -625,7 +626,7 @@ void main() { } await tester.pumpWidget( MaterialApp( - theme: ThemeData().copyWith( + theme: ThemeData(useMaterial3: false).copyWith( scrollbarTheme: _scrollbarTheme( trackVisibility: MaterialStateProperty.resolveWith(getTrackVisibility), ), diff --git a/packages/flutter/test/material/search_test.dart b/packages/flutter/test/material/search_test.dart index d5c4719c797..3bf869d453f 100644 --- a/packages/flutter/test/material/search_test.dart +++ b/packages/flutter/test/material/search_test.dart @@ -734,7 +734,7 @@ void main() { // Regression test for: https://github.com/flutter/flutter/issues/66781 testWidgets('text in search bar contrasts background (light mode)', (WidgetTester tester) async { - final ThemeData themeData = ThemeData.light(); + final ThemeData themeData = ThemeData(useMaterial3: false); final _TestSearchDelegate delegate = _TestSearchDelegate( defaultAppBarTheme: true, ); @@ -762,7 +762,7 @@ void main() { // Regression test for: https://github.com/flutter/flutter/issues/66781 testWidgets('text in search bar contrasts background (dark mode)', (WidgetTester tester) async { - final ThemeData themeData = ThemeData.dark(); + final ThemeData themeData = ThemeData.dark(useMaterial3: false); final _TestSearchDelegate delegate = _TestSearchDelegate( defaultAppBarTheme: true, ); diff --git a/packages/flutter/test/material/selection_area_test.dart b/packages/flutter/test/material/selection_area_test.dart index 0ab44528e69..b9fb37c582d 100644 --- a/packages/flutter/test/material/selection_area_test.dart +++ b/packages/flutter/test/material/selection_area_test.dart @@ -167,6 +167,7 @@ void main() { // Regression test for https://github.com/flutter/flutter/issues/119314 await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Padding( padding: const EdgeInsets.only(top: 64), diff --git a/packages/flutter/test/material/slider_test.dart b/packages/flutter/test/material/slider_test.dart index 582f566f0a8..f50c34cf017 100644 --- a/packages/flutter/test/material/slider_test.dart +++ b/packages/flutter/test/material/slider_test.dart @@ -829,6 +829,7 @@ void main() { ShowValueIndicator show = ShowValueIndicator.onlyForDiscrete, }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Directionality( textDirection: TextDirection.ltr, child: StatefulBuilder( @@ -2670,6 +2671,7 @@ void main() { bool enabled = true, }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Builder( // The builder is used to pass the context from the MaterialApp widget @@ -3638,10 +3640,11 @@ void main() { testWidgets('Slider can be hovered and has correct hover color', (WidgetTester tester) async { tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; - final ThemeData theme = ThemeData(); + final ThemeData theme = ThemeData(useMaterial3: false); double value = 0.5; Widget buildApp({bool enabled = true}) { return MaterialApp( + theme: theme, home: Material( child: Center( child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) { diff --git a/packages/flutter/test/material/slider_theme_test.dart b/packages/flutter/test/material/slider_theme_test.dart index dd0f00d7633..4f3a41e1f9f 100644 --- a/packages/flutter/test/material/slider_theme_test.dart +++ b/packages/flutter/test/material/slider_theme_test.dart @@ -242,6 +242,7 @@ void main() { const Color customColor2 = Color(0xdeadbeef); const Color customColor3 = Color(0xdecaface); final ThemeData theme = ThemeData( + useMaterial3: false, platform: TargetPlatform.android, primarySwatch: Colors.blue, sliderTheme: const SliderThemeData( @@ -276,6 +277,7 @@ void main() { value = d; }; return MaterialApp( + theme: theme, home: Directionality( textDirection: TextDirection.ltr, child: Material( @@ -894,6 +896,7 @@ void main() { debugDisableShadows = false; try { final ThemeData theme = ThemeData( + useMaterial3: false, platform: TargetPlatform.android, primarySwatch: Colors.blue, ); @@ -904,6 +907,7 @@ void main() { ); Widget buildApp(String value, { double sliderValue = 0.5, double textScale = 1.0 }) { return MaterialApp( + theme: theme, home: Directionality( textDirection: TextDirection.ltr, child: MediaQuery( @@ -1076,6 +1080,7 @@ void main() { debugDisableShadows = false; try { final ThemeData theme = ThemeData( + useMaterial3: false, platform: TargetPlatform.android, primarySwatch: Colors.blue, ); @@ -1086,6 +1091,7 @@ void main() { ); Widget buildApp(String value, { double sliderValue = 0.5, double textScale = 1.0 }) { return MaterialApp( + theme: theme, home: Directionality( textDirection: TextDirection.ltr, child: MediaQuery( @@ -2081,7 +2087,7 @@ void main() { testWidgets('Slider defaults', (WidgetTester tester) async { debugDisableShadows = false; - final ThemeData theme = ThemeData(); + final ThemeData theme = ThemeData(useMaterial3: false); const double trackHeight = 4.0; final ColorScheme colorScheme = theme.colorScheme; final Color activeTrackColor = Color(colorScheme.primary.value); @@ -2111,6 +2117,7 @@ void main() { value = d; }; return MaterialApp( + theme: theme, home: Directionality( textDirection: TextDirection.ltr, child: Material( @@ -2232,6 +2239,7 @@ void main() { debugDisableShadows = false; try { final ThemeData theme = ThemeData( + useMaterial3: false, platform: TargetPlatform.android, ); Widget buildApp(String value, { double sliderValue = 0.5, double textScale = 1.0 }) { diff --git a/packages/flutter/test/material/snack_bar_test.dart b/packages/flutter/test/material/snack_bar_test.dart index 50dec4950a5..23497a23afc 100644 --- a/packages/flutter/test/material/snack_bar_test.dart +++ b/packages/flutter/test/material/snack_bar_test.dart @@ -302,7 +302,7 @@ void main() { }); testWidgets('Light theme SnackBar has dark background', (WidgetTester tester) async { - final ThemeData lightTheme = ThemeData.light(); + final ThemeData lightTheme = ThemeData.light(useMaterial3: false); await tester.pumpWidget( MaterialApp( theme: lightTheme, @@ -383,7 +383,7 @@ void main() { }); testWidgets('Dark theme SnackBar has primary text buttons', (WidgetTester tester) async { - final ThemeData darkTheme = ThemeData.dark(); + final ThemeData darkTheme = ThemeData.dark(useMaterial3: false); await tester.pumpWidget( MaterialApp( theme: darkTheme, @@ -961,6 +961,7 @@ void main() { testWidgets('SnackBar button text alignment', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: MediaQuery( data: const MediaQueryData( padding: EdgeInsets.only( @@ -1010,6 +1011,7 @@ void main() { 'Custom padding between SnackBar and its contents when set to SnackBarBehavior.fixed', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: MediaQuery( data: const MediaQueryData( padding: EdgeInsets.only( @@ -1120,6 +1122,7 @@ void main() { testWidgets('Floating SnackBar button text alignment', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( theme: ThemeData( + useMaterial3: false, snackBarTheme: const SnackBarThemeData(behavior: SnackBarBehavior.floating), ), home: MediaQuery( @@ -1172,6 +1175,7 @@ void main() { (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( theme: ThemeData( + useMaterial3: false, snackBarTheme: const SnackBarThemeData(behavior: SnackBarBehavior.floating), ), home: MediaQuery( @@ -1902,8 +1906,9 @@ void main() { testWidgets('Snackbar with SnackBarBehavior.floating will assert when offset too high by a large Scaffold.persistentFooterButtons', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/84263 await tester.pumpWidget( - const MaterialApp( - home: Scaffold( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Scaffold( persistentFooterButtons: [SizedBox(height: 1000)], ), ), @@ -1917,8 +1922,9 @@ void main() { testWidgets('Snackbar with SnackBarBehavior.floating will assert when offset too high by a large Scaffold.bottomNavigationBar', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/84263 await tester.pumpWidget( - const MaterialApp( - home: Scaffold( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Scaffold( bottomNavigationBar: SizedBox(height: 1000), ), ), diff --git a/packages/flutter/test/material/tabs_test.dart b/packages/flutter/test/material/tabs_test.dart index e405a887a95..c2194170fe0 100644 --- a/packages/flutter/test/material/tabs_test.dart +++ b/packages/flutter/test/material/tabs_test.dart @@ -13,17 +13,20 @@ import '../rendering/recording_canvas.dart'; import '../widgets/semantics_tester.dart'; import 'feedback_tester.dart'; -Widget boilerplate({ Widget? child, TextDirection textDirection = TextDirection.ltr }) { - return Localizations( - locale: const Locale('en', 'US'), - delegates: const >[ - DefaultMaterialLocalizations.delegate, - DefaultWidgetsLocalizations.delegate, - ], - child: Directionality( - textDirection: textDirection, - child: Material( - child: child, +Widget boilerplate({ Widget? child, TextDirection textDirection = TextDirection.ltr, bool? useMaterial3, TabBarTheme? tabBarTheme }) { + return Theme( + data: ThemeData(useMaterial3: useMaterial3, tabBarTheme: tabBarTheme), + child: Localizations( + locale: const Locale('en', 'US'), + delegates: const >[ + DefaultMaterialLocalizations.delegate, + DefaultWidgetsLocalizations.delegate, + ], + child: Directionality( + textDirection: textDirection, + child: Material( + child: child, + ), ), ), ); @@ -115,9 +118,13 @@ Widget buildFrame({ EdgeInsetsGeometry? padding, TextDirection textDirection = TextDirection.ltr, TabAlignment? tabAlignment, + TabBarTheme? tabBarTheme, + bool? useMaterial3, }) { if (secondaryTabBar) { return boilerplate( + useMaterial3: useMaterial3, + tabBarTheme: tabBarTheme, textDirection: textDirection, child: DefaultTabController( animationDuration: animationDuration, @@ -136,6 +143,8 @@ Widget buildFrame({ } return boilerplate( + useMaterial3: useMaterial3, + tabBarTheme: tabBarTheme, textDirection: textDirection, child: DefaultTabController( animationDuration: animationDuration, @@ -196,9 +205,9 @@ class TabControllerFrameState extends State with SingleTicke } } -Widget buildLeftRightApp({required List tabs, required String value, bool automaticIndicatorColorAdjustment = true}) { +Widget buildLeftRightApp({required List tabs, required String value, bool automaticIndicatorColorAdjustment = true, ThemeData? themeData}) { return MaterialApp( - theme: ThemeData(platform: TargetPlatform.android), + theme: themeData ?? ThemeData(platform: TargetPlatform.android), home: DefaultTabController( initialIndex: tabs.indexOf(value), length: tabs.length, @@ -313,19 +322,23 @@ void main() { }); testWidgets('Tab sizing - text', (WidgetTester tester) async { + final ThemeData theme = ThemeData(fontFamily: 'FlutterTest'); + final bool material3 = theme.useMaterial3; await tester.pumpWidget( - MaterialApp(theme: ThemeData(fontFamily: 'FlutterTest'), home: const Center(child: Material(child: Tab(text: 'x')))), + MaterialApp(theme: theme, home: const Center(child: Material(child: Tab(text: 'x')))), ); expect(tester.renderObject(find.byType(RichText)).text.style!.fontFamily, 'FlutterTest'); - expect(tester.getSize(find.byType(Tab)), const Size(14.0, 46.0)); + expect(tester.getSize(find.byType(Tab)), material3 ? const Size(15.0, 46.0) : const Size(14.0, 46.0)); }); testWidgets('Tab sizing - icon and text', (WidgetTester tester) async { + final ThemeData theme = ThemeData(fontFamily: 'FlutterTest'); + final bool material3 = theme.useMaterial3; await tester.pumpWidget( - MaterialApp(theme: ThemeData(fontFamily: 'FlutterTest'), home: const Center(child: Material(child: Tab(icon: SizedBox(width: 10.0, height: 10.0), text: 'x')))), + MaterialApp(theme: theme, home: const Center(child: Material(child: Tab(icon: SizedBox(width: 10.0, height: 10.0), text: 'x')))), ); expect(tester.renderObject(find.byType(RichText)).text.style!.fontFamily, 'FlutterTest'); - expect(tester.getSize(find.byType(Tab)), const Size(14.0, 72.0)); + expect(tester.getSize(find.byType(Tab)), material3 ? const Size(15.0, 72.0) : const Size(14.0, 72.0)); }); testWidgets('Tab sizing - icon, iconMargin and text', (WidgetTester tester) async { @@ -353,35 +366,43 @@ void main() { }); testWidgets('Tab sizing - icon and child', (WidgetTester tester) async { + final ThemeData theme = ThemeData(fontFamily: 'FlutterTest'); + final bool material3 = theme.useMaterial3; await tester.pumpWidget( - MaterialApp(theme: ThemeData(fontFamily: 'FlutterTest'), home: const Center(child: Material(child: Tab(icon: SizedBox(width: 10.0, height: 10.0), child: Text('x'))))), + MaterialApp(theme: theme, home: const Center(child: Material(child: Tab(icon: SizedBox(width: 10.0, height: 10.0), child: Text('x'))))), ); expect(tester.renderObject(find.byType(RichText)).text.style!.fontFamily, 'FlutterTest'); - expect(tester.getSize(find.byType(Tab)), const Size(14.0, 72.0)); + expect(tester.getSize(find.byType(Tab)), material3 ? const Size(15.0, 72.0) : const Size(14.0, 72.0)); }); testWidgets('Tab color - normal', (WidgetTester tester) async { + final ThemeData theme = ThemeData(fontFamily: 'FlutterTest'); + final bool material3 = theme.useMaterial3; final Widget tabBar = TabBar(tabs: const [SizedBox.shrink()], controller: TabController(length: 1, vsync: tester)); await tester.pumpWidget( - MaterialApp(home: Material(child: tabBar)), + MaterialApp(theme: theme, home: Material(child: tabBar)), ); - expect(find.byType(TabBar), paints..line(color: Colors.blue[500])); + expect(find.byType(TabBar), paints..line(color: material3 ? theme.colorScheme.surfaceVariant : Colors.blue[500])); }); testWidgets('Tab color - match', (WidgetTester tester) async { + final ThemeData theme = ThemeData(); + final bool material3 = theme.useMaterial3; final Widget tabBar = TabBar(tabs: const [SizedBox.shrink()], controller: TabController(length: 1, vsync: tester)); await tester.pumpWidget( - MaterialApp(home: Material(color: const Color(0xff2196f3), child: tabBar)), + MaterialApp(theme: theme, home: Material(color: const Color(0xff2196f3), child: tabBar)), ); - expect(find.byType(TabBar), paints..line(color: Colors.white)); + expect(find.byType(TabBar), paints..line(color: material3 ? theme.colorScheme.surfaceVariant : Colors.white)); }); testWidgets('Tab color - transparency', (WidgetTester tester) async { + final ThemeData theme = ThemeData(); + final bool material3 = theme.useMaterial3; final Widget tabBar = TabBar(tabs: const [SizedBox.shrink()], controller: TabController(length: 1, vsync: tester)); await tester.pumpWidget( - MaterialApp(home: Material(type: MaterialType.transparency, child: tabBar)), + MaterialApp(theme: theme, home: Material(type: MaterialType.transparency, child: tabBar)), ); - expect(find.byType(TabBar), paints..line(color: Colors.blue[500])); + expect(find.byType(TabBar), paints..line(color: material3 ? theme.colorScheme.surfaceVariant : Colors.blue[500])); }); testWidgets('TabBar default selected/unselected label style (primary)', (WidgetTester tester) async { @@ -391,10 +412,7 @@ void main() { const String selectedValue = 'A'; const String unselectedValue = 'C'; await tester.pumpWidget( - Theme( - data: theme, - child: buildFrame(tabs: tabs, value: selectedValue), - ), + buildFrame(tabs: tabs, value: selectedValue, useMaterial3: theme.useMaterial3), ); expect(find.text('A'), findsOneWidget); expect(find.text('B'), findsOneWidget); @@ -420,10 +438,7 @@ void main() { const String selectedValue = 'A'; const String unselectedValue = 'C'; await tester.pumpWidget( - Theme( - data: theme, - child: buildFrame(tabs: tabs, value: selectedValue, secondaryTabBar: true), - ), + buildFrame(tabs: tabs, value: selectedValue, secondaryTabBar: true, useMaterial3: theme.useMaterial3), ); expect(find.text('A'), findsOneWidget); expect(find.text('B'), findsOneWidget); @@ -455,8 +470,8 @@ void main() { await tester.pumpWidget( MaterialApp( - theme: theme, home: boilerplate( + useMaterial3: theme.useMaterial3, child: Container( alignment: Alignment.topLeft, child: TabBar( @@ -514,8 +529,8 @@ void main() { await tester.pumpWidget( MaterialApp( - theme: theme, home: boilerplate( + useMaterial3: theme.useMaterial3, child: Container( alignment: Alignment.topLeft, child: TabBar.secondary( @@ -559,10 +574,7 @@ void main() { const String selectedValue = 'A'; const String unselectedValue = 'B'; await tester.pumpWidget( - Theme( - data: theme, - child: buildFrame(tabs: tabs, value: selectedValue), - ), + buildFrame(tabs: tabs, value: selectedValue, useMaterial3: theme.useMaterial3), ); RenderObject overlayColor() { @@ -599,10 +611,7 @@ void main() { const String selectedValue = 'A'; const String unselectedValue = 'B'; await tester.pumpWidget( - Theme( - data: theme, - child: buildFrame(tabs: tabs, value: selectedValue, secondaryTabBar: true), - ), + buildFrame(tabs: tabs, value: selectedValue, secondaryTabBar: true, useMaterial3: theme.useMaterial3), ); RenderObject overlayColor() { @@ -1548,7 +1557,7 @@ void main() { final List tabs = ['A', 'B']; const Color indicatorColor = Color(0xFFFF0000); - await tester.pumpWidget(buildFrame(tabs: tabs, value: 'A', indicatorColor: indicatorColor, animationDuration: Duration.zero)); + await tester.pumpWidget(buildFrame(useMaterial3: false, tabs: tabs, value: 'A', indicatorColor: indicatorColor, animationDuration: Duration.zero)); final RenderBox box = tester.renderObject(find.byType(TabBar)); final TabIndicatorRecordingCanvas canvas = TabIndicatorRecordingCanvas(indicatorColor); @@ -1882,7 +1891,7 @@ void main() { final List tabs = ['A', 'B']; const Color indicatorColor = Color(0xFFFF0000); - await tester.pumpWidget(buildFrame(tabs: tabs, value: 'A', indicatorColor: indicatorColor)); + await tester.pumpWidget(buildFrame(useMaterial3: false, tabs: tabs, value: 'A', indicatorColor: indicatorColor)); final RenderBox box = tester.renderObject(find.byType(TabBar)); final TabIndicatorRecordingCanvas canvas = TabIndicatorRecordingCanvas(indicatorColor); @@ -2301,6 +2310,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, child: Container( alignment: Alignment.topLeft, child: TabBar( @@ -2360,6 +2370,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, textDirection: TextDirection.rtl, child: Container( alignment: Alignment.topLeft, @@ -2421,6 +2432,7 @@ void main() { Widget buildFrame() { return boilerplate( + useMaterial3: false, child: Container( alignment: Alignment.topLeft, child: TabBar( @@ -2487,6 +2499,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, child: Container( alignment: Alignment.topLeft, child: TabBar( @@ -2556,6 +2569,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, textDirection: TextDirection.rtl, child: Container( alignment: Alignment.topLeft, @@ -2627,6 +2641,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, child: Container( alignment: Alignment.topLeft, child: TabBar( @@ -2697,6 +2712,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, textDirection: TextDirection.rtl, child: Container( alignment: Alignment.topLeft, @@ -2769,6 +2785,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, child: Container( alignment: Alignment.topLeft, child: TabBar( @@ -2847,6 +2864,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, textDirection: TextDirection.rtl, child: Container( alignment: Alignment.topLeft, @@ -3041,6 +3059,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, child: Container( alignment: Alignment.topLeft, child: TabBar( @@ -3111,6 +3130,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, child: Container( alignment: Alignment.topLeft, child: TabBar( @@ -3180,6 +3200,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, textDirection: TextDirection.rtl, child: Container( alignment: Alignment.topLeft, @@ -3242,6 +3263,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, child: Container( alignment: Alignment.topLeft, child: TabBar( @@ -3318,6 +3340,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, child: Semantics( container: true, child: TabBar( @@ -3584,6 +3607,7 @@ void main() { await tester.pumpWidget( boilerplate( + useMaterial3: false, child: Semantics( container: true, child: TabBar( @@ -3772,6 +3796,7 @@ void main() { Widget buildFrame(TabController controller) { return boilerplate( + useMaterial3: false, child: Container( alignment: Alignment.topLeft, child: TabBar( @@ -3975,23 +4000,27 @@ void main() { expect(tester.takeException(), null); }); - testWidgets('Default tab indicator color is white', (WidgetTester tester) async { + testWidgets('Default tab indicator color is white in M2 and surfaceVariant in M3', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/15958 final List tabs = ['LEFT', 'RIGHT']; - await tester.pumpWidget(buildLeftRightApp(tabs: tabs, value: 'LEFT')); + final ThemeData theme = ThemeData(platform: TargetPlatform.android); + final bool material3 = theme.useMaterial3; + await tester.pumpWidget(buildLeftRightApp(themeData: theme, tabs: tabs, value: 'LEFT')); final RenderBox tabBarBox = tester.firstRenderObject(find.byType(TabBar)); expect(tabBarBox, paints..line( - color: Colors.white, + color: material3 ? theme.colorScheme.surfaceVariant : Colors.white, )); }); testWidgets('Tab indicator color should not be adjusted when disable [automaticIndicatorColorAdjustment]', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/68077 final List tabs = ['LEFT', 'RIGHT']; - await tester.pumpWidget(buildLeftRightApp(tabs: tabs, value: 'LEFT', automaticIndicatorColorAdjustment: false)); + final ThemeData theme = ThemeData(platform: TargetPlatform.android); + final bool material3 = theme.useMaterial3; + await tester.pumpWidget(buildLeftRightApp(themeData: theme, tabs: tabs, value: 'LEFT', automaticIndicatorColorAdjustment: false)); final RenderBox tabBarBox = tester.firstRenderObject(find.byType(TabBar)); expect(tabBarBox, paints..line( - color: const Color(0xff2196f3), + color: material3 ? theme.colorScheme.surfaceVariant : const Color(0xff2196f3), )); }); @@ -4095,6 +4124,7 @@ void main() { const Color splashColor = Color(0xf00fffff); await tester.pumpWidget( boilerplate( + useMaterial3: false, child: DefaultTabController( length: 1, child: TabBar( @@ -4360,12 +4390,12 @@ void main() { testWidgets('TabBar colors labels correctly', (WidgetTester tester) async { MaterialStateColor buildMSC(Color selectedColor, Color unselectedColor) { return MaterialStateColor - .resolveWith((Set states) { - if (states.contains(MaterialState.selected)) { - return selectedColor; - } - return unselectedColor; - }); + .resolveWith((Set states) { + if (states.contains(MaterialState.selected)) { + return selectedColor; + } + return unselectedColor; + }); } final Color materialLabelColor = buildMSC(const Color(0x00000000), const Color(0x00000001)); @@ -4394,7 +4424,7 @@ void main() { labelStyle: TextStyle(color: Color(0x00000017)), unselectedLabelStyle: TextStyle(color: Color(0x00000018)), ); - + final ThemeData theme = ThemeData(useMaterial3: false); Widget buildTabBar({ bool isLabelColorMSC = false, bool isLabelColorNull = false, @@ -4411,7 +4441,7 @@ void main() { : tabBarTheme; return boilerplate( child: Theme( - data: ThemeData(tabBarTheme: effectiveTheme), + data: theme.copyWith(tabBarTheme: effectiveTheme), child: DefaultTabController( length: 2, child: TabBar( @@ -4488,8 +4518,8 @@ void main() { isUnselectedLabelColorNull: true, isTabBarThemeNull: true, )); - expect(getTab1Color(), equals(ThemeData().primaryTextTheme.bodyText1!.color!.value)); - expect(getTab2Color(), equals(ThemeData().primaryTextTheme.bodyText1!.color!.withAlpha(0xB2).value)); + expect(getTab1Color(), equals(theme.primaryTextTheme.bodyText1!.color!.value)); + expect(getTab2Color(), equals(theme.primaryTextTheme.bodyText1!.color!.withAlpha(0xB2).value)); }); testWidgets('Replacing the tabController after disposing the old one', (WidgetTester tester) async { @@ -4779,6 +4809,7 @@ void main() { Widget buildTabControllerFrame(BuildContext context, TabController controller) { tabController = controller; return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( appBar: AppBar( bottom: TabBar( @@ -5263,6 +5294,7 @@ void main() { testWidgets('Change tab bar height', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: DefaultTabController( length: 4, child: Scaffold( @@ -5775,9 +5807,7 @@ void main() { final ThemeData theme = ThemeData(useMaterial3: true); final List tabs = ['A', 'B', 'C']; - await tester.pumpWidget(Theme( - data: theme, - child: buildFrame(tabs: tabs, value: 'C')), + await tester.pumpWidget(buildFrame(tabs: tabs, value: 'C', useMaterial3: theme.useMaterial3), ); await tester.pumpAndSettle(); @@ -5828,8 +5858,7 @@ void main() { final List tabs = ['A', 'B', 'C']; await tester.pumpWidget(MaterialApp( - theme: theme, - home: buildFrame(tabs: tabs, value: 'B'), + home: buildFrame(tabs: tabs, value: 'B', useMaterial3: theme.useMaterial3), ), ); @@ -5878,8 +5907,7 @@ void main() { final List tabs = ['A', 'B', 'C']; await tester.pumpWidget(MaterialApp( - theme: theme, - home: buildFrame(tabs: tabs, value: 'B'), + home: buildFrame(tabs: tabs, value: 'B', useMaterial3: theme.useMaterial3), ), ); @@ -6025,7 +6053,7 @@ void main() { const String selectedValue = 'A'; const String unSelectedValue = 'C'; - await tester.pumpWidget(buildFrame(tabs: tabs, value: selectedValue)); + await tester.pumpWidget(buildFrame(useMaterial3: false, tabs: tabs, value: selectedValue)); expect(find.text('A'), findsOneWidget); expect(find.text('B'), findsOneWidget); expect(find.text('C'), findsOneWidget); @@ -6055,13 +6083,7 @@ void main() { const String unSelectedValue = 'C'; const Color labelColor = Color(0xff0000ff); await tester.pumpWidget( - Theme( - data: ThemeData( - tabBarTheme: const TabBarTheme(labelColor: labelColor), - useMaterial3: false, - ), - child: buildFrame(tabs: tabs, value: selectedValue), - ), + buildFrame(tabs: tabs, value: selectedValue, useMaterial3: false, tabBarTheme: const TabBarTheme(labelColor: labelColor)), ); expect(find.text('A'), findsOneWidget); expect(find.text('B'), findsOneWidget); @@ -6159,8 +6181,8 @@ void main() { await tester.pumpWidget( MaterialApp( - theme: theme, home: boilerplate( + useMaterial3: theme.useMaterial3, child: Container( alignment: Alignment.topLeft, child: TabBar( @@ -6205,8 +6227,8 @@ void main() { await tester.pumpWidget( MaterialApp( - theme: theme, home: boilerplate( + useMaterial3: theme.useMaterial3, child: Container( alignment: Alignment.topLeft, child: TabBar.secondary( diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index af2f20db2a3..687fda4c4f5 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -34,6 +34,18 @@ typedef FormatEditUpdateCallback = void Function(TextEditingValue, TextEditingVa // On web, key events in text fields are handled by the browser. const bool areKeyEventsHandledByPlatform = isBrowser; +class CupertinoLocalizationsDelegate extends LocalizationsDelegate { + @override + bool isSupported(Locale locale) => true; + + @override + Future load(Locale locale) => + DefaultCupertinoLocalizations.load(locale); + + @override + bool shouldReload(CupertinoLocalizationsDelegate old) => false; +} + class MaterialLocalizationsDelegate extends LocalizationsDelegate { @override bool isSupported(Locale locale) => true; @@ -75,6 +87,7 @@ Widget overlayWithEntry(OverlayEntry entry) { delegates: >[ WidgetsLocalizationsDelegate(), MaterialLocalizationsDelegate(), + CupertinoLocalizationsDelegate(), ], child: DefaultTextEditingShortcuts( child: Directionality( @@ -839,19 +852,22 @@ void main() { }); testWidgets('Overflow clipBehavior none golden', (WidgetTester tester) async { - final Widget widget = overlay( - child: RepaintBoundary( - key: const ValueKey(1), - child: SizedBox( - height: 200, - width: 200, - child: Center( - child: SizedBox( - // Make sure the input field is not high enough for the WidgetSpan. - height: 50, - child: TextField( - controller: OverflowWidgetTextEditingController(), - clipBehavior: Clip.none, + final Widget widget = Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: RepaintBoundary( + key: const ValueKey(1), + child: SizedBox( + height: 200, + width: 200, + child: Center( + child: SizedBox( + // Make sure the input field is not high enough for the WidgetSpan. + height: 50, + child: TextField( + controller: OverflowWidgetTextEditingController(), + clipBehavior: Clip.none, + ), ), ), ), @@ -873,13 +889,16 @@ void main() { }); testWidgets('Material cursor android golden', (WidgetTester tester) async { - final Widget widget = overlay( - child: const RepaintBoundary( - key: ValueKey(1), - child: TextField( - cursorColor: Colors.blue, - cursorWidth: 15, - cursorRadius: Radius.circular(3.0), + final Widget widget = Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: const RepaintBoundary( + key: ValueKey(1), + child: TextField( + cursorColor: Colors.blue, + cursorWidth: 15, + cursorRadius: Radius.circular(3.0), + ), ), ), ); @@ -969,8 +988,9 @@ void main() { testWidgets('text field selection toolbar renders correctly inside opacity', (WidgetTester tester) async { await tester.pumpWidget( - const MaterialApp( - home: Scaffold( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Scaffold( body: Center( child: SizedBox( width: 100, @@ -1230,12 +1250,15 @@ void main() { final FocusNode focusNode = FocusNode(); EditableText.debugDeterministicCursor = true; await tester.pumpWidget( - overlay( - child: RepaintBoundary( - child: TextField( - cursorWidth: 15.0, - controller: controller, - focusNode: focusNode, + Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: RepaintBoundary( + child: TextField( + cursorWidth: 15.0, + controller: controller, + focusNode: focusNode, + ), ), ), ), @@ -1257,13 +1280,16 @@ void main() { final FocusNode focusNode = FocusNode(); EditableText.debugDeterministicCursor = true; await tester.pumpWidget( - overlay( - child: RepaintBoundary( - child: TextField( - cursorWidth: 15.0, - cursorRadius: const Radius.circular(3.0), - controller: controller, - focusNode: focusNode, + Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: RepaintBoundary( + child: TextField( + cursorWidth: 15.0, + cursorRadius: const Radius.circular(3.0), + controller: controller, + focusNode: focusNode, + ), ), ), ), @@ -1285,13 +1311,16 @@ void main() { final FocusNode focusNode = FocusNode(); EditableText.debugDeterministicCursor = true; await tester.pumpWidget( - overlay( - child: RepaintBoundary( - child: TextField( - cursorWidth: 15.0, - cursorHeight: 30.0, - controller: controller, - focusNode: focusNode, + Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: RepaintBoundary( + child: TextField( + cursorWidth: 15.0, + cursorHeight: 30.0, + controller: controller, + focusNode: focusNode, + ), ), ), ), @@ -1310,11 +1339,14 @@ void main() { final TextEditingController controller = TextEditingController(); await tester.pumpWidget( - overlay( - child: TextField( - key: textFieldKey, - controller: controller, - maxLines: null, + Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: TextField( + key: textFieldKey, + controller: controller, + maxLines: null, + ), ), ), ); @@ -3379,12 +3411,15 @@ void main() { ); await tester.pumpWidget( - overlay( - child: TextField( - dragStartBehavior: DragStartBehavior.down, - controller: controller, - maxLines: 3, - minLines: 3, + Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: TextField( + dragStartBehavior: DragStartBehavior.down, + controller: controller, + maxLines: 3, + minLines: 3, + ), ), ), ); @@ -3861,6 +3896,7 @@ void main() { final TextEditingController controller = TextEditingController(); await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Padding( padding: const EdgeInsets.all(30.0), @@ -4410,6 +4446,7 @@ void main() { Widget? prefix, }) { return boilerplate( + theme: ThemeData(useMaterial3: false), child: SizedBox( height: height, child: TextField( @@ -4548,12 +4585,15 @@ void main() { final TextEditingController controller = TextEditingController(); await tester.pumpWidget( - overlay( - child: TextField( - dragStartBehavior: DragStartBehavior.down, - controller: controller, - style: const TextStyle(color: Colors.black, fontSize: 34.0), - maxLines: 3, + Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: TextField( + dragStartBehavior: DragStartBehavior.down, + controller: controller, + style: const TextStyle(color: Colors.black, fontSize: 34.0), + maxLines: 3, + ), ), ), ); @@ -4796,11 +4836,14 @@ void main() { testWidgets('TextField errorText trumps helperText', (WidgetTester tester) async { await tester.pumpWidget( - overlay( - child: const TextField( - decoration: InputDecoration( - errorText: 'error text', - helperText: 'helper text', + Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: const TextField( + decoration: InputDecoration( + errorText: 'error text', + helperText: 'helper text', + ), ), ), ), @@ -4810,7 +4853,7 @@ void main() { }); testWidgets('TextField with default helperStyle', (WidgetTester tester) async { - final ThemeData themeData = ThemeData(hintColor: Colors.blue[500]); + final ThemeData themeData = ThemeData(hintColor: Colors.blue[500], useMaterial3: false); await tester.pumpWidget( overlay( child: Theme( @@ -5214,12 +5257,15 @@ void main() { testWidgets('Collapsed hint text placement', (WidgetTester tester) async { await tester.pumpWidget( - overlay( - child: const TextField( - decoration: InputDecoration.collapsed( - hintText: 'hint', + Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: const TextField( + decoration: InputDecoration.collapsed( + hintText: 'hint', + ), + strutStyle: StrutStyle.disabled, ), - strutStyle: StrutStyle.disabled, ), ), ); @@ -5585,11 +5631,14 @@ void main() { final TextEditingController controller = TextEditingController(); await tester.pumpWidget( - overlay( - child: SizedBox( - width: 100.0, - child: TextField( - controller: controller, + Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: SizedBox( + width: 100.0, + child: TextField( + controller: controller, + ), ), ), ), @@ -6358,6 +6407,7 @@ void main() { const String errorText = 'error text'; Widget buildFrame(bool enabled, bool hasError) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField( @@ -6405,6 +6455,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField( @@ -7251,40 +7302,43 @@ void main() { final Key keyB = UniqueKey(); await tester.pumpWidget( - overlay( - child: Row( - crossAxisAlignment: CrossAxisAlignment.baseline, - textBaseline: TextBaseline.alphabetic, - children: [ - Expanded( - child: TextField( - key: keyA, - decoration: null, - controller: controllerA, + Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: Row( + crossAxisAlignment: CrossAxisAlignment.baseline, + textBaseline: TextBaseline.alphabetic, + children: [ + Expanded( + child: TextField( + key: keyA, + decoration: null, + controller: controllerA, + // The point size of the font must be a multiple of 4 until + // https://github.com/flutter/flutter/issues/122066 is resolved. + style: const TextStyle(fontFamily: 'FlutterTest', fontSize: 12.0), + strutStyle: StrutStyle.disabled, + ), + ), + const Text( + 'abc', // The point size of the font must be a multiple of 4 until // https://github.com/flutter/flutter/issues/122066 is resolved. - style: const TextStyle(fontFamily: 'FlutterTest', fontSize: 12.0), - strutStyle: StrutStyle.disabled, + style: TextStyle(fontFamily: 'FlutterTest', fontSize: 24.0), ), - ), - const Text( - 'abc', - // The point size of the font must be a multiple of 4 until - // https://github.com/flutter/flutter/issues/122066 is resolved. - style: TextStyle(fontFamily: 'FlutterTest', fontSize: 24.0), - ), - Expanded( - child: TextField( - key: keyB, - decoration: null, - controller: controllerB, - // The point size of the font must be a multiple of 4 until - // https://github.com/flutter/flutter/issues/122066 is resolved. - style: const TextStyle(fontFamily: 'FlutterTest', fontSize: 36.0), - strutStyle: StrutStyle.disabled, + Expanded( + child: TextField( + key: keyB, + decoration: null, + controller: controllerB, + // The point size of the font must be a multiple of 4 until + // https://github.com/flutter/flutter/issues/122066 is resolved. + style: const TextStyle(fontFamily: 'FlutterTest', fontSize: 36.0), + strutStyle: StrutStyle.disabled, + ), ), - ), - ], + ], + ), ), ), ); @@ -7310,38 +7364,41 @@ void main() { final Key keyB = UniqueKey(); await tester.pumpWidget( - overlay( - child: Row( - crossAxisAlignment: CrossAxisAlignment.baseline, - textBaseline: TextBaseline.alphabetic, - children: [ - Expanded( - child: TextField( - key: keyA, - decoration: null, - controller: controllerA, + Theme( + data: ThemeData(useMaterial3: false), + child: overlay( + child: Row( + crossAxisAlignment: CrossAxisAlignment.baseline, + textBaseline: TextBaseline.alphabetic, + children: [ + Expanded( + child: TextField( + key: keyA, + decoration: null, + controller: controllerA, + // The point size of the font must be a multiple of 4 until + // https://github.com/flutter/flutter/issues/122066 is resolved. + style: const TextStyle(fontFamily: 'FlutterTest', fontSize: 12.0), + ), + ), + const Text( + 'abc', // The point size of the font must be a multiple of 4 until // https://github.com/flutter/flutter/issues/122066 is resolved. - style: const TextStyle(fontFamily: 'FlutterTest', fontSize: 12.0), + style: TextStyle(fontFamily: 'FlutterTest', fontSize: 24.0), ), - ), - const Text( - 'abc', - // The point size of the font must be a multiple of 4 until - // https://github.com/flutter/flutter/issues/122066 is resolved. - style: TextStyle(fontFamily: 'FlutterTest', fontSize: 24.0), - ), - Expanded( - child: TextField( - key: keyB, - decoration: null, - controller: controllerB, - // The point size of the font must be a multiple of 4 until - // https://github.com/flutter/flutter/issues/122066 is resolved. - style: const TextStyle(fontFamily: 'FlutterTest', fontSize: 36.0), + Expanded( + child: TextField( + key: keyB, + decoration: null, + controller: controllerB, + // The point size of the font must be a multiple of 4 until + // https://github.com/flutter/flutter/issues/122066 is resolved. + style: const TextStyle(fontFamily: 'FlutterTest', fontSize: 36.0), + ), ), - ), - ], + ], + ), ), ), ); @@ -8138,8 +8195,9 @@ void main() { testWidgets('TextField displays text with text direction', (WidgetTester tester) async { await tester.pumpWidget( - const MaterialApp( - home: Material( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Material( child: TextField( textDirection: TextDirection.rtl, ), @@ -8158,8 +8216,9 @@ void main() { expect(topLeft.dx, equals(701)); await tester.pumpWidget( - const MaterialApp( - home: Material( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: const Material( child: TextField( textDirection: TextDirection.ltr, ), @@ -8366,6 +8425,7 @@ void main() { final TextEditingController controller = TextEditingController(text: 'Just some text'); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: MediaQuery( data: const MediaQueryData(textScaleFactor: 4.0), @@ -8582,6 +8642,7 @@ void main() { required TextAlign textAlign, }) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Center( child: Column( @@ -8652,6 +8713,7 @@ void main() { // Regression test for https://github.com/flutter/flutter/issues/23994 final ThemeData themeData = ThemeData( + useMaterial3: false, textTheme: TextTheme( titleMedium: TextStyle( color: Colors.blue[500], @@ -9471,6 +9533,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: TextField( dragStartBehavior: DragStartBehavior.down, @@ -9583,6 +9646,7 @@ void main() { ); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField( @@ -9673,6 +9737,7 @@ void main() { ); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField( @@ -10185,6 +10250,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: TextField( dragStartBehavior: DragStartBehavior.down, @@ -10285,6 +10351,7 @@ void main() { await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: TextField( dragStartBehavior: DragStartBehavior.down, @@ -11418,6 +11485,7 @@ void main() { ); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField( @@ -11506,6 +11574,7 @@ void main() { ); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField( @@ -11594,6 +11663,7 @@ void main() { ); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField( @@ -11759,6 +11829,7 @@ void main() { ); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField( @@ -12119,6 +12190,7 @@ void main() { final bool isTargetPlatformMobile = defaultTargetPlatform == TargetPlatform.iOS; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField( @@ -12232,6 +12304,7 @@ void main() { ); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField( @@ -12878,7 +12951,7 @@ void main() { (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData(platform: TargetPlatform.android), + theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false), home: const Material( child: Center( child: TextField( @@ -12923,7 +12996,7 @@ void main() { (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData(platform: TargetPlatform.android), + theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false), home: const Material( child: Center( child: TextField( @@ -12947,7 +13020,7 @@ void main() { (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData(platform: TargetPlatform.android), + theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false), home: const Material( child: Center( child: TextField( @@ -12978,7 +13051,7 @@ void main() { (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData(platform: TargetPlatform.android), + theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false), home: const Material( child: Center( child: TextField( @@ -13007,7 +13080,7 @@ void main() { (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData(platform: TargetPlatform.android), + theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false), home: const Material( child: Center( child: TextField( @@ -13036,7 +13109,7 @@ void main() { (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( - theme: ThemeData(platform: TargetPlatform.android), + theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false), home: const Material( child: Center( child: TextField( @@ -13065,11 +13138,14 @@ void main() { testWidgets('Caret center position', (WidgetTester tester) async { await tester.pumpWidget( overlay( - child: const SizedBox( - width: 300.0, - child: TextField( - textAlign: TextAlign.center, - decoration: null, + child: Theme( + data: ThemeData(useMaterial3: false), + child: const SizedBox( + width: 300.0, + child: TextField( + textAlign: TextAlign.center, + decoration: null, + ), ), ), ), @@ -13105,11 +13181,14 @@ void main() { testWidgets('Caret indexes into trailing whitespace center align', (WidgetTester tester) async { await tester.pumpWidget( overlay( - child: const SizedBox( - width: 300.0, - child: TextField( - textAlign: TextAlign.center, - decoration: null, + child: Theme( + data: ThemeData(useMaterial3: false), + child: const SizedBox( + width: 300.0, + child: TextField( + textAlign: TextAlign.center, + decoration: null, + ), ), ), ), @@ -13573,7 +13652,7 @@ void main() { final ScrollController scrollController = ScrollController(); await tester.pumpWidget(MaterialApp( - theme: ThemeData(), + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Center( child: ListView( @@ -13604,7 +13683,7 @@ void main() { final ScrollController textFieldScrollController = ScrollController(); await tester.pumpWidget(MaterialApp( - theme: ThemeData(), + theme: ThemeData(useMaterial3: false), home: Scaffold( body: Center( child: ListView( @@ -14291,6 +14370,7 @@ void main() { Widget textFieldBuilder({ FloatingLabelBehavior behavior = FloatingLabelBehavior.auto }) { return MaterialApp( theme: ThemeData( + useMaterial3: false, inputDecorationTheme: InputDecorationTheme( floatingLabelBehavior: behavior, ), @@ -14872,6 +14952,7 @@ void main() { final bool isTargetPlatformMobile = defaultTargetPlatform == TargetPlatform.iOS; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField(controller: controller), @@ -14977,6 +15058,7 @@ void main() { || defaultTargetPlatform == TargetPlatform.fuchsia; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField(controller: controller), @@ -15083,6 +15165,7 @@ void main() { final bool isTargetPlatformMobile = defaultTargetPlatform == TargetPlatform.iOS; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField(controller: controller), @@ -15187,6 +15270,7 @@ void main() { || defaultTargetPlatform == TargetPlatform.fuchsia; await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextField(controller: controller), diff --git a/packages/flutter/test/material/text_form_field_test.dart b/packages/flutter/test/material/text_form_field_test.dart index afcaedbffdb..b46266268ce 100644 --- a/packages/flutter/test/material/text_form_field_test.dart +++ b/packages/flutter/test/material/text_form_field_test.dart @@ -591,12 +591,13 @@ void main() { }); - testWidgets('Disabled field hides helper and counter', (WidgetTester tester) async { + testWidgets('Disabled field hides helper and counter in M2', (WidgetTester tester) async { const String helperText = 'helper text'; const String counterText = 'counter text'; const String errorText = 'error text'; Widget buildFrame(bool enabled, bool hasError) { return MaterialApp( + theme: ThemeData(useMaterial3: false), home: Material( child: Center( child: TextFormField( diff --git a/packages/flutter/test/material/text_selection_test.dart b/packages/flutter/test/material/text_selection_test.dart index 91ef755b31a..37c22e7ecbf 100644 --- a/packages/flutter/test/material/text_selection_test.dart +++ b/packages/flutter/test/material/text_selection_test.dart @@ -376,7 +376,7 @@ void main() { final TextEditingController controller = TextEditingController(text: 'abc def ghi'); await tester.pumpWidget(MaterialApp( - theme: ThemeData(platform: TargetPlatform.android), + theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false), home: Directionality( textDirection: TextDirection.ltr, child: MediaQuery( diff --git a/packages/flutter/test/material/theme_data_test.dart b/packages/flutter/test/material/theme_data_test.dart index ce77262ad0d..a69ff727cf2 100644 --- a/packages/flutter/test/material/theme_data_test.dart +++ b/packages/flutter/test/material/theme_data_test.dart @@ -23,7 +23,7 @@ void main() { test('Defaults to the default typography for the platform', () { for (final TargetPlatform platform in TargetPlatform.values) { - final ThemeData theme = ThemeData(platform: platform); + final ThemeData theme = ThemeData(platform: platform, useMaterial3: false); final Typography typography = Typography.material2018(platform: platform); expect( theme.textTheme, @@ -34,8 +34,8 @@ void main() { }); test('Default text theme contrasts with brightness', () { - final ThemeData lightTheme = ThemeData(brightness: Brightness.light); - final ThemeData darkTheme = ThemeData(brightness: Brightness.dark); + final ThemeData lightTheme = ThemeData(brightness: Brightness.light, useMaterial3: false); + final ThemeData darkTheme = ThemeData(brightness: Brightness.dark, useMaterial3: false); final Typography typography = Typography.material2018(platform: lightTheme.platform); expect(lightTheme.textTheme.titleLarge!.color, typography.black.titleLarge!.color); @@ -43,8 +43,8 @@ void main() { }); test('Default primary text theme contrasts with primary brightness', () { - final ThemeData lightTheme = ThemeData(primaryColor: Colors.white); - final ThemeData darkTheme = ThemeData(primaryColor: Colors.black); + final ThemeData lightTheme = ThemeData(primaryColor: Colors.white, useMaterial3: false); + final ThemeData darkTheme = ThemeData(primaryColor: Colors.black, useMaterial3: false); final Typography typography = Typography.material2018(platform: lightTheme.platform); expect(lightTheme.primaryTextTheme.titleLarge!.color, typography.black.titleLarge!.color); @@ -52,8 +52,8 @@ void main() { }); test('Default icon theme contrasts with brightness', () { - final ThemeData lightTheme = ThemeData(brightness: Brightness.light); - final ThemeData darkTheme = ThemeData(brightness: Brightness.dark); + final ThemeData lightTheme = ThemeData(brightness: Brightness.light, useMaterial3: false); + final ThemeData darkTheme = ThemeData(brightness: Brightness.dark, useMaterial3: false); final Typography typography = Typography.material2018(platform: lightTheme.platform); expect(lightTheme.textTheme.titleLarge!.color, typography.black.titleLarge!.color); @@ -61,8 +61,8 @@ void main() { }); test('Default primary icon theme contrasts with primary brightness', () { - final ThemeData lightTheme = ThemeData(primaryColor: Colors.white); - final ThemeData darkTheme = ThemeData(primaryColor: Colors.black); + final ThemeData lightTheme = ThemeData(primaryColor: Colors.white, useMaterial3: false); + final ThemeData darkTheme = ThemeData(primaryColor: Colors.black, useMaterial3: false); final Typography typography = Typography.material2018(platform: lightTheme.platform); expect(lightTheme.primaryTextTheme.titleLarge!.color, typography.black.titleLarge!.color); diff --git a/packages/flutter/test/material/tooltip_test.dart b/packages/flutter/test/material/tooltip_test.dart index 009f9a0cdbc..f46cef7f560 100644 --- a/packages/flutter/test/material/tooltip_test.dart +++ b/packages/flutter/test/material/tooltip_test.dart @@ -142,32 +142,35 @@ void main() { testWidgetsWithLeakTracking('Does tooltip end up in the right place - top left', (WidgetTester tester) async { final GlobalKey tooltipKey = GlobalKey(); await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Overlay( - initialEntries: [ - OverlayEntry( - builder: (BuildContext context) { - return Stack( - children: [ - Positioned( - left: 0.0, - top: 0.0, - child: Tooltip( - key: tooltipKey, - message: tooltipText, - height: 20.0, - padding: const EdgeInsets.all(5.0), - verticalOffset: 20.0, - preferBelow: false, - child: const SizedBox.shrink(), + Theme( + data: ThemeData(useMaterial3: false), + child: Directionality( + textDirection: TextDirection.ltr, + child: Overlay( + initialEntries: [ + OverlayEntry( + builder: (BuildContext context) { + return Stack( + children: [ + Positioned( + left: 0.0, + top: 0.0, + child: Tooltip( + key: tooltipKey, + message: tooltipText, + height: 20.0, + padding: const EdgeInsets.all(5.0), + verticalOffset: 20.0, + preferBelow: false, + child: const SizedBox.shrink(), + ), ), - ), - ], - ); - }, - ), - ], + ], + ); + }, + ), + ], + ), ), ), ); @@ -362,32 +365,35 @@ void main() { testWidgetsWithLeakTracking('Does tooltip end up in the right place - way off to the right', (WidgetTester tester) async { final GlobalKey tooltipKey = GlobalKey(); await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Overlay( - initialEntries: [ - OverlayEntry( - builder: (BuildContext context) { - return Stack( - children: [ - Positioned( - left: 1600.0, - top: 300.0, - child: Tooltip( - key: tooltipKey, - message: tooltipText, - height: 10.0, - padding: EdgeInsets.zero, - verticalOffset: 10.0, - preferBelow: true, - child: const SizedBox.shrink(), + Theme( + data: ThemeData(useMaterial3: false), + child: Directionality( + textDirection: TextDirection.ltr, + child: Overlay( + initialEntries: [ + OverlayEntry( + builder: (BuildContext context) { + return Stack( + children: [ + Positioned( + left: 1600.0, + top: 300.0, + child: Tooltip( + key: tooltipKey, + message: tooltipText, + height: 10.0, + padding: EdgeInsets.zero, + verticalOffset: 10.0, + preferBelow: true, + child: const SizedBox.shrink(), + ), ), - ), - ], - ); - }, - ), - ], + ], + ); + }, + ), + ], + ), ), ), ); @@ -416,32 +422,35 @@ void main() { testWidgetsWithLeakTracking('Does tooltip end up in the right place - near the edge', (WidgetTester tester) async { final GlobalKey tooltipKey = GlobalKey(); await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Overlay( - initialEntries: [ - OverlayEntry( - builder: (BuildContext context) { - return Stack( - children: [ - Positioned( - left: 780.0, - top: 300.0, - child: Tooltip( - key: tooltipKey, - message: tooltipText, - height: 10.0, - padding: EdgeInsets.zero, - verticalOffset: 10.0, - preferBelow: true, - child: const SizedBox.shrink(), + Theme( + data: ThemeData(useMaterial3: false), + child: Directionality( + textDirection: TextDirection.ltr, + child: Overlay( + initialEntries: [ + OverlayEntry( + builder: (BuildContext context) { + return Stack( + children: [ + Positioned( + left: 780.0, + top: 300.0, + child: Tooltip( + key: tooltipKey, + message: tooltipText, + height: 10.0, + padding: EdgeInsets.zero, + verticalOffset: 10.0, + preferBelow: true, + child: const SizedBox.shrink(), + ), ), - ), - ], - ); - }, - ), - ], + ], + ); + }, + ), + ], + ), ), ), ); @@ -580,6 +589,7 @@ void main() { testWidgetsWithLeakTracking('Default tooltip message textStyle - light', (WidgetTester tester) async { final GlobalKey tooltipKey = GlobalKey(); await tester.pumpWidget(MaterialApp( + theme: ThemeData(useMaterial3: false), home: Tooltip( key: tooltipKey, message: tooltipText, @@ -604,6 +614,7 @@ void main() { final GlobalKey tooltipKey = GlobalKey(); await tester.pumpWidget(MaterialApp( theme: ThemeData( + useMaterial3: false, brightness: Brightness.dark, ), home: Tooltip( @@ -760,20 +771,23 @@ void main() { testWidgetsWithLeakTracking('Does tooltip end up with the right default size, shape, and color', (WidgetTester tester) async { final GlobalKey tooltipKey = GlobalKey(); await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Overlay( - initialEntries: [ - OverlayEntry( - builder: (BuildContext context) { - return Tooltip( - key: tooltipKey, - message: tooltipText, - child: const SizedBox.shrink(), - ); - }, - ), - ], + Theme( + data: ThemeData(useMaterial3: false), + child: Directionality( + textDirection: TextDirection.ltr, + child: Overlay( + initialEntries: [ + OverlayEntry( + builder: (BuildContext context) { + return Tooltip( + key: tooltipKey, + message: tooltipText, + child: const SizedBox.shrink(), + ); + }, + ), + ], + ), ), ), ); @@ -797,6 +811,7 @@ void main() { final GlobalKey tooltipKey = GlobalKey(); await tester.pumpWidget( MaterialApp( + theme: ThemeData(useMaterial3: false), home: Tooltip( key: tooltipKey, message: tooltipText, @@ -828,21 +843,24 @@ void main() { color: Color(0x80800000), ); await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: Overlay( - initialEntries: [ - OverlayEntry( - builder: (BuildContext context) { - return Tooltip( - key: tooltipKey, - decoration: customDecoration, - message: tooltipText, - child: const SizedBox.shrink(), - ); - }, - ), - ], + Theme( + data: ThemeData(useMaterial3: false), + child: Directionality( + textDirection: TextDirection.ltr, + child: Overlay( + initialEntries: [ + OverlayEntry( + builder: (BuildContext context) { + return Tooltip( + key: tooltipKey, + decoration: customDecoration, + message: tooltipText, + child: const SizedBox.shrink(), + ); + }, + ), + ], + ), ), ), ); @@ -1431,27 +1449,30 @@ void main() { testWidgetsWithLeakTracking('Tooltip text scales with textScaleFactor', (WidgetTester tester) async { Widget buildApp(String text, { required double textScaleFactor }) { - return MediaQuery( - data: MediaQueryData(textScaleFactor: textScaleFactor), - child: Directionality( - textDirection: TextDirection.ltr, - child: Navigator( - onGenerateRoute: (RouteSettings settings) { - return MaterialPageRoute( - builder: (BuildContext context) { - return Center( - child: Tooltip( - message: text, - child: Container( - width: 100.0, - height: 100.0, - color: Colors.green[500], + return Theme( + data: ThemeData(useMaterial3: false), + child: MediaQuery( + data: MediaQueryData(textScaleFactor: textScaleFactor), + child: Directionality( + textDirection: TextDirection.ltr, + child: Navigator( + onGenerateRoute: (RouteSettings settings) { + return MaterialPageRoute( + builder: (BuildContext context) { + return Center( + child: Tooltip( + message: text, + child: Container( + width: 100.0, + height: 100.0, + color: Colors.green[500], + ), ), - ), - ); - }, - ); - }, + ); + }, + ); + }, + ), ), ), ); diff --git a/packages/flutter/test/material/tooltip_theme_test.dart b/packages/flutter/test/material/tooltip_theme_test.dart index b163d524f2d..c658dd55b5d 100644 --- a/packages/flutter/test/material/tooltip_theme_test.dart +++ b/packages/flutter/test/material/tooltip_theme_test.dart @@ -686,6 +686,7 @@ void main() { textDirection: TextDirection.ltr, child: Theme( data: ThemeData( + useMaterial3: false, tooltipTheme: const TooltipThemeData( decoration: customDecoration, ), @@ -723,22 +724,25 @@ void main() { color: Color(0x80800000), ); await tester.pumpWidget( - Directionality( - textDirection: TextDirection.ltr, - child: TooltipTheme( - data: const TooltipThemeData(decoration: customDecoration), - child: Overlay( - initialEntries: [ - OverlayEntry( - builder: (BuildContext context) { - return Tooltip( - key: key, - message: tooltipText, - child: const SizedBox.shrink(), - ); - }, - ), - ], + Theme( + data: ThemeData(useMaterial3: false), + child: Directionality( + textDirection: TextDirection.ltr, + child: TooltipTheme( + data: const TooltipThemeData(decoration: customDecoration), + child: Overlay( + initialEntries: [ + OverlayEntry( + builder: (BuildContext context) { + return Tooltip( + key: key, + message: tooltipText, + child: const SizedBox.shrink(), + ); + }, + ), + ], + ), ), ), ),