diff --git a/analysis_options.yaml b/analysis_options.yaml index 5eb60fd68f..05b4cf1b51 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -87,7 +87,7 @@ linter: - avoid_type_to_string - avoid_types_as_parameter_names # - avoid_types_on_closure_parameters # conflicts with always_specify_types - # - avoid_unnecessary_containers # not yet tested + - avoid_unnecessary_containers - avoid_unused_constructor_parameters - avoid_void_async # - avoid_web_libraries_in_flutter # not yet tested diff --git a/dev/benchmarks/complex_layout/lib/main.dart b/dev/benchmarks/complex_layout/lib/main.dart index 7d3662ac2e..0f1fcdbc8c 100644 --- a/dev/benchmarks/complex_layout/lib/main.dart +++ b/dev/benchmarks/complex_layout/lib/main.dart @@ -551,9 +551,7 @@ class ItemGalleryBox extends StatelessWidget { }).toList(), ), ), - Container( - child: const TabPageSelector(), - ), + const TabPageSelector(), ], ), ), diff --git a/dev/benchmarks/macrobenchmarks/lib/src/fullscreen_textfield.dart b/dev/benchmarks/macrobenchmarks/lib/src/fullscreen_textfield.dart index 3044a2d35c..733604c198 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/fullscreen_textfield.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/fullscreen_textfield.dart @@ -53,12 +53,10 @@ class TextFieldPage extends StatelessWidget { @override Widget build(BuildContext context) { return Material( - child: Container( - child: TextField( - maxLines: null, - controller: TextEditingController(text: textLotsOfText), - key: const Key('fullscreen-textfield'), - ), + child: TextField( + maxLines: null, + controller: TextEditingController(text: textLotsOfText), + key: const Key('fullscreen-textfield'), ), ); } diff --git a/dev/integration_tests/flutter_gallery/lib/demo/material/modal_bottom_sheet_demo.dart b/dev/integration_tests/flutter_gallery/lib/demo/material/modal_bottom_sheet_demo.dart index f79ee8a139..016b725de9 100644 --- a/dev/integration_tests/flutter_gallery/lib/demo/material/modal_bottom_sheet_demo.dart +++ b/dev/integration_tests/flutter_gallery/lib/demo/material/modal_bottom_sheet_demo.dart @@ -23,15 +23,13 @@ class ModalBottomSheetDemo extends StatelessWidget { child: const Text('SHOW BOTTOM SHEET'), onPressed: () { showModalBottomSheet(context: context, builder: (BuildContext context) { - return Container( - child: Padding( - padding: const EdgeInsets.all(32.0), - child: Text('This is the modal bottom sheet. Slide down to dismiss.', - textAlign: TextAlign.center, - style: TextStyle( - color: Theme.of(context).accentColor, - fontSize: 24.0, - ), + return Padding( + padding: const EdgeInsets.all(32.0), + child: Text('This is the modal bottom sheet. Slide down to dismiss.', + textAlign: TextAlign.center, + style: TextStyle( + color: Theme.of(context).accentColor, + fontSize: 24.0, ), ), ); diff --git a/dev/integration_tests/flutter_gallery/lib/demo/shrine/expanding_bottom_sheet.dart b/dev/integration_tests/flutter_gallery/lib/demo/shrine/expanding_bottom_sheet.dart index 70d5551156..29894b9e5d 100644 --- a/dev/integration_tests/flutter_gallery/lib/demo/shrine/expanding_bottom_sheet.dart +++ b/dev/integration_tests/flutter_gallery/lib/demo/shrine/expanding_bottom_sheet.dart @@ -541,11 +541,9 @@ class ExtraProductsNumber extends StatelessWidget { final int numOverflowProducts = _calculateOverflow(model); // Maximum of 99 so padding doesn't get messy. final int displayedOverflowProducts = numOverflowProducts <= 99 ? numOverflowProducts : 99; - return Container( - child: Text( - '+$displayedOverflowProducts', - style: Theme.of(context).primaryTextTheme.button, - ), + return Text( + '+$displayedOverflowProducts', + style: Theme.of(context).primaryTextTheme.button, ); } diff --git a/dev/integration_tests/flutter_gallery/lib/demo/shrine/shopping_cart.dart b/dev/integration_tests/flutter_gallery/lib/demo/shrine/shopping_cart.dart index 1375c4084d..ab3d818286 100644 --- a/dev/integration_tests/flutter_gallery/lib/demo/shrine/shopping_cart.dart +++ b/dev/integration_tests/flutter_gallery/lib/demo/shrine/shopping_cart.dart @@ -41,63 +41,61 @@ class _ShoppingCartPageState extends State { return Scaffold( backgroundColor: kShrinePink50, body: SafeArea( - child: Container( - child: ScopedModelDescendant( - builder: (BuildContext context, Widget? child, AppStateModel model) { - return Stack( - children: [ - ListView( - children: [ - Row( - children: [ - SizedBox( - width: _leftColumnWidth, - child: IconButton( - icon: const Icon(Icons.keyboard_arrow_down), - onPressed: () => ExpandingBottomSheet.of(context)!.close(), - ), + child: ScopedModelDescendant( + builder: (BuildContext context, Widget? child, AppStateModel model) { + return Stack( + children: [ + ListView( + children: [ + Row( + children: [ + SizedBox( + width: _leftColumnWidth, + child: IconButton( + icon: const Icon(Icons.keyboard_arrow_down), + onPressed: () => ExpandingBottomSheet.of(context)!.close(), ), - Text( - 'CART', - style: localTheme.textTheme.subtitle1!.copyWith(fontWeight: FontWeight.w600), - ), - const SizedBox(width: 16.0), - Text('${model.totalCartQuantity} ITEMS'), - ], - ), - const SizedBox(height: 16.0), - Column( - children: _createShoppingCartRows(model), - ), - ShoppingCartSummary(model: model), - const SizedBox(height: 100.0), - ], - ), - Positioned( - bottom: 16.0, - left: 16.0, - right: 16.0, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - primary: kShrinePink100, - shape: const BeveledRectangleBorder( - borderRadius: BorderRadius.all(Radius.circular(7.0)), ), - ), - child: const Padding( - padding: EdgeInsets.symmetric(vertical: 12.0), - child: Text('CLEAR CART'), - ), - onPressed: () { - model.clearCart(); - ExpandingBottomSheet.of(context)!.close(); - }, + Text( + 'CART', + style: localTheme.textTheme.subtitle1!.copyWith(fontWeight: FontWeight.w600), + ), + const SizedBox(width: 16.0), + Text('${model.totalCartQuantity} ITEMS'), + ], ), + const SizedBox(height: 16.0), + Column( + children: _createShoppingCartRows(model), + ), + ShoppingCartSummary(model: model), + const SizedBox(height: 100.0), + ], + ), + Positioned( + bottom: 16.0, + left: 16.0, + right: 16.0, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + primary: kShrinePink100, + shape: const BeveledRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(7.0)), + ), + ), + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 12.0), + child: Text('CLEAR CART'), + ), + onPressed: () { + model.clearCart(); + ExpandingBottomSheet.of(context)!.close(); + }, ), - ], - ); - }, - ), + ), + ], + ); + }, ), ), ); diff --git a/packages/flutter/lib/src/cupertino/action_sheet.dart b/packages/flutter/lib/src/cupertino/action_sheet.dart index dc78b190d0..95161ec361 100644 --- a/packages/flutter/lib/src/cupertino/action_sheet.dart +++ b/packages/flutter/lib/src/cupertino/action_sheet.dart @@ -235,12 +235,10 @@ class CupertinoActionSheet extends StatelessWidget { height: 0.0, ); } - return Container( - child: _CupertinoAlertActionSection( - children: actions!, - scrollController: actionScrollController, - hasCancelButton: cancelButton != null, - ), + return _CupertinoAlertActionSection( + children: actions!, + scrollController: actionScrollController, + hasCancelButton: cancelButton != null, ); } diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index fbb64e071f..aca0a99395 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -657,11 +657,9 @@ class _TileIcon extends StatelessWidget { return Align( alignment: Alignment.topCenter, heightFactor: 1.0, - child: Container( - child: IconTheme( - data: iconThemeData, - child: selected ? item.activeIcon : item.icon, - ), + child: IconTheme( + data: iconThemeData, + child: selected ? item.activeIcon : item.icon, ), ); } diff --git a/packages/flutter/test/cupertino/nav_bar_test.dart b/packages/flutter/test/cupertino/nav_bar_test.dart index 34719ef2d0..7b98dfb839 100644 --- a/packages/flutter/test/cupertino/nav_bar_test.dart +++ b/packages/flutter/test/cupertino/nav_bar_test.dart @@ -1137,19 +1137,17 @@ void main() { home: Builder(builder: (BuildContext context) { return MediaQuery( data: MediaQuery.of(context).copyWith(textScaleFactor: 99), - child: CupertinoPageScaffold( + child: const CupertinoPageScaffold( child: CustomScrollView( slivers: [ - const CupertinoSliverNavigationBar( + CupertinoSliverNavigationBar( leading: Text('leading'), middle: Text('middle'), largeTitle: Text('Large Title'), trailing: Text('trailing'), ), SliverToBoxAdapter( - child: Container( - child: const Text('content'), - ), + child: Text('content'), ), ], ), @@ -1185,17 +1183,15 @@ void main() { builder: (BuildContext context) { return MediaQuery( data: MediaQuery.of(context).copyWith(textScaleFactor: 99), - child: Container( - child: const CupertinoPageScaffold( - child: CustomScrollView( - slivers: [ - CupertinoSliverNavigationBar( - automaticallyImplyLeading: true, - automaticallyImplyTitle: true, - previousPageTitle: 'previous title', - ), - ], - ), + child: const CupertinoPageScaffold( + child: CustomScrollView( + slivers: [ + CupertinoSliverNavigationBar( + automaticallyImplyLeading: true, + automaticallyImplyTitle: true, + previousPageTitle: 'previous title', + ), + ], ), ), ); diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index 6f7093c588..085ba46d62 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -3732,12 +3732,11 @@ void main() { ), Expanded( child: Navigator( - onGenerateRoute: (_) => - CupertinoPageRoute(builder: (_) => Container( - child: CupertinoTextField( - controller: controller, - ), - )), + onGenerateRoute: (_) => CupertinoPageRoute( + builder: (_) => CupertinoTextField( + controller: controller, + ), + ), ), ), ], diff --git a/packages/flutter/test/material/bottom_sheet_test.dart b/packages/flutter/test/material/bottom_sheet_test.dart index b9626461ee..0b3ab19775 100644 --- a/packages/flutter/test/material/bottom_sheet_test.dart +++ b/packages/flutter/test/material/bottom_sheet_test.dart @@ -487,9 +487,7 @@ void main() { showModalBottomSheet(context: scaffoldKey.currentContext!, builder: (BuildContext context) { - return Container( - child: const Text('BottomSheet'), - ); + return const Text('BottomSheet'); }); await tester.pump(); // bottom sheet show animation starts @@ -548,9 +546,7 @@ void main() { shape: shape, clipBehavior: clipBehavior, builder: (BuildContext context) { - return Container( - child: const Text('BottomSheet'), - ); + return const Text('BottomSheet'); }, ); @@ -587,9 +583,7 @@ void main() { builder: (_, ScrollController controller) { return SingleChildScrollView( controller: controller, - child: Container( - child: const Text('BottomSheet'), - ), + child: const Text('BottomSheet'), ); }, ); @@ -713,9 +707,7 @@ void main() { routeSettings: routeSettings, builder: (BuildContext context) { retrievedRouteSettings = ModalRoute.of(context)!.settings; - return Container( - child: const Text('BottomSheet'), - ); + return const Text('BottomSheet'); }, ); @@ -743,9 +735,7 @@ void main() { reverseDuration: const Duration(seconds: 2), ), builder: (BuildContext context) { - return Container( - child: const Text('BottomSheet'), - ); + return const Text('BottomSheet'); }, ); }, diff --git a/packages/flutter/test/material/bottom_sheet_theme_test.dart b/packages/flutter/test/material/bottom_sheet_theme_test.dart index 0d03f74c4c..b75bcb9664 100644 --- a/packages/flutter/test/material/bottom_sheet_theme_test.dart +++ b/packages/flutter/test/material/bottom_sheet_theme_test.dart @@ -245,9 +245,7 @@ void main() { showModalBottomSheet( context: context, builder: (BuildContext context) { - return Container( - child: const Text('This is a modal bottom sheet.'), - ); + return const Text('This is a modal bottom sheet.'); }, ); }, @@ -299,10 +297,8 @@ Widget bottomSheetWithElevations(BottomSheetThemeData bottomSheetTheme) { showModalBottomSheet( context: context, builder: (BuildContext _) { - return Container( - child: const Text( - 'This is a modal bottom sheet.', - ), + return const Text( + 'This is a modal bottom sheet.', ); }, ); @@ -314,10 +310,8 @@ Widget bottomSheetWithElevations(BottomSheetThemeData bottomSheetTheme) { showBottomSheet( context: context, builder: (BuildContext _) { - return Container( - child: const Text( - 'This is a persistent bottom sheet.', - ), + return const Text( + 'This is a persistent bottom sheet.', ); }, ); diff --git a/packages/flutter/test/material/drawer_test.dart b/packages/flutter/test/material/drawer_test.dart index d16ed23417..954c085a8e 100644 --- a/packages/flutter/test/material/drawer_test.dart +++ b/packages/flutter/test/material/drawer_test.dart @@ -168,17 +168,13 @@ void main() { testWidgets('Open/close drawers by flinging', (WidgetTester tester) async { await tester.pumpWidget( - MaterialApp( + const MaterialApp( home: Scaffold( drawer: Drawer( - child: Container( - child: const Text('start drawer'), - ), + child: Text('start drawer'), ), endDrawer: Drawer( - child: Container( - child: const Text('end drawer'), - ), + child: Text('end drawer'), ), ), ), diff --git a/packages/flutter/test/material/expansion_panel_test.dart b/packages/flutter/test/material/expansion_panel_test.dart index fa690d7ad1..a850f2a222 100644 --- a/packages/flutter/test/material/expansion_panel_test.dart +++ b/packages/flutter/test/material/expansion_panel_test.dart @@ -103,9 +103,7 @@ class ExpansionPanelListSemanticsTestState extends State[StretchMode.blurBackground], - background: Container( - child: Row( - children: [ - Expanded(child: Container(color: Colors.red)), - Expanded(child:Container(color: Colors.blue)), - ], - ) + background: Row( + children: [ + Expanded(child: Container(color: Colors.red)), + Expanded(child:Container(color: Colors.blue)), + ], ), ), ), diff --git a/packages/flutter/test/material/page_test.dart b/packages/flutter/test/material/page_test.dart index a9d3bf0e31..d51bc90bd3 100644 --- a/packages/flutter/test/material/page_test.dart +++ b/packages/flutter/test/material/page_test.dart @@ -287,7 +287,7 @@ void main() { onPressed: () { Navigator.of(context).pushNamed('/b'); }, ), ), - '/b': (BuildContext context) => Container(child: const Text('HELLO')), + '/b': (BuildContext context) => const Text('HELLO'), }; await tester.pumpWidget( MaterialApp( diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index e2b0c37046..e7dfcd5a97 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -1151,26 +1151,24 @@ void main() { await tester.pumpWidget( MaterialApp( home: Scaffold( - body: Container( - child: Center( - child: PopupMenuButton( - onSelected: (String result) { - selectedValue = result; - }, - child: const Text('Menu Button'), - initialValue: '1', - itemBuilder: (BuildContext context) => >[ - const PopupMenuItem( - child: Text('1'), - value: '1', - ), - const PopupMenuDivider(), - const PopupMenuItem( - child: Text('2'), - value: '2', - ), - ], - ), + body: Center( + child: PopupMenuButton( + onSelected: (String result) { + selectedValue = result; + }, + child: const Text('Menu Button'), + initialValue: '1', + itemBuilder: (BuildContext context) => >[ + const PopupMenuItem( + child: Text('1'), + value: '1', + ), + const PopupMenuDivider(), + const PopupMenuItem( + child: Text('2'), + value: '2', + ), + ], ), ), ), diff --git a/packages/flutter/test/material/scaffold_test.dart b/packages/flutter/test/material/scaffold_test.dart index 099eb544ed..5ead37e3df 100644 --- a/packages/flutter/test/material/scaffold_test.dart +++ b/packages/flutter/test/material/scaffold_test.dart @@ -1831,9 +1831,7 @@ void main() { body: Center( child: Container(), ), - bottomSheet: Container( - child: const Text('Bottom sheet'), - ), + bottomSheet: const Text('Bottom sheet'), ), ), ); diff --git a/packages/flutter/test/material/tabs_test.dart b/packages/flutter/test/material/tabs_test.dart index e8fadd198f..19cdf3f93e 100644 --- a/packages/flutter/test/material/tabs_test.dart +++ b/packages/flutter/test/material/tabs_test.dart @@ -2397,14 +2397,12 @@ void main() { required List tabs, }) { return boilerplate( - child: Container( - child: TabBar( - controller: controller, - tabs: tabs.map((String tab) => Tab(text: tab)).toList(), - onTap: (int index) { - tabIndex = index; - }, - ), + child: TabBar( + controller: controller, + tabs: tabs.map((String tab) => Tab(text: tab)).toList(), + onTap: (int index) { + tabIndex = index; + }, ), ); } diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index 27f7e7f3e7..b64821e5dc 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -3568,11 +3568,9 @@ void main() { await tester.pumpWidget( overlay( - child: Container( - child: TextField( - controller: controller, - maxLines: 6, - ), + child: TextField( + controller: controller, + maxLines: 6, ), ), ); diff --git a/packages/flutter/test/rendering/viewport_test.dart b/packages/flutter/test/rendering/viewport_test.dart index 5c8da28f01..a2e6492bb3 100644 --- a/packages/flutter/test/rendering/viewport_test.dart +++ b/packages/flutter/test/rendering/viewport_test.dart @@ -1592,17 +1592,13 @@ void main() { return Directionality( textDirection: TextDirection.ltr, child: Center( - child: Container( - child: ListView( - scrollDirection: a1, - children: List.generate(10, (int y) { - return Container( - child: ListView( - scrollDirection: a2, - ), - ); - }), - ), + child: ListView( + scrollDirection: a1, + children: List.generate(10, (int y) { + return ListView( + scrollDirection: a2, + ); + }), ), ), ); diff --git a/packages/flutter/test/widgets/actions_test.dart b/packages/flutter/test/widgets/actions_test.dart index cb6ef7d89c..7b764c665a 100644 --- a/packages/flutter/test/widgets/actions_test.dart +++ b/packages/flutter/test/widgets/actions_test.dart @@ -379,11 +379,9 @@ void main() { actions: >{ TestIntent: testAction, }, - child: Container( - child: Actions( - actions: const >{}, - child: Container(key: containerKey), - ), + child: Actions( + actions: const >{}, + child: Container(key: containerKey), ), ), ); diff --git a/packages/flutter/test/widgets/automatic_keep_alive_test.dart b/packages/flutter/test/widgets/automatic_keep_alive_test.dart index fcfa123d48..7b9baba55d 100644 --- a/packages/flutter/test/widgets/automatic_keep_alive_test.dart +++ b/packages/flutter/test/widgets/automatic_keep_alive_test.dart @@ -175,7 +175,7 @@ void tests({ required bool impliedMode }) { childAspectRatio: 400.0 / 24.6, // about 50 widgets visible cacheExtent: 0.0, children: generateList( - Container(child: const Placeholder()), + const Placeholder(), impliedMode: impliedMode, ), ), diff --git a/packages/flutter/test/widgets/basic_test.dart b/packages/flutter/test/widgets/basic_test.dart index af8250cb13..10a9da13d4 100644 --- a/packages/flutter/test/widgets/basic_test.dart +++ b/packages/flutter/test/widgets/basic_test.dart @@ -220,21 +220,19 @@ void main() { await tester.pumpWidget( MaterialApp( home: Scaffold( - body: Container( - child: Row( - crossAxisAlignment: CrossAxisAlignment.baseline, - textBaseline: TextBaseline.alphabetic, - children: [ - Text('big text', - key: key1, - style: const TextStyle(fontSize: fontSize1), - ), - Text('one\ntwo\nthree\nfour\nfive\nsix\nseven', - key: key2, - style: const TextStyle(fontSize: fontSize2), - ), - ], - ), + body: Row( + crossAxisAlignment: CrossAxisAlignment.baseline, + textBaseline: TextBaseline.alphabetic, + children: [ + Text('big text', + key: key1, + style: const TextStyle(fontSize: fontSize1), + ), + Text('one\ntwo\nthree\nfour\nfive\nsix\nseven', + key: key2, + style: const TextStyle(fontSize: fontSize2), + ), + ], ), ), ), @@ -277,22 +275,20 @@ void main() { await tester.pumpWidget( MaterialApp( home: Scaffold( - body: Container( - child: Row( - crossAxisAlignment: CrossAxisAlignment.baseline, - textBaseline: TextBaseline.alphabetic, - children: [ - Text('big text', - key: key1, - style: const TextStyle(fontSize: fontSize1), - ), - Text('one\ntwo\nthree\nfour\nfive\nsix\nseven', - key: key2, - style: const TextStyle(fontSize: fontSize2), - ), - const FlutterLogo(size: 250), - ], - ), + body: Row( + crossAxisAlignment: CrossAxisAlignment.baseline, + textBaseline: TextBaseline.alphabetic, + children: [ + Text('big text', + key: key1, + style: const TextStyle(fontSize: fontSize1), + ), + Text('one\ntwo\nthree\nfour\nfive\nsix\nseven', + key: key2, + style: const TextStyle(fontSize: fontSize2), + ), + const FlutterLogo(size: 250), + ], ), ), ), diff --git a/packages/flutter/test/widgets/draggable_test.dart b/packages/flutter/test/widgets/draggable_test.dart index 7366e68038..73671e6e04 100644 --- a/packages/flutter/test/widgets/draggable_test.dart +++ b/packages/flutter/test/widgets/draggable_test.dart @@ -408,14 +408,12 @@ void main() { onTap: () { events.add('tap'); }, - child: Container( - child: const Text('Button'), - ), + child: const Text('Button'), ), DragTarget( builder: (BuildContext context, List data, List rejects) { - return IgnorePointer( - child: Container(child: const Text('Target')), + return const IgnorePointer( + child: Text('Target'), ); }, onAccept: (int? data) { @@ -498,7 +496,7 @@ void main() { onTap: () { events.add('tap'); }, - child: Container(child: const Text('Button')), + child: const Text('Button'), ), feedback: const Text('Dragging'), ), diff --git a/packages/flutter/test/widgets/drawer_test.dart b/packages/flutter/test/widgets/drawer_test.dart index 8aa4cc21d3..3cbef841ec 100644 --- a/packages/flutter/test/widgets/drawer_test.dart +++ b/packages/flutter/test/widgets/drawer_test.dart @@ -273,11 +273,9 @@ void main() { ], ), ), - body: Container( - child: TextButton( - child: const Text('button'), - onPressed: () { buttonPressed = true; }, - ), + body: TextButton( + child: const Text('button'), + onPressed: () { buttonPressed = true; }, ), ); }, diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index 59b7bc669b..7074ba2ad4 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -4681,19 +4681,17 @@ void main() { await tester.pumpWidget(MaterialApp( home: Align( alignment: Alignment.topLeft, - child: Container( - child: SizedBox( - width: 100, - child: EditableText( - showSelectionHandles: true, - controller: controller, - focusNode: FocusNode(), - style: Typography.material2018(platform: TargetPlatform.iOS).black.subtitle1!, - cursorColor: Colors.blue, - backgroundCursorColor: Colors.grey, - selectionControls: cupertinoTextSelectionControls, - keyboardType: TextInputType.text, - ), + child: SizedBox( + width: 100, + child: EditableText( + showSelectionHandles: true, + controller: controller, + focusNode: FocusNode(), + style: Typography.material2018(platform: TargetPlatform.iOS).black.subtitle1!, + cursorColor: Colors.blue, + backgroundCursorColor: Colors.grey, + selectionControls: cupertinoTextSelectionControls, + keyboardType: TextInputType.text, ), ), ), diff --git a/packages/flutter/test/widgets/focus_scope_test.dart b/packages/flutter/test/widgets/focus_scope_test.dart index 4b378af2bc..9bfac7a0e7 100644 --- a/packages/flutter/test/widgets/focus_scope_test.dart +++ b/packages/flutter/test/widgets/focus_scope_test.dart @@ -1141,20 +1141,16 @@ void main() { children: [ Focus( key: key2, - child: Container( - child: Focus( - key: key3, - child: Container(), - ), + child: Focus( + key: key3, + child: Container(), ), ), Focus( key: key4, - child: Container( - child: Focus( - key: key5, - child: Container(), - ), + child: Focus( + key: key5, + child: Container(), ), ), Focus( diff --git a/packages/flutter/test/widgets/framework_test.dart b/packages/flutter/test/widgets/framework_test.dart index 19bc675c96..2a4c3ed141 100644 --- a/packages/flutter/test/widgets/framework_test.dart +++ b/packages/flutter/test/widgets/framework_test.dart @@ -904,7 +904,7 @@ void main() { children: [ const SwapKeyWidget(childKey: ValueKey(0)), Container(key: const ValueKey(1)), - Container(child: SizedBox(key: key)), + Container(color: Colors.green, child: SizedBox(key: key)), ], ); await tester.pumpWidget(stack); @@ -1160,7 +1160,7 @@ void main() { children: [ Container(), Container(key: key1 = GlobalKey()), - Container(child: Container()), + Container(), Container(key: key2 = GlobalKey()), Container(), ], @@ -1179,7 +1179,7 @@ void main() { children: [ Container(), Container(key: GlobalKey()), - Container(child: Container()), + Container(color: Colors.green, child: Container()), Container(key: GlobalKey()), Container(), ], @@ -1197,10 +1197,11 @@ void main() { '├Container-[GlobalKey#00000]\n' '│└LimitedBox(maxWidth: 0.0, maxHeight: 0.0, renderObject: RenderLimitedBox#00000 relayoutBoundary=up1)\n' '│ └ConstrainedBox(BoxConstraints(biggest), renderObject: RenderConstrainedBox#00000 relayoutBoundary=up2)\n' - '├Container\n' - '│└Container\n' - '│ └LimitedBox(maxWidth: 0.0, maxHeight: 0.0, renderObject: RenderLimitedBox#00000 relayoutBoundary=up1)\n' - '│ └ConstrainedBox(BoxConstraints(biggest), renderObject: RenderConstrainedBox#00000 relayoutBoundary=up2)\n' + '├Container(bg: MaterialColor(primary value: Color(0xff4caf50)))\n' + '│└ColoredBox(color: MaterialColor(primary value: Color(0xff4caf50)), renderObject: _RenderColoredBox#00000 relayoutBoundary=up1)\n' + '│ └Container\n' + '│ └LimitedBox(maxWidth: 0.0, maxHeight: 0.0, renderObject: RenderLimitedBox#00000 relayoutBoundary=up2)\n' + '│ └ConstrainedBox(BoxConstraints(biggest), renderObject: RenderConstrainedBox#00000 relayoutBoundary=up3)\n' '├Container-[GlobalKey#00000]\n' '│└LimitedBox(maxWidth: 0.0, maxHeight: 0.0, renderObject: RenderLimitedBox#00000 relayoutBoundary=up1)\n' '│ └ConstrainedBox(BoxConstraints(biggest), renderObject: RenderConstrainedBox#00000 relayoutBoundary=up2)\n' @@ -1462,7 +1463,7 @@ void main() { testWidgets('A widget whose element has an invalid visitChildren implementation triggers a useful error message', (WidgetTester tester) async { final GlobalKey key = GlobalKey(); - await tester.pumpWidget(Container(child: _WidgetWithNoVisitChildren(_StatefulLeaf(key: key)))); + await tester.pumpWidget(_WidgetWithNoVisitChildren(_StatefulLeaf(key: key))); (key.currentState! as _StatefulLeafState).markNeedsBuild(); await tester.pumpWidget(Container()); final dynamic exception = tester.takeException(); diff --git a/packages/flutter/test/widgets/gesture_detector_test.dart b/packages/flutter/test/widgets/gesture_detector_test.dart index 72f67d2c94..3a9830bd6e 100644 --- a/packages/flutter/test/widgets/gesture_detector_test.dart +++ b/packages/flutter/test/widgets/gesture_detector_test.dart @@ -858,9 +858,7 @@ void main() { textDirection: TextDirection.ltr, child: RawGestureDetector( key: key, - child: Container( - child: const Text('Text'), - ), + child: const Text('Text'), ), ), ); diff --git a/packages/flutter/test/widgets/global_keys_duplicated_test.dart b/packages/flutter/test/widgets/global_keys_duplicated_test.dart index fa0de7d783..618dbaffa9 100644 --- a/packages/flutter/test/widgets/global_keys_duplicated_test.dart +++ b/packages/flutter/test/widgets/global_keys_duplicated_test.dart @@ -12,9 +12,9 @@ void main() { testWidgets('GlobalKey children of one node', (WidgetTester tester) async { // This is actually a test of the regular duplicate key logic, which // happens before the duplicate GlobalKey logic. - await tester.pumpWidget(Stack(children: [ - Container(key: const GlobalObjectKey(0)), - Container(key: const GlobalObjectKey(0)), + await tester.pumpWidget(Stack(children: const [ + DummyWidget(key: GlobalObjectKey(0)), + DummyWidget(key: GlobalObjectKey(0)), ])); final dynamic error = tester.takeException(); expect(error, isFlutterError); @@ -23,56 +23,61 @@ void main() { expect(error.toString(), contains('[GlobalObjectKey ${describeIdentity(0)}]')); }); - testWidgets('GlobalKey children of two nodes', (WidgetTester tester) async { + testWidgets('GlobalKey children of two nodes - A', (WidgetTester tester) async { await tester.pumpWidget(Stack( textDirection: TextDirection.ltr, - children: [ - Container(child: Container(key: const GlobalObjectKey(0))), - Container(child: Container(key: const GlobalObjectKey(0))), + children: const [ + DummyWidget(child: DummyWidget(key: GlobalObjectKey(0))), + DummyWidget( + child: DummyWidget(key: GlobalObjectKey(0), + ), + ), ], )); final dynamic error = tester.takeException(); expect(error, isFlutterError); expect(error.toString(), startsWith('Multiple widgets used the same GlobalKey.\n')); expect(error.toString(), contains('different widgets that both had the following description')); - expect(error.toString(), contains('Container')); + expect(error.toString(), contains('DummyWidget')); expect(error.toString(), contains('[GlobalObjectKey ${describeIdentity(0)}]')); expect(error.toString(), endsWith('\nA GlobalKey can only be specified on one widget at a time in the widget tree.')); }); - testWidgets('GlobalKey children of two different nodes', (WidgetTester tester) async { + testWidgets('GlobalKey children of two different nodes - B', (WidgetTester tester) async { await tester.pumpWidget(Stack( textDirection: TextDirection.ltr, - children: [ - Container(child: Container(key: const GlobalObjectKey(0))), - Container(key: const Key('x'), child: Container(key: const GlobalObjectKey(0))), + children: const [ + DummyWidget(child: DummyWidget(key: GlobalObjectKey(0))), + DummyWidget(key: Key('x'), child: DummyWidget(key: GlobalObjectKey(0))), ], )); final dynamic error = tester.takeException(); expect(error, isFlutterError); expect(error.toString(), startsWith('Multiple widgets used the same GlobalKey.\n')); expect(error.toString(), isNot(contains('different widgets that both had the following description'))); - expect(error.toString(), contains('Container')); - expect(error.toString(), contains("Container-[<'x'>]")); + expect(error.toString(), contains('DummyWidget')); + expect(error.toString(), contains("DummyWidget-[<'x'>]")); expect(error.toString(), contains('[GlobalObjectKey ${describeIdentity(0)}]')); expect(error.toString(), endsWith('\nA GlobalKey can only be specified on one widget at a time in the widget tree.')); }); - testWidgets('GlobalKey children of two nodes', (WidgetTester tester) async { + testWidgets('GlobalKey children of two nodes - C', (WidgetTester tester) async { late StateSetter nestedSetState; bool flag = false; await tester.pumpWidget(Stack( textDirection: TextDirection.ltr, children: [ - Container(child: Container(key: const GlobalObjectKey(0))), - Container(child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) { - nestedSetState = setState; - if (flag) - return Container(key: const GlobalObjectKey(0)); - return Container(); - }, - )), + const DummyWidget(child: DummyWidget(key: GlobalObjectKey(0))), + DummyWidget( + child: StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + nestedSetState = setState; + if (flag) + return const DummyWidget(key: GlobalObjectKey(0)); + return const DummyWidget(); + }, + ), + ), ], )); nestedSetState(() { flag = true; }); @@ -84,8 +89,23 @@ void main() { // We should probably also verify the three other combinations that can be generated... expect(error.toString().split('\n').join(' '), contains('This was determined by noticing that after the widget with the above global key was moved out of its previous parent, that previous parent never updated during this frame, meaning that it either did not update at all or updated before the widget was moved, in either case implying that it still thinks that it should have a child with that global key.')); expect(error.toString(), contains('[GlobalObjectKey ${describeIdentity(0)}]')); - expect(error.toString(), contains('Container')); + expect(error.toString(), contains('DummyWidget')); expect(error.toString(), endsWith('\nA GlobalKey can only be specified on one widget at a time in the widget tree.')); expect(error, isFlutterError); }); } + +class DummyWidget extends StatelessWidget { + const DummyWidget({ Key? key, this.child }) : super(key: key); + + final Widget? child; + + @override + Widget build(BuildContext context) { + return child ?? LimitedBox( + maxWidth: 0.0, + maxHeight: 0.0, + child: ConstrainedBox(constraints: const BoxConstraints.expand()), + ); + } +} diff --git a/packages/flutter/test/widgets/grid_view_test.dart b/packages/flutter/test/widgets/grid_view_test.dart index 881172e7d0..53abf41a20 100644 --- a/packages/flutter/test/widgets/grid_view_test.dart +++ b/packages/flutter/test/widgets/grid_view_test.dart @@ -160,9 +160,7 @@ void main() { return Builder( builder: (BuildContext context) { log.add(i); - return Container( - child: Text('$i'), - ); + return Text('$i'); } ); }), @@ -254,9 +252,7 @@ void main() { return Builder( builder: (BuildContext context) { log.add(i); - return Container( - child: Text('$i'), - ); + return Text('$i'); } ); }), @@ -292,9 +288,7 @@ void main() { return Builder( builder: (BuildContext context) { log.add(i); - return Container( - child: Text('$i'), - ); + return Text('$i'); } ); }), @@ -353,9 +347,7 @@ void main() { return Builder( builder: (BuildContext context) { log.add(i); - return Container( - child: Text('$i'), - ); + return Text('$i'); } ); }), @@ -391,9 +383,7 @@ void main() { return Builder( builder: (BuildContext context) { log.add(i); - return Container( - child: Text('$i'), - ); + return Text('$i'); } ); }), @@ -454,9 +444,7 @@ void main() { child: GridView.count( crossAxisCount: 4, children: List.generate(20, (int i) { - return Container( - child: Text('$i'), - ); + return Text('$i'); }), ), ), @@ -477,9 +465,7 @@ void main() { crossAxisCount: 4, shrinkWrap: true, children: List.generate(20, (int i) { - return Container( - child: Text('$i'), - ); + return Text('$i'); }), ), ), @@ -501,9 +487,7 @@ void main() { shrinkWrap: true, itemCount: 20, itemBuilder: (BuildContext context, int index) { - return Container( - child: Text('$index'), - ); + return Text('$index'); }, ), ), @@ -523,9 +507,7 @@ void main() { ), shrinkWrap: true, itemBuilder: (BuildContext context, int index) { - return Container( - child: Text('$index'), - ); + return Text('$index'); }, ), ), @@ -743,9 +725,7 @@ void main() { children: List.generate(20, (int i) { return Builder( builder: (BuildContext context) { - return Container( - child: Text('$i'), - ); + return Text('$i'); } ); }), @@ -771,9 +751,7 @@ void main() { children: List.generate(20, (int i) { return Builder( builder: (BuildContext context) { - return Container( - child: Text('$i'), - ); + return Text('$i'); } ); }), diff --git a/packages/flutter/test/widgets/heroes_test.dart b/packages/flutter/test/widgets/heroes_test.dart index 7ae6a05d2a..f77f86d29c 100644 --- a/packages/flutter/test/widgets/heroes_test.dart +++ b/packages/flutter/test/widgets/heroes_test.dart @@ -944,9 +944,7 @@ Future main() async { children: [ const SizedBox(height: 200.0), // This container will appear at Y=200 - Container( - child: const Hero(tag: 'H', child: SizedBox(key: homeHeroKey, height: 100.0, width: 100.0)), - ), + const Hero(tag: 'H', child: SizedBox(key: homeHeroKey, height: 100.0, width: 100.0)), TextButton( child: const Text('PUSH'), onPressed: () { Navigator.push(context, route); }, @@ -1023,9 +1021,7 @@ Future main() async { children: [ const SizedBox(height: 200.0), // This container will appear at Y=200 - Container( - child: const Hero(tag: 'H', child: SizedBox(key: homeHeroKey, height: 100.0, width: 100.0)), - ), + const Hero(tag: 'H', child: SizedBox(key: homeHeroKey, height: 100.0, width: 100.0)), TextButton( child: const Text('PUSH'), onPressed: () { Navigator.push(context, route); }, @@ -1077,19 +1073,17 @@ Future main() async { builder: (BuildContext context) { return Material( child: ListView( - children: [ + children: const [ // This container will appear at Y=0 - Container( - child: const Hero( - tag: 'BC', - child: SizedBox( - key: heroBCKey, - height: 150.0, - child: Text('Hero'), - ), + Hero( + tag: 'BC', + child: SizedBox( + key: heroBCKey, + height: 150.0, + child: Text('Hero'), ), ), - const SizedBox(height: 800.0), + SizedBox(height: 800.0), ], ), ); @@ -1104,27 +1098,23 @@ Future main() async { children: [ const SizedBox(height: 100.0), // This container will appear at Y=100 - Container( - child: const Hero( - tag: 'AB', - child: SizedBox( - key: heroABKey, - height: 200.0, - child: Text('Hero'), - ), + const Hero( + tag: 'AB', + child: SizedBox( + key: heroABKey, + height: 200.0, + child: Text('Hero'), ), ), TextButton( child: const Text('PUSH C'), onPressed: () { Navigator.push(context, routeC); }, ), - Container( - child: const Hero( - tag: 'BC', - child: SizedBox( - height: 150.0, - child: Text('Hero'), - ), + const Hero( + tag: 'BC', + child: SizedBox( + height: 150.0, + child: Text('Hero'), ), ), const SizedBox(height: 800.0), @@ -1144,14 +1134,12 @@ Future main() async { children: [ const SizedBox(height: 200.0), // This container will appear at Y=200 - Container( - child: const Hero( - tag: 'AB', - child: SizedBox( - height: 100.0, - width: 100.0, - child: Text('Hero'), - ), + const Hero( + tag: 'AB', + child: SizedBox( + height: 100.0, + width: 100.0, + child: Text('Hero'), ), ), TextButton( @@ -2107,15 +2095,13 @@ Future main() async { testWidgets('Hero within a Hero subtree, throws', (WidgetTester tester) async { await tester.pumpWidget( - MaterialApp( + const MaterialApp( home: Material( - child: Container( - child: const Hero( - tag: 'a', - child: Hero( - tag: 'b', - child: Text('Child of a Hero'), - ), + child: Hero( + tag: 'a', + child: Hero( + tag: 'b', + child: Text('Child of a Hero'), ), ), ), @@ -2426,11 +2412,9 @@ Future main() async { child: Hero( tag: 'hero', transitionOnUserGestures: true, - child: Container( - child: Image( - image: imageProvider, - key: imageKey2, - ), + child: Image( + image: imageProvider, + key: imageKey2, ), ), ); diff --git a/packages/flutter/test/widgets/html_element_view_test.dart b/packages/flutter/test/widgets/html_element_view_test.dart index 758657167b..198e775513 100644 --- a/packages/flutter/test/widgets/html_element_view_test.dart +++ b/packages/flutter/test/widgets/html_element_view_test.dart @@ -152,12 +152,10 @@ void main() { await tester.pumpWidget( Center( - child: Container( - child: SizedBox( - width: 200.0, - height: 100.0, - child: HtmlElementView(viewType: 'webview', key: key), - ), + child: SizedBox( + width: 200.0, + height: 100.0, + child: HtmlElementView(viewType: 'webview', key: key), ), ), ); diff --git a/packages/flutter/test/widgets/inherited_test.dart b/packages/flutter/test/widgets/inherited_test.dart index 7d2e239e41..ec7a5821b8 100644 --- a/packages/flutter/test/widgets/inherited_test.dart +++ b/packages/flutter/test/widgets/inherited_test.dart @@ -118,48 +118,32 @@ void main() { final List log = []; await tester.pumpWidget( - Container( - child: ValueInherited( - value: 1, - child: Container( - child: FlipWidget( - left: Container( - child: ValueInherited( - value: 2, - child: Container( - child: ValueInherited( - value: 3, - child: Container( - child: Builder( - builder: (BuildContext context) { - final ValueInherited v = context.dependOnInheritedWidgetOfExactType()!; - log.add('a: ${v.value}'); - return const Text('', textDirection: TextDirection.ltr); - } - ), - ), - ), - ), - ), - ), - right: Container( - child: ValueInherited( - value: 2, - child: Container( - child: Container( - child: Builder( - builder: (BuildContext context) { - final ValueInherited v = context.dependOnInheritedWidgetOfExactType()!; - log.add('b: ${v.value}'); - return const Text('', textDirection: TextDirection.ltr); - } - ), - ), - ), - ), + ValueInherited( + value: 1, + child: FlipWidget( + left: ValueInherited( + value: 2, + child: ValueInherited( + value: 3, + child: Builder( + builder: (BuildContext context) { + final ValueInherited v = context.dependOnInheritedWidgetOfExactType()!; + log.add('a: ${v.value}'); + return const Text('', textDirection: TextDirection.ltr); + } ), ), ), + right: ValueInherited( + value: 2, + child: Builder( + builder: (BuildContext context) { + final ValueInherited v = context.dependOnInheritedWidgetOfExactType()!; + log.add('b: ${v.value}'); + return const Text('', textDirection: TextDirection.ltr); + } + ), + ), ), ), ); @@ -192,47 +176,35 @@ void main() { final Key key = GlobalKey(); await tester.pumpWidget( - Container( - child: ValueInherited( - value: 1, - child: Container( - child: FlipWidget( - left: Container( - child: ValueInherited( - value: 2, - child: Container( - child: ValueInherited( - value: 3, - child: Container( - key: key, - child: Builder( - builder: (BuildContext context) { - final ValueInherited v = context.dependOnInheritedWidgetOfExactType()!; - log.add('a: ${v.value}'); - return const Text('', textDirection: TextDirection.ltr); - } - ), - ), - ), - ), + ValueInherited( + value: 1, + child: FlipWidget( + left: ValueInherited( + value: 2, + child: ValueInherited( + value: 3, + child: Container( + key: key, + child: Builder( + builder: (BuildContext context) { + final ValueInherited v = context.dependOnInheritedWidgetOfExactType()!; + log.add('a: ${v.value}'); + return const Text('', textDirection: TextDirection.ltr); + } ), ), - right: Container( - child: ValueInherited( - value: 2, - child: Container( - child: Container( - key: key, - child: Builder( - builder: (BuildContext context) { - final ValueInherited v = context.dependOnInheritedWidgetOfExactType()!; - log.add('b: ${v.value}'); - return const Text('', textDirection: TextDirection.ltr); - } - ), - ), - ), - ), + ), + ), + right: ValueInherited( + value: 2, + child: Container( + key: key, + child: Builder( + builder: (BuildContext context) { + final ValueInherited v = context.dependOnInheritedWidgetOfExactType()!; + log.add('b: ${v.value}'); + return const Text('', textDirection: TextDirection.ltr); + } ), ), ), @@ -275,38 +247,26 @@ void main() { ); await tester.pumpWidget( - Container( - child: ValueInherited( - value: 1, - child: Container( - child: FlipWidget( - left: Container( - child: ValueInherited( - value: 2, - child: Container( - child: ValueInherited( - value: 3, - child: Container( - key: key, - child: child, - ), - ), - ), - ), - ), - right: Container( - child: ValueInherited( - value: 2, - child: Container( - child: Container( - key: key, - child: child, - ), - ), - ), + ValueInherited( + value: 1, + child: FlipWidget( + left: ValueInherited( + value: 2, + child: ValueInherited( + value: 3, + child: Container( + key: key, + child: child, ), ), ), + right: ValueInherited( + value: 2, + child: Container( + key: key, + child: child, + ), + ), ), ), ); diff --git a/packages/flutter/test/widgets/init_state_test.dart b/packages/flutter/test/widgets/init_state_test.dart index e65f635920..e31ab75cc6 100644 --- a/packages/flutter/test/widgets/init_state_test.dart +++ b/packages/flutter/test/widgets/init_state_test.dart @@ -29,7 +29,16 @@ class TestWidgetState extends State { void main() { testWidgets('initState() is called when we are in the tree', (WidgetTester tester) async { - await tester.pumpWidget(Container(child: const TestWidget())); - expect(ancestors, equals(['Container', 'RenderObjectToWidgetAdapter'])); + await tester.pumpWidget(const Parent(child: TestWidget())); + expect(ancestors, equals(['Parent', 'RenderObjectToWidgetAdapter'])); }); } + +class Parent extends StatelessWidget { + const Parent({ Key? key, required this.child }) : super(key: key); + + final Widget child; + + @override + Widget build(BuildContext context) => child; +} diff --git a/packages/flutter/test/widgets/keep_alive_test.dart b/packages/flutter/test/widgets/keep_alive_test.dart index 52f8d77f31..1ca7d3c8f3 100644 --- a/packages/flutter/test/widgets/keep_alive_test.dart +++ b/packages/flutter/test/widgets/keep_alive_test.dart @@ -152,7 +152,7 @@ void main() { addSemanticIndexes: false, crossAxisCount: 2, childAspectRatio: 400.0 / 24.6, // about 50 widgets visible - children: generateList(Container(child: const Placeholder())), + children: generateList(const Placeholder()), ), ), ); diff --git a/packages/flutter/test/widgets/list_view_test.dart b/packages/flutter/test/widgets/list_view_test.dart index 5fa5bd9eca..5c2886ad39 100644 --- a/packages/flutter/test/widgets/list_view_test.dart +++ b/packages/flutter/test/widgets/list_view_test.dart @@ -65,9 +65,7 @@ class _StatefulListViewState extends State<_StatefulListView> { children: List.generate(200, (int i) { return Builder( builder: (BuildContext context) { - return Container( - child: Alive(widget.aliveCallback(i), i), - ); + return Alive(widget.aliveCallback(i), i); }, ); }), @@ -97,6 +95,7 @@ void main() { itemExtent: 200.0, children: List.generate(20, (int i) { return Container( + color: Colors.green, child: Text('$i'), ); }), @@ -147,9 +146,7 @@ void main() { return Builder( builder: (BuildContext context) { log.add(i); - return Container( - child: Text('$i'), - ); + return Text('$i'); }, ); }), @@ -239,9 +236,7 @@ void main() { child: ListView( itemExtent: 100.0, children: List.generate(2, (int i) { - return Container( - child: Text('$i'), - ); + return Text('$i'); }), ), ), @@ -260,9 +255,7 @@ void main() { child: ListView( itemExtent: 100.0, children: List.generate(5, (int i) { - return Container( - child: Text('$i'), - ); + return Text('$i'); }), ), ), @@ -306,9 +299,7 @@ void main() { itemExtent: 100.0, shrinkWrap: true, children: List.generate(20, (int i) { - return Container( - child: Text('$i'), - ); + return Text('$i'); }), ), ), @@ -324,9 +315,7 @@ void main() { List.generate( 20, (int i) { - return Container( - child: Text('$i', textDirection: TextDirection.ltr), - ); + return Text('$i', textDirection: TextDirection.ltr); }, ), ); diff --git a/packages/flutter/test/widgets/list_view_vertical_test.dart b/packages/flutter/test/widgets/list_view_vertical_test.dart index 2111dd2737..2421ba09b9 100644 --- a/packages/flutter/test/widgets/list_view_vertical_test.dart +++ b/packages/flutter/test/widgets/list_view_vertical_test.dart @@ -14,9 +14,7 @@ Widget buildFrame() { itemExtent: 290.0, scrollDirection: Axis.vertical, children: items.map((int item) { - return Container( - child: Text('$item'), - ); + return Text('$item'); }).toList(), ), ); @@ -75,9 +73,7 @@ void main() { padding: const EdgeInsets.only(top: 250.0), scrollDirection: Axis.vertical, children: items.map((int item) { - return Container( - child: Text('$item'), - ); + return Text('$item'); }).toList(), ), ), diff --git a/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart b/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart index 6b365c0fc3..bab3573f5a 100644 --- a/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart +++ b/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart @@ -1282,13 +1282,11 @@ void main() { controller: ScrollController(initialScrollOffset: 300.0), itemExtent: 100.0, children: outerChildren = List.generate(10, (int i) { - return Container( - child: Center( - child: innerChildren[i] = SizedBox( - height: 50.0, - width: 50.0, - child: Text('Item $i'), - ), + return Center( + child: innerChildren[i] = SizedBox( + height: 50.0, + width: 50.0, + child: Text('Item $i'), ), ); }), @@ -1354,13 +1352,11 @@ void main() { itemExtent: 100.0, children: outerChildren = List.generate(10, (int i) { - return Container( - child: Center( - child: innerChildren[i] = SizedBox( - height: 50.0, - width: 50.0, - child: Text('Item $i'), - ), + return Center( + child: innerChildren[i] = SizedBox( + height: 50.0, + width: 50.0, + child: Text('Item $i'), ), ); }), diff --git a/packages/flutter/test/widgets/modal_barrier_test.dart b/packages/flutter/test/widgets/modal_barrier_test.dart index f5b66217ea..a0bd497165 100644 --- a/packages/flutter/test/widgets/modal_barrier_test.dart +++ b/packages/flutter/test/widgets/modal_barrier_test.dart @@ -426,9 +426,7 @@ class FirstWidget extends StatelessWidget { onTap: () { Navigator.pushNamed(context, '/modal'); }, - child: Container( - child: const Text('X'), - ), + child: const Text('X'), ); } } diff --git a/packages/flutter/test/widgets/mouse_region_test.dart b/packages/flutter/test/widgets/mouse_region_test.dart index 0c64d8cc44..5d918c1a31 100644 --- a/packages/flutter/test/widgets/mouse_region_test.dart +++ b/packages/flutter/test/widgets/mouse_region_test.dart @@ -852,12 +852,10 @@ void main() { await tester.pumpWidget( Center( - child: Container( - child: HoverFeedback( - key: feedbackKey, - onEnter: () { numEntrances += 1; }, - onExit: () { numExits += 1; }, - ), + child: HoverFeedback( + key: feedbackKey, + onEnter: () { numEntrances += 1; }, + onExit: () { numExits += 1; }, ), ), ); diff --git a/packages/flutter/test/widgets/multichild_test.dart b/packages/flutter/test/widgets/multichild_test.dart index 3da31be5a7..6602993b18 100644 --- a/packages/flutter/test/widgets/multichild_test.dart +++ b/packages/flutter/test/widgets/multichild_test.dart @@ -145,12 +145,12 @@ void main() { await tester.pumpWidget( Stack( textDirection: TextDirection.ltr, - children: [ - const DecoratedBox(decoration: kBoxDecorationA), - Container( - child: const DecoratedBox(decoration: kBoxDecorationB), + children: const [ + DecoratedBox(decoration: kBoxDecorationA), + DummyWidget( + child: DecoratedBox(decoration: kBoxDecorationB), ), - const DecoratedBox(decoration: kBoxDecorationC), + DecoratedBox(decoration: kBoxDecorationC), ], ), ); @@ -160,14 +160,14 @@ void main() { await tester.pumpWidget( Stack( textDirection: TextDirection.ltr, - children: [ - const DecoratedBox(decoration: kBoxDecorationA), - Container( - child: Container( - child: const DecoratedBox(decoration: kBoxDecorationB), + children: const [ + DecoratedBox(decoration: kBoxDecorationA), + DummyWidget( + child: DummyWidget( + child: DecoratedBox(decoration: kBoxDecorationB), ), ), - const DecoratedBox(decoration: kBoxDecorationC), + DecoratedBox(decoration: kBoxDecorationC), ], ), ); @@ -177,16 +177,16 @@ void main() { await tester.pumpWidget( Stack( textDirection: TextDirection.ltr, - children: [ - Container( - child: Container( - child: const DecoratedBox(decoration: kBoxDecorationB), + children: const [ + DummyWidget( + child: DummyWidget( + child: DecoratedBox(decoration: kBoxDecorationB), ), ), - Container( - child: const DecoratedBox(decoration: kBoxDecorationA), + DummyWidget( + child: DecoratedBox(decoration: kBoxDecorationA), ), - const DecoratedBox(decoration: kBoxDecorationC), + DecoratedBox(decoration: kBoxDecorationC), ], ), ); @@ -196,14 +196,14 @@ void main() { await tester.pumpWidget( Stack( textDirection: TextDirection.ltr, - children: [ - Container( - child: const DecoratedBox(decoration: kBoxDecorationB), + children: const [ + DummyWidget( + child: DecoratedBox(decoration: kBoxDecorationB), ), - Container( - child: const DecoratedBox(decoration: kBoxDecorationA), + DummyWidget( + child: DecoratedBox(decoration: kBoxDecorationA), ), - const DecoratedBox(decoration: kBoxDecorationC), + DecoratedBox(decoration: kBoxDecorationC), ], ), ); @@ -213,14 +213,14 @@ void main() { await tester.pumpWidget( Stack( textDirection: TextDirection.ltr, - children: [ - Container( - key: const Key('b'), - child: const DecoratedBox(decoration: kBoxDecorationB), + children: const [ + DummyWidget( + key: Key('b'), + child: DecoratedBox(decoration: kBoxDecorationB), ), - Container( - key: const Key('a'), - child: const DecoratedBox(decoration: kBoxDecorationA), + DummyWidget( + key: Key('a'), + child: DecoratedBox(decoration: kBoxDecorationA), ), ], ), @@ -231,14 +231,14 @@ void main() { await tester.pumpWidget( Stack( textDirection: TextDirection.ltr, - children: [ - Container( - key: const Key('a'), - child: const DecoratedBox(decoration: kBoxDecorationA), + children: const [ + DummyWidget( + key: Key('a'), + child: DecoratedBox(decoration: kBoxDecorationA), ), - Container( - key: const Key('b'), - child: const DecoratedBox(decoration: kBoxDecorationB), + DummyWidget( + key: Key('b'), + child: DecoratedBox(decoration: kBoxDecorationB), ), ], ), @@ -363,3 +363,12 @@ class FakeRenderObject extends RenderBox { size = constraints.biggest; } } + +class DummyWidget extends StatelessWidget { + const DummyWidget({ Key? key, required this.child }) : super(key: key); + + final Widget child; + + @override + Widget build(BuildContext context) => child; +} diff --git a/packages/flutter/test/widgets/navigator_and_layers_test.dart b/packages/flutter/test/widgets/navigator_and_layers_test.dart index 3b60f5b4f7..1a6fd7cd93 100644 --- a/packages/flutter/test/widgets/navigator_and_layers_test.dart +++ b/packages/flutter/test/widgets/navigator_and_layers_test.dart @@ -33,20 +33,18 @@ void main() { MaterialApp( routes: { '/': (BuildContext context) => RepaintBoundary( - child: Container( - child: RepaintBoundary( - child: FlipWidget( - left: CustomPaint( - painter: TestCustomPainter( - log: log, - name: 'left', - ), + child: RepaintBoundary( + child: FlipWidget( + left: CustomPaint( + painter: TestCustomPainter( + log: log, + name: 'left', ), - right: CustomPaint( - painter: TestCustomPainter( - log: log, - name: 'right', - ), + ), + right: CustomPaint( + painter: TestCustomPainter( + log: log, + name: 'right', ), ), ), diff --git a/packages/flutter/test/widgets/navigator_test.dart b/packages/flutter/test/widgets/navigator_test.dart index a5aadc7100..20f503c9e0 100644 --- a/packages/flutter/test/widgets/navigator_test.dart +++ b/packages/flutter/test/widgets/navigator_test.dart @@ -84,10 +84,8 @@ class OnTapPage extends StatelessWidget { body: GestureDetector( onTap: onTap, behavior: HitTestBehavior.opaque, - child: Container( - child: Center( - child: Text(id, style: Theme.of(context).textTheme.headline3), - ), + child: Center( + child: Text(id, style: Theme.of(context).textTheme.headline3), ), ), ); diff --git a/packages/flutter/test/widgets/nested_scroll_view_test.dart b/packages/flutter/test/widgets/nested_scroll_view_test.dart index e472c21f8a..cf631e3add 100644 --- a/packages/flutter/test/widgets/nested_scroll_view_test.dart +++ b/packages/flutter/test/widgets/nested_scroll_view_test.dart @@ -2075,11 +2075,9 @@ void main() { body: ListView.builder( itemCount: 50, itemBuilder: (BuildContext context, int index) { - return Container( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Text('Item $index'), - ) + return Padding( + padding: const EdgeInsets.all(8.0), + child: Text('Item $index'), ); } ), diff --git a/packages/flutter/test/widgets/parent_data_test.dart b/packages/flutter/test/widgets/parent_data_test.dart index 0372e9c143..2e8d6a0370 100644 --- a/packages/flutter/test/widgets/parent_data_test.dart +++ b/packages/flutter/test/widgets/parent_data_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; @@ -179,8 +180,8 @@ void main() { right: 10.0, child: Container(child: kDecoratedBoxB), ), - Container( - child: const Positioned( + const DummyWidget( + child: Positioned( top: 8.0, child: kDecoratedBoxC, ), @@ -293,7 +294,7 @@ void main() { await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, - child: Container( + child: DummyWidget( child: Row( children: const [ Positioned( @@ -319,7 +320,7 @@ void main() { 'Typically, Positioned widgets are placed directly inside Stack widgets.\n' 'The offending Positioned is currently placed inside a Row widget.\n' 'The ownership chain for the RenderObject that received the incompatible parent data was:\n' - ' DecoratedBox ← Positioned ← Row ← Container ← Directionality ← [root]' + ' DecoratedBox ← Positioned ← Row ← DummyWidget ← Directionality ← [root]' ), ); @@ -515,3 +516,12 @@ class RenderAnother extends RenderProxyBox { child.parentData = DummyParentData(); } } + +class DummyWidget extends StatelessWidget { + const DummyWidget({ Key? key, required this.child }) : super(key: key); + + final Widget child; + + @override + Widget build(BuildContext context) => child; +} diff --git a/packages/flutter/test/widgets/platform_view_test.dart b/packages/flutter/test/widgets/platform_view_test.dart index cb6fbe7eae..f77193bd1a 100644 --- a/packages/flutter/test/widgets/platform_view_test.dart +++ b/packages/flutter/test/widgets/platform_view_test.dart @@ -230,12 +230,10 @@ void main() { await tester.pumpWidget( Center( - child: Container( - child: SizedBox( - width: 200.0, - height: 100.0, - child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr, key: key), - ), + child: SizedBox( + width: 200.0, + height: 100.0, + child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr, key: key), ), ), ); @@ -1337,12 +1335,10 @@ void main() { await tester.pumpWidget( Center( - child: Container( - child: SizedBox( - width: 200.0, - height: 100.0, - child: UiKitView(viewType: 'webview', layoutDirection: TextDirection.ltr, key: key), - ), + child: SizedBox( + width: 200.0, + height: 100.0, + child: UiKitView(viewType: 'webview', layoutDirection: TextDirection.ltr, key: key), ), ), ); @@ -2348,12 +2344,10 @@ void main() { await tester.pumpWidget( Center( - child: Container( - child: SizedBox( - width: 200.0, - height: 100.0, - child: createPlatformViewLink(), - ), + child: SizedBox( + width: 200.0, + height: 100.0, + child: createPlatformViewLink(), ), ), ); diff --git a/packages/flutter/test/widgets/reparent_state_test.dart b/packages/flutter/test/widgets/reparent_state_test.dart index 3d29162e61..b06cd62f24 100644 --- a/packages/flutter/test/widgets/reparent_state_test.dart +++ b/packages/flutter/test/widgets/reparent_state_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; @@ -59,9 +60,11 @@ void main() { textDirection: TextDirection.ltr, children: [ Container( + color: Colors.green, child: StateMarker(key: left), ), Container( + color: Colors.green, child: StateMarker( key: right, child: grandchild, @@ -86,12 +89,14 @@ void main() { textDirection: TextDirection.ltr, children: [ Container( + color: Colors.green, child: StateMarker( key: right, child: newGrandchild, ), ), Container( + color: Colors.green, child: StateMarker(key: left), ), ], @@ -111,6 +116,7 @@ void main() { await tester.pumpWidget( Center( child: Container( + color: Colors.green, child: StateMarker( key: left, child: Container(), @@ -178,6 +184,7 @@ void main() { await tester.pumpWidget( Center( child: Container( + color: Colors.green, child: StateMarker( key: left, child: Container(), diff --git a/packages/flutter/test/widgets/reparent_state_with_layout_builder_test.dart b/packages/flutter/test/widgets/reparent_state_with_layout_builder_test.dart index 6eace99c88..78026985fd 100644 --- a/packages/flutter/test/widgets/reparent_state_with_layout_builder_test.dart +++ b/packages/flutter/test/widgets/reparent_state_with_layout_builder_test.dart @@ -111,11 +111,17 @@ void main() { ); }), Container( + color: Colors.green, child: Container( + color: Colors.green, child: Container( + color: Colors.green, child: Container( + color: Colors.green, child: Container( + color: Colors.green, child: Container( + color: Colors.green, child: StatefulBuilder( builder: (BuildContext context, StateSetter setState) { childSetState = setState; diff --git a/packages/flutter/test/widgets/route_notification_messages_test.dart b/packages/flutter/test/widgets/route_notification_messages_test.dart index 26cad6947f..abb200b9ac 100644 --- a/packages/flutter/test/widgets/route_notification_messages_test.dart +++ b/packages/flutter/test/widgets/route_notification_messages_test.dart @@ -21,10 +21,8 @@ class OnTapPage extends StatelessWidget { body: GestureDetector( onTap: onTap, behavior: HitTestBehavior.opaque, - child: Container( - child: Center( - child: Text(id, style: Theme.of(context).textTheme.headline3), - ), + child: Center( + child: Text(id, style: Theme.of(context).textTheme.headline3), ), ), ); diff --git a/packages/flutter/test/widgets/scroll_position_test.dart b/packages/flutter/test/widgets/scroll_position_test.dart index 3df8dc9d5f..746a9f7e14 100644 --- a/packages/flutter/test/widgets/scroll_position_test.dart +++ b/packages/flutter/test/widgets/scroll_position_test.dart @@ -39,13 +39,13 @@ Future performTest(WidgetTester tester, bool maintainState) async { if (settings.name == '/') { return MaterialPageRoute( settings: settings, - builder: (_) => Container(child: const ThePositiveNumbers(from: 0)), + builder: (_) => const ThePositiveNumbers(from: 0), maintainState: maintainState, ); } else if (settings.name == '/second') { return MaterialPageRoute( settings: settings, - builder: (_) => Container(child: const ThePositiveNumbers(from: 10000)), + builder: (_) => const ThePositiveNumbers(from: 10000), maintainState: maintainState, ); } diff --git a/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart b/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart index cdd2c5bcf2..27a4bbb16c 100644 --- a/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart +++ b/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart @@ -64,12 +64,10 @@ void main() { itemExtent: 290.0, scrollDirection: Axis.vertical, children: items.map((int item) { - return Container( - child: GestureDetector( - onTap: () { tapped.add(item); }, - child: Text('$item'), - dragStartBehavior: DragStartBehavior.down, - ), + return GestureDetector( + onTap: () { tapped.add(item); }, + child: Text('$item'), + dragStartBehavior: DragStartBehavior.down, ); }).toList(), ), @@ -107,11 +105,9 @@ void main() { itemExtent: 290.0, padding: const EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0), children: items.map((int item) { - return Container( - child: GestureDetector( - onTap: () { tapped.add(item); }, - child: Text('$item'), - ), + return GestureDetector( + onTap: () { tapped.add(item); }, + child: Text('$item'), ); }).toList(), ), @@ -142,11 +138,9 @@ void main() { reverse: true, padding: const EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0), children: items.map((int item) { - return Container( - child: GestureDetector( - onTap: () { tapped.add(item); }, - child: Text('$item'), - ), + return GestureDetector( + onTap: () { tapped.add(item); }, + child: Text('$item'), ); }).toList(), ), @@ -176,11 +170,9 @@ void main() { child: ListView( itemExtent: 200.0, children: items.map((int item) { - return Container( - child: GestureDetector( - onTap: () { tapped.add(item); }, - child: Text('$item'), - ), + return GestureDetector( + onTap: () { tapped.add(item); }, + child: Text('$item'), ); }).toList(), ), diff --git a/packages/flutter/test/widgets/scrollable_restoration_test.dart b/packages/flutter/test/widgets/scrollable_restoration_test.dart index 984f680a96..0c84f91cc8 100644 --- a/packages/flutter/test/widgets/scrollable_restoration_test.dart +++ b/packages/flutter/test/widgets/scrollable_restoration_test.dart @@ -269,9 +269,7 @@ void main() { restorationId: 'pager', children: List.generate( 50, - (int index) => Container( - child: Text('Tile $index'), - ), + (int index) => Text('Tile $index'), ), ), ), @@ -325,9 +323,7 @@ void main() { itemExtent: 50, children: List.generate( 50, - (int index) => Container( - child: Text('Tile $index'), - ), + (int index) => Text('Tile $index'), ), ), ), diff --git a/packages/flutter/test/widgets/scrollable_test.dart b/packages/flutter/test/widgets/scrollable_test.dart index 42168a37dd..d38da79b9d 100644 --- a/packages/flutter/test/widgets/scrollable_test.dart +++ b/packages/flutter/test/widgets/scrollable_test.dart @@ -1157,31 +1157,29 @@ void main() { home: Scaffold( body: SingleChildScrollView( controller: outerController, - child: Container( - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Column( - children: [ - for (int i = 0; i < 100; i++) - Text('SingleChildScrollView $i'), - ] - ), - SizedBox( - height: 3000, - width: 400, - child: ListView.builder( - controller: innerController, - physics: const NeverScrollableScrollPhysics(), - itemCount: 100, - itemBuilder: (BuildContext context, int index) { - return Text('Nested NeverScrollable ListView $index'); - }, - ) - ), - ] - ) + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Column( + children: [ + for (int i = 0; i < 100; i++) + Text('SingleChildScrollView $i'), + ] + ), + SizedBox( + height: 3000, + width: 400, + child: ListView.builder( + controller: innerController, + physics: const NeverScrollableScrollPhysics(), + itemCount: 100, + itemBuilder: (BuildContext context, int index) { + return Text('Nested NeverScrollable ListView $index'); + }, + ) + ), + ] ) ) ), diff --git a/packages/flutter/test/widgets/semantics_1_test.dart b/packages/flutter/test/widgets/semantics_1_test.dart index a3acb1f938..8161794c51 100644 --- a/packages/flutter/test/widgets/semantics_1_test.dart +++ b/packages/flutter/test/widgets/semantics_1_test.dart @@ -16,13 +16,11 @@ void main() { await tester.pumpWidget( Semantics( container: true, - child: Container( - child: Semantics( - label: 'test1', - textDirection: TextDirection.ltr, - child: Container(), - selected: true, - ), + child: Semantics( + label: 'test1', + textDirection: TextDirection.ltr, + child: Container(), + selected: true, ), ), ); diff --git a/packages/flutter/test/widgets/semantics_3_test.dart b/packages/flutter/test/widgets/semantics_3_test.dart index 53a6b1753c..1ee92a1c7d 100644 --- a/packages/flutter/test/widgets/semantics_3_test.dart +++ b/packages/flutter/test/widgets/semantics_3_test.dart @@ -16,15 +16,11 @@ void main() { await tester.pumpWidget( Semantics( container: true, - child: Container( + child: Semantics( + label: 'test', + textDirection: TextDirection.ltr, child: Semantics( - label: 'test', - textDirection: TextDirection.ltr, - child: Container( - child: Semantics( - checked: true - ), - ), + checked: true ), ), ), @@ -47,10 +43,8 @@ void main() { await tester.pumpWidget( Semantics( container: true, - child: Container( - child: Semantics( - checked: true, - ), + child: Semantics( + checked: true, ), ), ); @@ -71,11 +65,9 @@ void main() { await tester.pumpWidget( Semantics( container: true, - child: Container( - child: Semantics( - label: 'test', - textDirection: TextDirection.ltr, - ), + child: Semantics( + label: 'test', + textDirection: TextDirection.ltr, ), ), ); @@ -97,13 +89,11 @@ void main() { await tester.pumpWidget( Semantics( container: true, - child: Container( + child: Semantics( + checked: true, child: Semantics( - checked: true, - child: Semantics( - label: 'test', - textDirection: TextDirection.ltr, - ), + label: 'test', + textDirection: TextDirection.ltr, ), ), ), @@ -131,13 +121,11 @@ void main() { await tester.pumpWidget( Semantics( container: true, - child: Container( + child: Semantics( + checked: true, child: Semantics( - checked: true, - child: Semantics( - label: 'test', - textDirection: TextDirection.ltr, - ), + label: 'test', + textDirection: TextDirection.ltr, ), ), ), diff --git a/packages/flutter/test/widgets/semantics_test.dart b/packages/flutter/test/widgets/semantics_test.dart index 8f418e285e..4ba7368fe2 100644 --- a/packages/flutter/test/widgets/semantics_test.dart +++ b/packages/flutter/test/widgets/semantics_test.dart @@ -30,12 +30,10 @@ void main() { ); await tester.pumpWidget( - Container( - child: Semantics( - label: 'test1', - textDirection: TextDirection.ltr, - child: Container(), - ), + Semantics( + label: 'test1', + textDirection: TextDirection.ltr, + child: Container(), ), ); @@ -69,15 +67,13 @@ void main() { await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, - child: Container( + child: Semantics( + label: 'test1', child: Semantics( - label: 'test1', - child: Semantics( - key: key, - container: true, - label: 'test2a', - child: Container(), - ), + key: key, + container: true, + label: 'test2a', + child: Container(), ), ), )); @@ -102,18 +98,16 @@ void main() { await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, - child: Container( + child: Semantics( + label: 'test1', child: Semantics( - label: 'test1', + container: true, + label: 'middle', child: Semantics( + key: key, container: true, - label: 'middle', - child: Semantics( - key: key, - container: true, - label: 'test2b', - child: Container(), - ), + label: 'test2b', + child: Container(), ), ), ), diff --git a/packages/flutter/test/widgets/semantics_traversal_test.dart b/packages/flutter/test/widgets/semantics_traversal_test.dart index 5d2ed87b67..99ca3ea92a 100644 --- a/packages/flutter/test/widgets/semantics_traversal_test.dart +++ b/packages/flutter/test/widgets/semantics_traversal_test.dart @@ -295,30 +295,28 @@ class TraversalTester { }) async { assert(children is LinkedHashMap); await tester.pumpWidget( - Container( - child: Directionality( - textDirection: textDirection, - child: Semantics( - textDirection: textDirection, - child: CustomMultiChildLayout( - delegate: TestLayoutDelegate(children), - children: children.keys.map((String label) { - return LayoutId( - id: label, - child: Semantics( - container: true, - explicitChildNodes: true, - label: label, - child: SizedBox( - width: children[label]!.width, - height: children[label]!.height, - ), - ), - ); - }).toList(), - ), - ), + Directionality( + textDirection: textDirection, + child: Semantics( + textDirection: textDirection, + child: CustomMultiChildLayout( + delegate: TestLayoutDelegate(children), + children: children.keys.map((String label) { + return LayoutId( + id: label, + child: Semantics( + container: true, + explicitChildNodes: true, + label: label, + child: SizedBox( + width: children[label]!.width, + height: children[label]!.height, + ), + ), + ); + }).toList(), ), + ), ), ); diff --git a/packages/flutter/test/widgets/sliver_fill_viewport_test.dart b/packages/flutter/test/widgets/sliver_fill_viewport_test.dart index 33cf314da5..c2243894b4 100644 --- a/packages/flutter/test/widgets/sliver_fill_viewport_test.dart +++ b/packages/flutter/test/widgets/sliver_fill_viewport_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; @@ -9,7 +10,7 @@ import 'package:flutter/widgets.dart'; void main() { testWidgets('SliverFillViewport control test', (WidgetTester tester) async { final List children = List.generate(20, (int i) { - return Container(child: Text('$i', textDirection: TextDirection.ltr)); + return Container(color: Colors.green, child: Text('$i', textDirection: TextDirection.ltr)); }); await tester.pumpWidget( @@ -102,21 +103,27 @@ void main() { ' │ │ diagnosis: insufficient data to draw conclusion (less than five\n' ' │ │ repaints)\n' ' │ │\n' - ' │ └─child: RenderParagraph#00000\n' + ' │ └─child: _RenderColoredBox#00000\n' ' │ │ parentData: (can use size)\n' ' │ │ constraints: BoxConstraints(w=800.0, h=600.0)\n' - ' │ │ semantics node: SemanticsNode#2\n' ' │ │ size: Size(800.0, 600.0)\n' - ' │ │ textAlign: start\n' - ' │ │ textDirection: ltr\n' - ' │ │ softWrap: wrapping at box width\n' - ' │ │ overflow: clip\n' - ' │ │ maxLines: unlimited\n' - ' │ ╘═╦══ text ═══\n' - ' │ ║ TextSpan:\n' - ' │ ║ \n' - ' │ ║ "0"\n' - ' │ ╚═══════════\n' + ' │ │ behavior: opaque\n' + ' │ │\n' + ' │ └─child: RenderParagraph#00000\n' + ' │ │ parentData: (can use size)\n' + ' │ │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ │ semantics node: SemanticsNode#2\n' + ' │ │ size: Size(800.0, 600.0)\n' + ' │ │ textAlign: start\n' + ' │ │ textDirection: ltr\n' + ' │ │ softWrap: wrapping at box width\n' + ' │ │ overflow: clip\n' + ' │ │ maxLines: unlimited\n' + ' │ ╘═╦══ text ═══\n' + ' │ ║ TextSpan:\n' + ' │ ║ \n' + ' │ ║ "0"\n' + ' │ ╚═══════════\n' ' └─child with index 1: RenderRepaintBoundary#00000\n' ' │ needs compositing\n' ' │ parentData: index=1; layoutOffset=600.0\n' @@ -127,22 +134,27 @@ void main() { ' │ diagnosis: insufficient data to draw conclusion (less than five\n' ' │ repaints)\n' ' │\n' - ' └─child: RenderParagraph#00000\n' + ' └─child: _RenderColoredBox#00000\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' - ' │ semantics node: SemanticsNode#3\n' ' │ size: Size(800.0, 600.0)\n' - ' │ textAlign: start\n' - ' │ textDirection: ltr\n' - ' │ softWrap: wrapping at box width\n' - ' │ overflow: clip\n' - ' │ maxLines: unlimited\n' - ' ╘═╦══ text ═══\n' - ' ║ TextSpan:\n' - ' ║ \n' - ' ║ "1"\n' - ' ╚═══════════\n' - '' + ' │ behavior: opaque\n' + ' │\n' + ' └─child: RenderParagraph#00000\n' + ' │ parentData: (can use size)\n' + ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' │ semantics node: SemanticsNode#3\n' + ' │ size: Size(800.0, 600.0)\n' + ' │ textAlign: start\n' + ' │ textDirection: ltr\n' + ' │ softWrap: wrapping at box width\n' + ' │ overflow: clip\n' + ' │ maxLines: unlimited\n' + ' ╘═╦══ text ═══\n' + ' ║ TextSpan:\n' + ' ║ \n' + ' ║ "1"\n' + ' ╚═══════════\n' ), ); }); @@ -150,7 +162,7 @@ void main() { testWidgets('SliverFillViewport padding test', (WidgetTester tester) async { final SliverChildListDelegate delegate = SliverChildListDelegate( [ - Container(child: const Text('0')), + const Text('0'), ], addAutomaticKeepAlives: false, addSemanticIndexes: false, diff --git a/packages/flutter/test/widgets/slivers_test.dart b/packages/flutter/test/widgets/slivers_test.dart index 28e329314f..58e3e5a60c 100644 --- a/packages/flutter/test/widgets/slivers_test.dart +++ b/packages/flutter/test/widgets/slivers_test.dart @@ -389,10 +389,10 @@ void main() { ), delegate: SliverChildListDelegate( [ - Container(child: const Center(child: Text('A'))), - Container(child: const Center(child: Text('B'))), - Container(child: const Center(child: Text('C'))), - Container(child: const Center(child: Text('D'))), + const Center(child: Text('A')), + const Center(child: Text('B')), + const Center(child: Text('C')), + const Center(child: Text('D')), ], ), ), @@ -952,15 +952,13 @@ void main() { SliverGrid( delegate: SliverChildBuilderDelegate( (BuildContext context, int index) { - return Container( - child: Material( - color: index.isEven ? Colors.yellow : Colors.red, - child: InkWell( - onTap: () { - index.isEven ? firstTapped++ : secondTapped++; - }, - child: Text('Index $index'), - ), + return Material( + color: index.isEven ? Colors.yellow : Colors.red, + child: InkWell( + onTap: () { + index.isEven ? firstTapped++ : secondTapped++; + }, + child: Text('Index $index'), ), ); }, diff --git a/packages/flutter/test/widgets/syncing_test.dart b/packages/flutter/test/widgets/syncing_test.dart index fdeaddbb31..fc72072ec6 100644 --- a/packages/flutter/test/widgets/syncing_test.dart +++ b/packages/flutter/test/widgets/syncing_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; @@ -51,7 +52,9 @@ void main() { testWidgets('no change', (WidgetTester tester) async { await tester.pumpWidget( Container( + color: Colors.blue, child: Container( + color: Colors.blue, child: TestWidget( persistentState: 1, syncedState: 0, @@ -68,7 +71,9 @@ void main() { await tester.pumpWidget( Container( + color: Colors.blue, child: Container( + color: Colors.blue, child: TestWidget( persistentState: 2, syncedState: 0, @@ -87,7 +92,9 @@ void main() { testWidgets('remove one', (WidgetTester tester) async { await tester.pumpWidget( Container( + color: Colors.blue, child: Container( + color: Colors.blue, child: TestWidget( persistentState: 10, syncedState: 0, @@ -104,6 +111,7 @@ void main() { await tester.pumpWidget( Container( + color: Colors.green, child: TestWidget( persistentState: 11, syncedState: 0, diff --git a/packages/flutter/test/widgets/text_test.dart b/packages/flutter/test/widgets/text_test.dart index 5bed549971..80f7e6cda2 100644 --- a/packages/flutter/test/widgets/text_test.dart +++ b/packages/flutter/test/widgets/text_test.dart @@ -872,14 +872,12 @@ void main() { MaterialApp( home: Scaffold( body: Center( - child: Container( - // Each word takes up more than a half of a line. Together they - // wrap onto two lines, but leave a lot of extra space. - child: Text( - 'twowordsthateachtakeupmorethanhalfof alineoftextsothattheywrapwithlotsofextraspace', - textDirection: TextDirection.ltr, - textWidthBasis: textWidthBasis, - ), + // Each word takes up more than a half of a line. Together they + // wrap onto two lines, but leave a lot of extra space. + child: Text( + 'twowordsthateachtakeupmorethanhalfof alineoftextsothattheywrapwithlotsofextraspace', + textDirection: TextDirection.ltr, + textWidthBasis: textWidthBasis, ), ), ), diff --git a/packages/flutter/test/widgets/ticker_provider_test.dart b/packages/flutter/test/widgets/ticker_provider_test.dart index 63364f8079..9f4354011d 100644 --- a/packages/flutter/test/widgets/ticker_provider_test.dart +++ b/packages/flutter/test/widgets/ticker_provider_test.dart @@ -98,9 +98,7 @@ void main() { testWidgets('SingleTickerProviderStateMixin dispose while active', (WidgetTester tester) async { final GlobalKey<_SingleTickerTestState> key = GlobalKey<_SingleTickerTestState>(); - final Widget widget = Container( - child: _SingleTickerTest(key: key), - ); + final Widget widget = _SingleTickerTest(key: key); await tester.pumpWidget(widget); FlutterError? error; key.currentState!.controller.repeat(); @@ -141,9 +139,7 @@ void main() { testWidgets('SingleTickerProviderStateMixin dispose while active', (WidgetTester tester) async { final GlobalKey<_SingleTickerTestState> key = GlobalKey<_SingleTickerTestState>(); - final Widget widget = Container( - child: _SingleTickerTest(key: key), - ); + final Widget widget = _SingleTickerTest(key: key); await tester.pumpWidget(widget); FlutterError? error; key.currentState!.controller.repeat(); @@ -184,9 +180,7 @@ void main() { testWidgets('ProviderStateMixin dispose while any ticker is active', (WidgetTester tester) async { final GlobalKey<_MultipleTickerTestState> key = GlobalKey<_MultipleTickerTestState>(); - final Widget widget = Container( - child: _MultipleTickerTest(key: key), - ); + final Widget widget = _MultipleTickerTest(key: key); await tester.pumpWidget(widget); FlutterError? error; key.currentState!.controllers.first.repeat(); diff --git a/packages/flutter_test/test/controller_test.dart b/packages/flutter_test/test/controller_test.dart index 04a7ed201a..19148a3405 100644 --- a/packages/flutter_test/test/controller_test.dart +++ b/packages/flutter_test/test/controller_test.dart @@ -61,11 +61,9 @@ void main() { await tester.pumpWidget( MaterialApp( home: Scaffold( - body: Container( - child: OutlinedButton( - onPressed: () { }, - child: const Text('hello'), - ), + body: OutlinedButton( + onPressed: () { }, + child: const Text('hello'), ), ), ), @@ -83,11 +81,9 @@ void main() { await tester.pumpWidget( MaterialApp( home: Scaffold( - body: Container( - child: OutlinedButton( - onPressed: () { }, - child: const Text('hello'), - ), + body: OutlinedButton( + onPressed: () { }, + child: const Text('hello'), ), ), ), @@ -717,7 +713,7 @@ void main() { shrinkWrap: true, scrollDirection: Axis.horizontal, // ListTile does not support horizontal list - itemBuilder: (BuildContext context, int i) => Container(child: Text('Item $i')), + itemBuilder: (BuildContext context, int i) => Text('Item $i'), ), ), ), diff --git a/packages/flutter_test/test/finders_test.dart b/packages/flutter_test/test/finders_test.dart index e01630296f..756fa3c661 100644 --- a/packages/flutter_test/test/finders_test.dart +++ b/packages/flutter_test/test/finders_test.dart @@ -153,9 +153,7 @@ void main() { key: key1, child: const Text('1'), ), - Container( - child: const Text('2'), - ), + const Text('2'), ], )), );