From 3961a12a6dfacaff35e7ab270dd3b040107b92d0 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Wed, 7 Oct 2020 10:11:24 -0700 Subject: [PATCH] Migrate some material tests to nnbd (#67477) --- .../flutter/lib/src/material/popup_menu.dart | 3 +- .../test/material/navigation_rail_test.dart | 34 ++++--- .../material/navigation_rail_theme_test.dart | 6 +- .../test/material/outlined_button_test.dart | 94 +++++++++---------- .../material/outlined_button_theme_test.dart | 26 +++-- .../test/material/page_selector_test.dart | 4 +- packages/flutter/test/material/page_test.dart | 94 ++++++++----------- .../material/page_transitions_theme_test.dart | 22 ++--- .../material/paginated_data_table_test.dart | 34 ++++--- .../persistent_bottom_sheet_test.dart | 27 +++--- .../test/material/popup_menu_test.dart | 87 +++++------------ .../test/material/popup_menu_theme_test.dart | 10 +- 12 files changed, 185 insertions(+), 256 deletions(-) diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index 8891a4e8c6..c86d124bdc 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -96,8 +96,7 @@ abstract class PopupMenuEntry extends StatefulWidget { /// * [showMenu], a method to dynamically show a popup menu at a given location. /// * [PopupMenuButton], an [IconButton] that automatically shows a menu when /// it is tapped. -// ignore: prefer_void_to_null, https://github.com/dart-lang/sdk/issues/34416 -class PopupMenuDivider extends PopupMenuEntry { +class PopupMenuDivider extends PopupMenuEntry { /// Creates a horizontal divider for a popup menu. /// /// By default, the divider has a height of 16 logical pixels. diff --git a/packages/flutter/test/material/navigation_rail_test.dart b/packages/flutter/test/material/navigation_rail_test.dart index d85dfb2341..11e72535dd 100644 --- a/packages/flutter/test/material/navigation_rail_test.dart +++ b/packages/flutter/test/material/navigation_rail_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -26,8 +24,8 @@ void main() { ), ); - final TextStyle actualSelectedTextStyle = tester.renderObject(find.text('Abc')).text.style; - final TextStyle actualUnselectedTextStyle = tester.renderObject(find.text('Def')).text.style; + final TextStyle actualSelectedTextStyle = tester.renderObject(find.text('Abc')).text.style!; + final TextStyle actualUnselectedTextStyle = tester.renderObject(find.text('Def')).text.style!; expect(actualSelectedTextStyle.fontSize, equals(selectedTextStyle.fontSize)); expect(actualSelectedTextStyle.fontWeight, equals(selectedTextStyle.fontWeight)); expect(actualUnselectedTextStyle.fontSize, equals(actualUnselectedTextStyle.fontSize)); @@ -1416,7 +1414,7 @@ void main() { testWidgets('Extended rail animates the width and labels appear - [textDirection]=LTR', (WidgetTester tester) async { bool extended = false; - StateSetter stateSetter; + late StateSetter stateSetter; await tester.pumpWidget( MaterialApp( @@ -1553,7 +1551,7 @@ void main() { testWidgets('Extended rail animates the width and labels appear - [textDirection]=RTL', (WidgetTester tester) async { bool extended = false; - StateSetter stateSetter; + late StateSetter stateSetter; await tester.pumpWidget( MaterialApp( @@ -1697,7 +1695,7 @@ void main() { testWidgets('Extended rail gets wider with longer labels are larger text scale', (WidgetTester tester) async { bool extended = false; - StateSetter stateSetter; + late StateSetter stateSetter; await tester.pumpWidget( MaterialApp( @@ -1708,7 +1706,7 @@ void main() { body: Row( children: [ MediaQuery( - data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0), + data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0), child: NavigationRail( selectedIndex: 0, destinations: const [ @@ -1755,7 +1753,7 @@ void main() { testWidgets('Extended rail final width can be changed', (WidgetTester tester) async { bool extended = false; - StateSetter stateSetter; + late StateSetter stateSetter; await tester.pumpWidget( MaterialApp( @@ -1797,7 +1795,7 @@ void main() { /// Regression test for https://github.com/flutter/flutter/issues/65657 testWidgets('Extended rail transition does not jump from the beginning', (WidgetTester tester) async { bool extended = false; - StateSetter stateSetter; + late StateSetter stateSetter; await tester.pumpWidget( MaterialApp( @@ -1855,8 +1853,8 @@ void main() { testWidgets('Extended rail animation can be consumed', (WidgetTester tester) async { bool extended = false; - Animation animation; - StateSetter stateSetter; + late Animation animation; + late StateSetter stateSetter; await tester.pumpWidget( MaterialApp( @@ -1899,7 +1897,7 @@ void main() { }); testWidgets('onDestinationSelected is called', (WidgetTester tester) async { - int selectedIndex; + late int selectedIndex; await _pumpNavigationRail( tester, @@ -2106,14 +2104,14 @@ List _destinations() { Future _pumpNavigationRail( WidgetTester tester, { double textScaleFactor = 1.0, - NavigationRail navigationRail, + required NavigationRail navigationRail, }) async { await tester.pumpWidget( MaterialApp( home: Builder( builder: (BuildContext context) { return MediaQuery( - data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor), + data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor), child: Scaffold( body: Row( children: [ @@ -2131,7 +2129,7 @@ Future _pumpNavigationRail( ); } -Future _pumpLocalizedTestRail(WidgetTester tester, { NavigationRailLabelType labelType, bool extended = false }) async { +Future _pumpLocalizedTestRail(WidgetTester tester, { NavigationRailLabelType? labelType, bool extended = false }) async { await tester.pumpWidget( Localizations( locale: const Locale('en', 'US'), @@ -2184,7 +2182,7 @@ TextStyle _iconStyle(WidgetTester tester, IconData icon) { of: find.byIcon(icon), matching: find.byType(RichText), ), - ).text.style; + ).text.style!; } Finder _opacityAboveLabel(String text) { @@ -2213,4 +2211,4 @@ Material _railMaterial(WidgetTester tester) { matching: find.byType(Material), ), ); -} \ No newline at end of file +} diff --git a/packages/flutter/test/material/navigation_rail_theme_test.dart b/packages/flutter/test/material/navigation_rail_theme_test.dart index 2787bb3fc2..72dc6b10f2 100644 --- a/packages/flutter/test/material/navigation_rail_theme_test.dart +++ b/packages/flutter/test/material/navigation_rail_theme_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; @@ -271,7 +269,7 @@ TextStyle _selectedLabelStyle(WidgetTester tester) { of: find.text('Abc'), matching: find.byType(RichText), ), - ).text.style; + ).text.style!; } TextStyle _unselectedLabelStyle(WidgetTester tester) { @@ -280,7 +278,7 @@ TextStyle _unselectedLabelStyle(WidgetTester tester) { of: find.text('Def'), matching: find.byType(RichText), ), - ).text.style; + ).text.style!; } Align _destinationsAlign(WidgetTester tester) { diff --git a/packages/flutter/test/material/outlined_button_test.dart b/packages/flutter/test/material/outlined_button_test.dart index 80be500701..8c315a1196 100644 --- a/packages/flutter/test/material/outlined_button_test.dart +++ b/packages/flutter/test/material/outlined_button_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -49,10 +47,10 @@ void main() { ), borderRadius: BorderRadius.circular(4.0), )); - expect(material.textStyle.color, colorScheme.primary); - expect(material.textStyle.fontFamily, 'Roboto'); - expect(material.textStyle.fontSize, 14); - expect(material.textStyle.fontWeight, FontWeight.w500); + expect(material.textStyle!.color, colorScheme.primary); + expect(material.textStyle!.fontFamily, 'Roboto'); + expect(material.textStyle!.fontSize, 14); + expect(material.textStyle!.fontWeight, FontWeight.w500); expect(material.type, MaterialType.button); final Offset center = tester.getCenter(find.byType(OutlinedButton)); @@ -80,10 +78,10 @@ void main() { ), borderRadius: BorderRadius.circular(4.0), )); - expect(material.textStyle.color, colorScheme.primary); - expect(material.textStyle.fontFamily, 'Roboto'); - expect(material.textStyle.fontSize, 14); - expect(material.textStyle.fontWeight, FontWeight.w500); + expect(material.textStyle!.color, colorScheme.primary); + expect(material.textStyle!.fontFamily, 'Roboto'); + expect(material.textStyle!.fontSize, 14); + expect(material.textStyle!.fontWeight, FontWeight.w500); expect(material.type, MaterialType.button); // Disabled OutlinedButton @@ -114,17 +112,17 @@ void main() { ), borderRadius: BorderRadius.circular(4.0), )); - expect(material.textStyle.color, colorScheme.onSurface.withOpacity(0.38)); - expect(material.textStyle.fontFamily, 'Roboto'); - expect(material.textStyle.fontSize, 14); - expect(material.textStyle.fontWeight, FontWeight.w500); + expect(material.textStyle!.color, colorScheme.onSurface.withOpacity(0.38)); + expect(material.textStyle!.fontFamily, 'Roboto'); + expect(material.textStyle!.fontSize, 14); + expect(material.textStyle!.fontWeight, FontWeight.w500); expect(material.type, MaterialType.button); }); testWidgets('Does OutlinedButton work with hover', (WidgetTester tester) async { const Color hoverColor = Color(0xff001122); - Color getOverlayColor(Set states) { + Color? getOverlayColor(Set states) { return states.contains(MaterialState.hovered) ? hoverColor : null; } @@ -133,7 +131,7 @@ void main() { textDirection: TextDirection.ltr, child: OutlinedButton( style: ButtonStyle( - overlayColor: MaterialStateProperty.resolveWith(getOverlayColor), + overlayColor: MaterialStateProperty.resolveWith(getOverlayColor), ), onPressed: () { }, child: const Text('button'), @@ -154,7 +152,7 @@ void main() { testWidgets('Does OutlinedButton work with focus', (WidgetTester tester) async { const Color focusColor = Color(0xff001122); - Color getOverlayColor(Set states) { + Color? getOverlayColor(Set states) { return states.contains(MaterialState.focused) ? focusColor : null; } @@ -164,7 +162,7 @@ void main() { textDirection: TextDirection.ltr, child: OutlinedButton( style: ButtonStyle( - overlayColor: MaterialStateProperty.resolveWith(getOverlayColor), + overlayColor: MaterialStateProperty.resolveWith(getOverlayColor), ), focusNode: focusNode, onPressed: () { }, @@ -184,7 +182,7 @@ void main() { testWidgets('Does OutlinedButton work with autofocus', (WidgetTester tester) async { const Color focusColor = Color(0xff001122); - Color getOverlayColor(Set states) { + Color? getOverlayColor(Set states) { return states.contains(MaterialState.focused) ? focusColor : null; } @@ -195,7 +193,7 @@ void main() { child: OutlinedButton( autofocus: true, style: ButtonStyle( - overlayColor: MaterialStateProperty.resolveWith(getOverlayColor), + overlayColor: MaterialStateProperty.resolveWith(getOverlayColor), ), focusNode: focusNode, onPressed: () { }, @@ -268,9 +266,9 @@ void main() { MaterialState.focused, }; if (states.any(interactiveStates.contains)) { - return Colors.blue[900]; + return Colors.blue[900]!; } - return Colors.blue[800]; + return Colors.blue[800]!; } await tester.pumpWidget( @@ -368,7 +366,7 @@ void main() { ); Color textColor() { - return tester.renderObject(find.text('OutlinedButton')).text.style.color; + return tester.renderObject(find.text('OutlinedButton')).text.style!.color!; } // Default, not disabled. @@ -438,7 +436,7 @@ void main() { ), ); - Color iconColor() => _iconStyle(tester, Icons.add).color; + Color iconColor() => _iconStyle(tester, Icons.add).color!; // Default, not disabled. expect(iconColor(), equals(defaultColor)); @@ -535,7 +533,7 @@ void main() { bool wasPressed; Finder outlinedButton; - Widget buildFrame({ VoidCallback onPressed, VoidCallback onLongPress }) { + Widget buildFrame({ VoidCallback? onPressed, VoidCallback? onLongPress }) { return Directionality( textDirection: TextDirection.ltr, child: OutlinedButton( @@ -575,7 +573,7 @@ void main() { }); testWidgets("Outline button doesn't crash if disabled during a gesture", (WidgetTester tester) async { - Widget buildFrame(VoidCallback onPressed) { + Widget buildFrame(VoidCallback? onPressed) { return Directionality( textDirection: TextDirection.ltr, child: Theme( @@ -600,7 +598,7 @@ void main() { const BorderSide enabledBorderSide = BorderSide(color: Color(0xFFFF00FF), width: 4); const BorderSide pressedBorderSide = BorderSide(color: Color(0xFF0000FF), width: 5); - Widget buildFrame({ VoidCallback onPressed }) { + Widget buildFrame({ VoidCallback? onPressed }) { return Directionality( textDirection: TextDirection.ltr, child: Theme( @@ -946,7 +944,7 @@ void main() { const List textScaleFactorOptions = [0.5, 1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 4.0]; const List textDirectionOptions = [TextDirection.ltr, TextDirection.rtl]; - const List iconOptions = [null, Icon(Icons.add, size: 18, key: iconKey)]; + const List iconOptions = [null, Icon(Icons.add, size: 18, key: iconKey)]; // Expected values for each textScaleFactor. final Map paddingVertical = { @@ -986,7 +984,7 @@ void main() { } /// Computes the padding between two [Rect]s, one inside the other. - EdgeInsets paddingBetween({ Rect parent, Rect child }) { + EdgeInsets paddingBetween({ required Rect parent, required Rect child }) { assert (parent.intersect(child) == child); return EdgeInsets.fromLTRB( child.left - parent.left, @@ -998,7 +996,7 @@ void main() { for (final double textScaleFactor in textScaleFactorOptions) { for (final TextDirection textDirection in textDirectionOptions) { - for (final Widget icon in iconOptions) { + for (final Widget? icon in iconOptions) { final String testName = 'OutlinedButton' ', text scale $textScaleFactor' '${icon != null ? ", with icon" : ""}' @@ -1011,7 +1009,7 @@ void main() { home: Builder( builder: (BuildContext context) { return MediaQuery( - data: MediaQuery.of(context).copyWith( + data: MediaQuery.of(context)!.copyWith( textScaleFactor: textScaleFactor, ), child: Directionality( @@ -1050,9 +1048,9 @@ void main() { // Compute expected padding, and check. - final double expectedPaddingTop = paddingVertical[textScaleFactor]; - final double expectedPaddingBottom = paddingVertical[textScaleFactor]; - final double expectedPaddingStart = paddingHorizontal[textScaleFactor]; + final double expectedPaddingTop = paddingVertical[textScaleFactor]!; + final double expectedPaddingBottom = paddingVertical[textScaleFactor]!; + final double expectedPaddingStart = paddingHorizontal[textScaleFactor]!; final double expectedPaddingEnd = expectedPaddingStart; final EdgeInsets expectedPadding = EdgeInsetsDirectional.fromSTEB( @@ -1069,9 +1067,9 @@ void main() { final RenderBox labelRenderBox = tester.renderObject(find.byKey(labelKey)); final Rect labelBounds = globalBounds(labelRenderBox); - final RenderBox iconRenderBox = icon == null ? null : tester.renderObject(find.byKey(iconKey)); - final Rect iconBounds = icon == null ? null : globalBounds(iconRenderBox); - final Rect childBounds = icon == null ? labelBounds : labelBounds.expandToInclude(iconBounds); + final RenderBox? iconRenderBox = icon == null ? null : tester.renderObject(find.byKey(iconKey)); + final Rect? iconBounds = icon == null ? null : globalBounds(iconRenderBox!); + final Rect childBounds = icon == null ? labelBounds : labelBounds.expandToInclude(iconBounds!); // We measure the `InkResponse` descendant of the button // element, because the button has a larger `RenderBox` @@ -1120,8 +1118,8 @@ void main() { // Check the gap between the icon and the label if (icon != null) { final double gapWidth = textDirection == TextDirection.ltr - ? labelBounds.left - iconBounds.right - : iconBounds.left - labelBounds.right; + ? labelBounds.left - iconBounds!.right + : iconBounds!.left - labelBounds.right; expect(gapWidth, paddingWithIconGap[textScaleFactor]); } @@ -1150,7 +1148,7 @@ void main() { home: Builder( builder: (BuildContext context) { return MediaQuery( - data: MediaQuery.of(context).copyWith( + data: MediaQuery.of(context)!.copyWith( textScaleFactor: 2, ), child: Scaffold( @@ -1180,24 +1178,24 @@ void main() { PhysicalModelLayer _findPhysicalLayer(Element element) { expect(element, isNotNull); - RenderObject object = element.renderObject; + RenderObject? object = element.renderObject; while (object != null && object is! RenderRepaintBoundary && object is! RenderView) { object = object.parent as RenderObject; } - expect(object.debugLayer, isNotNull); - expect(object.debugLayer.firstChild, isA()); - final PhysicalModelLayer layer = object.debugLayer.firstChild as PhysicalModelLayer; - final Layer child = layer.firstChild; + expect(object!.debugLayer, isNotNull); + expect(object.debugLayer!.firstChild, isA()); + final PhysicalModelLayer layer = object.debugLayer!.firstChild as PhysicalModelLayer; + final Layer child = layer.firstChild!; return child is PhysicalModelLayer ? child : layer; } -void _checkPhysicalLayer(Element element, Color expectedColor, { Path clipPath, Rect clipRect }) { +void _checkPhysicalLayer(Element element, Color expectedColor, { Path? clipPath, Rect? clipRect }) { final PhysicalModelLayer expectedLayer = _findPhysicalLayer(element); expect(expectedLayer.elevation, 0.0); expect(expectedLayer.color, expectedColor); if (clipPath != null) { expect(clipRect, isNotNull); - expect(expectedLayer.clipPath, coversSameAreaAs(clipPath, areaToCompare: clipRect.inflate(10.0))); + expect(expectedLayer.clipPath, coversSameAreaAs(clipPath, areaToCompare: clipRect!.inflate(10.0))); } } @@ -1205,5 +1203,5 @@ TextStyle _iconStyle(WidgetTester tester, IconData icon) { final RichText iconRichText = tester.widget( find.descendant(of: find.byIcon(icon), matching: find.byType(RichText)), ); - return iconRichText.text.style; + return iconRichText.text.style!; } diff --git a/packages/flutter/test/material/outlined_button_theme_test.dart b/packages/flutter/test/material/outlined_button_theme_test.dart index dde81e7a5c..fb1ff3b71d 100644 --- a/packages/flutter/test/material/outlined_button_theme_test.dart +++ b/packages/flutter/test/material/outlined_button_theme_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -40,10 +38,10 @@ void main() { side: BorderSide(width: 1, color: colorScheme.onSurface.withOpacity(0.12)), borderRadius: BorderRadius.circular(4.0), )); - expect(material.textStyle.color, colorScheme.primary); - expect(material.textStyle.fontFamily, 'Roboto'); - expect(material.textStyle.fontSize, 14); - expect(material.textStyle.fontWeight, FontWeight.w500); + expect(material.textStyle!.color, colorScheme.primary); + expect(material.textStyle!.fontFamily, 'Roboto'); + expect(material.textStyle!.fontSize, 14); + expect(material.textStyle!.fontWeight, FontWeight.w500); }); group('[Theme, TextTheme, OutlinedButton style overrides]', () { @@ -81,7 +79,7 @@ void main() { enableFeedback: enableFeedback, ); - Widget buildFrame({ ButtonStyle buttonStyle, ButtonStyle themeStyle, ButtonStyle overallStyle }) { + Widget buildFrame({ ButtonStyle? buttonStyle, ButtonStyle? themeStyle, ButtonStyle? overallStyle }) { final Widget child = Builder( builder: (BuildContext context) { return OutlinedButton( @@ -126,15 +124,15 @@ void main() { void checkButton(WidgetTester tester) { final Material material = tester.widget(findMaterial); final InkWell inkWell = tester.widget(findInkWell); - expect(material.textStyle.color, primaryColor); - expect(material.textStyle.fontSize, 12); + expect(material.textStyle!.color, primaryColor); + expect(material.textStyle!.fontSize, 12); expect(material.color, backgroundColor); expect(material.shadowColor, shadowColor); expect(material.elevation, elevation); - expect(MaterialStateProperty.resolveAs(inkWell.mouseCursor, enabled), enabledMouseCursor); - expect(MaterialStateProperty.resolveAs(inkWell.mouseCursor, disabled), disabledMouseCursor); - expect(inkWell.overlayColor.resolve(hovered), primaryColor.withOpacity(0.04)); - expect(inkWell.overlayColor.resolve(focused), primaryColor.withOpacity(0.12)); + expect(MaterialStateProperty.resolveAs(inkWell.mouseCursor, enabled), enabledMouseCursor); + expect(MaterialStateProperty.resolveAs(inkWell.mouseCursor, disabled), disabledMouseCursor); + expect(inkWell.overlayColor!.resolve(hovered), primaryColor.withOpacity(0.04)); + expect(inkWell.overlayColor!.resolve(focused), primaryColor.withOpacity(0.12)); expect(inkWell.enableFeedback, enableFeedback); expect(material.borderRadius, null); expect(material.shape, shape); @@ -186,7 +184,7 @@ void main() { const Color shadowColor = Color(0xff000001); const Color overiddenColor = Color(0xff000002); - Widget buildFrame({ Color overallShadowColor, Color themeShadowColor, Color shadowColor }) { + Widget buildFrame({ Color? overallShadowColor, Color? themeShadowColor, Color? shadowColor }) { return MaterialApp( theme: ThemeData.from(colorScheme: colorScheme).copyWith( shadowColor: overallShadowColor, diff --git a/packages/flutter/test/material/page_selector_test.dart b/packages/flutter/test/material/page_selector_test.dart index 2eb3727801..8fd57710ec 100644 --- a/packages/flutter/test/material/page_selector_test.dart +++ b/packages/flutter/test/material/page_selector_test.dart @@ -2,15 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/material.dart'; const Color kSelectedColor = Color(0xFF00FF00); const Color kUnselectedColor = Colors.transparent; -Widget buildFrame(TabController tabController, { Color color, Color selectedColor, double indicatorSize = 12.0 }) { +Widget buildFrame(TabController tabController, { Color? color, Color? selectedColor, double indicatorSize = 12.0 }) { return Directionality( textDirection: TextDirection.ltr, child: Theme( diff --git a/packages/flutter/test/material/page_test.dart b/packages/flutter/test/material/page_test.dart index d9861b6e16..504e24dd08 100644 --- a/packages/flutter/test/material/page_test.dart +++ b/packages/flutter/test/material/page_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart' show CupertinoPageRoute; @@ -32,7 +30,7 @@ void main() { await tester.pump(const Duration(milliseconds: 1)); FadeTransition widget2Opacity = - tester.element(find.text('Page 2')).findAncestorWidgetOfExactType(); + tester.element(find.text('Page 2')).findAncestorWidgetOfExactType()!; Offset widget2TopLeft = tester.getTopLeft(find.text('Page 2')); final Size widget2Size = tester.getSize(find.text('Page 2')); @@ -56,7 +54,7 @@ void main() { await tester.pump(const Duration(milliseconds: 1)); widget2Opacity = - tester.element(find.text('Page 2')).findAncestorWidgetOfExactType(); + tester.element(find.text('Page 2')).findAncestorWidgetOfExactType()!; widget2TopLeft = tester.getTopLeft(find.text('Page 2')); // Page 2 starts to move down. @@ -96,7 +94,7 @@ void main() { Offset widget1TransientTopLeft = tester.getTopLeft(find.text('Page 1')); Offset widget2TopLeft = tester.getTopLeft(find.text('Page 2')); final RenderDecoratedBox box = tester.element(find.byKey(page2Key)) - .findAncestorRenderObjectOfType(); + .findAncestorRenderObjectOfType()!; // Page 1 is moving to the left. expect(widget1TransientTopLeft.dx < widget1InitialTopLeft.dx, true); @@ -284,7 +282,7 @@ void main() { '/': (BuildContext context) => Material( child: TextButton( child: const Text('PUSH'), - onPressed: () { Navigator.of(context).pushNamed('/b'); }, + onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, ), ), '/b': (BuildContext context) => Container(child: const Text('HELLO')), @@ -311,7 +309,7 @@ void main() { final Offset helloPosition2 = tester.getCenter(find.text('HELLO')); expect(helloPosition1.dx, lessThan(helloPosition2.dx)); expect(helloPosition1.dy, helloPosition2.dy); - expect(Theme.of(tester.element(find.text('HELLO'))).platform, TargetPlatform.iOS); + expect(Theme.of(tester.element(find.text('HELLO')))!.platform, TargetPlatform.iOS); await tester.pumpWidget( MaterialApp( theme: ThemeData(platform: TargetPlatform.android), @@ -327,7 +325,7 @@ void main() { // frame in which the theme animation ends. // 3. End all the other animations. expect(await tester.pumpAndSettle(const Duration(minutes: 1)), 2); - expect(Theme.of(tester.element(find.text('HELLO'))).platform, TargetPlatform.android); + expect(Theme.of(tester.element(find.text('HELLO')))!.platform, TargetPlatform.android); final Offset helloPosition3 = tester.getCenter(find.text('HELLO')); expect(helloPosition3, helloPosition2); expect(find.text('PUSH'), findsOneWidget); @@ -367,7 +365,7 @@ void main() { final Offset helloPosition6 = tester.getCenter(find.text('HELLO')); expect(helloPosition5.dx, lessThan(helloPosition6.dx)); expect(helloPosition5.dy, helloPosition6.dy); - expect(Theme.of(tester.element(find.text('HELLO'))).platform, TargetPlatform.macOS); + expect(Theme.of(tester.element(find.text('HELLO')))!.platform, TargetPlatform.macOS); }); testWidgets('test no back gesture on fullscreen dialogs', (WidgetTester tester) async { @@ -481,30 +479,6 @@ void main() { expect(widget1InitialTopLeft == widget1TransientTopLeft, true); }, variant: const TargetPlatformVariant({ TargetPlatform.iOS, TargetPlatform.macOS })); - testWidgets('throws when builder returns null', (WidgetTester tester) async { - await tester.pumpWidget(const MaterialApp( - home: Text('Home'), - )); - // No exceptions yet. - expect(tester.takeException(), isNull); - - tester - .state(find.byType(Navigator)) - .push(MaterialPageRoute( - settings: const RouteSettings(name: 'broken'), - builder: (BuildContext context) => null, - )); - await tester.pumpAndSettle(); - // An exception should've been thrown because the `builder` returned null. - final dynamic exception = tester.takeException(); - expect(exception, isFlutterError); - expect(exception.toStringDeep(), equalsIgnoringHashCodes( - 'FlutterError\n' - ' The builder for route "broken" returned null.\n' - ' Route builders must never return null.\n' - )); - }); - testWidgets('test edge swipe then drop back at starting point works', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( @@ -584,7 +558,7 @@ void main() { body: Center( child: ElevatedButton( onPressed: () { - Navigator.push(scaffoldKey.currentContext, MaterialPageRoute( + Navigator.push(scaffoldKey.currentContext!, MaterialPageRoute( builder: (BuildContext context) { return const Scaffold( body: Center(child: Text('route')), @@ -655,7 +629,7 @@ void main() { // Use the navigator to push a route instead of tapping the 'push' button. // The topmost route (the one that's animating away), ignores input while // the pop is underway because route.navigator.userGestureInProgress. - Navigator.push(scaffoldKey.currentContext, MaterialPageRoute( + Navigator.push(scaffoldKey.currentContext!, MaterialPageRoute( builder: (BuildContext context) { return const Scaffold( body: Center(child: Text('route')), @@ -693,7 +667,7 @@ void main() { expect(homeTapCount, 1); expect(pageTapCount, 0); - Navigator.push(homeScaffoldKey.currentContext, MaterialPageRoute( + Navigator.push(homeScaffoldKey.currentContext!, MaterialPageRoute( builder: (BuildContext context) { return Scaffold( key: pageScaffoldKey, @@ -763,10 +737,10 @@ void main() { expect(homeTapCount, 1); expect(pageTapCount, 0); - final ValueNotifier notifier = Navigator.of(homeScaffoldKey.currentContext).userGestureInProgressNotifier; + final ValueNotifier notifier = Navigator.of(homeScaffoldKey.currentContext!)!.userGestureInProgressNotifier; expect(notifier.value, false); - Navigator.push(homeScaffoldKey.currentContext, MaterialPageRoute( + Navigator.push(homeScaffoldKey.currentContext!, MaterialPageRoute( builder: (BuildContext context) { return Scaffold( key: pageScaffoldKey, @@ -846,7 +820,10 @@ void main() { await tester.pumpWidget( buildNavigator( pages: myPages, - onPopPage: (Route route, dynamic result) => null, + onPopPage: (Route route, dynamic result) { + assert(false); // The test should never execute this. + return true; + }, transitionDelegate: detector, ) ); @@ -861,7 +838,10 @@ void main() { await tester.pumpWidget( buildNavigator( pages: myPages, - onPopPage: (Route route, dynamic result) => null, + onPopPage: (Route route, dynamic result) { + assert(false); // The test should never execute this. + return true; + }, transitionDelegate: detector, ) ); @@ -883,7 +863,10 @@ void main() { await tester.pumpWidget( buildNavigator( pages: myPages, - onPopPage: (Route route, dynamic result) => null, + onPopPage: (Route route, dynamic result) { + assert(false); // The test should never execute this. + return true; + }, transitionDelegate: detector, ) ); @@ -901,7 +884,10 @@ void main() { await tester.pumpWidget( buildNavigator( pages: myPages, - onPopPage: (Route route, dynamic result) => null, + onPopPage: (Route route, dynamic result) { + assert(false); // The test should never execute this. + return true; + }, transitionDelegate: detector, ) ); @@ -919,7 +905,7 @@ void main() { expect(find.text('subpage'), findsOneWidget); expect(find.text('home'), findsNothing); - navigator.currentState.pop(); + navigator.currentState!.pop(); await tester.pump(); expect(find.text('subpage'), findsOneWidget); @@ -931,9 +917,9 @@ class TransitionDetector extends DefaultTransitionDelegate { bool hasTransition = false; @override Iterable resolve({ - List newPageRouteHistory, - Map locationToExitingPageRoute, - Map> pageRouteToPagelessRoutes + required List newPageRouteHistory, + required Map locationToExitingPageRoute, + required Map> pageRouteToPagelessRoutes }) { hasTransition = true; return super.resolve( @@ -945,13 +931,13 @@ class TransitionDetector extends DefaultTransitionDelegate { } Widget buildNavigator({ - List> pages, - PopPageCallback onPopPage, - GlobalKey key, - TransitionDelegate transitionDelegate + required List> pages, + required PopPageCallback onPopPage, + GlobalKey? key, + TransitionDelegate? transitionDelegate }) { return MediaQuery( - data: MediaQueryData.fromWindow(WidgetsBinding.instance.window), + data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window), child: Localizations( locale: const Locale('en', 'US'), delegates: const >[ @@ -974,14 +960,14 @@ Widget buildNavigator({ class KeepsStateTestWidget extends StatefulWidget { const KeepsStateTestWidget({this.navigatorKey}); - final Key navigatorKey; + final Key? navigatorKey; @override State createState() => _KeepsStateTestWidgetState(); } class _KeepsStateTestWidgetState extends State { - String _subpage = 'subpage'; + String? _subpage = 'subpage'; @override Widget build(BuildContext context) { @@ -990,7 +976,7 @@ class _KeepsStateTestWidgetState extends State { key: widget.navigatorKey, pages: >[ const MaterialPage(child: Text('home')), - if (_subpage != null) MaterialPage(child: Text(_subpage)), + if (_subpage != null) MaterialPage(child: Text(_subpage!)), ], onPopPage: (Route route, dynamic result) { if (!route.didPop(result)) { diff --git a/packages/flutter/test/material/page_transitions_theme_test.dart b/packages/flutter/test/material/page_transitions_theme_test.dart index a27381a1d2..6649d98c77 100644 --- a/packages/flutter/test/material/page_transitions_theme_test.dart +++ b/packages/flutter/test/material/page_transitions_theme_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -12,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets('Default PageTransitionsTheme platform', (WidgetTester tester) async { await tester.pumpWidget(const MaterialApp(home: Text('home'))); - final PageTransitionsTheme theme = Theme.of(tester.element(find.text('home'))).pageTransitionsTheme; + final PageTransitionsTheme theme = Theme.of(tester.element(find.text('home')))!.pageTransitionsTheme; expect(theme.builders, isNotNull); for (final TargetPlatform platform in TargetPlatform.values) { if (platform == TargetPlatform.fuchsia) { @@ -28,7 +26,7 @@ void main() { '/': (BuildContext context) => Material( child: TextButton( child: const Text('push'), - onPressed: () { Navigator.of(context).pushNamed('/b'); }, + onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, ), ), '/b': (BuildContext context) => const Text('page b'), @@ -40,7 +38,7 @@ void main() { ), ); - expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride); + expect(Theme.of(tester.element(find.text('push')))!.platform, debugDefaultTargetPlatformOverride); expect(find.byType(CupertinoPageTransition), findsOneWidget); await tester.tap(find.text('push')); @@ -54,7 +52,7 @@ void main() { '/': (BuildContext context) => Material( child: TextButton( child: const Text('push'), - onPressed: () { Navigator.of(context).pushNamed('/b'); }, + onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, ), ), '/b': (BuildContext context) => const Text('page b'), @@ -73,7 +71,7 @@ void main() { ); } - expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride); + expect(Theme.of(tester.element(find.text('push')))!.platform, debugDefaultTargetPlatformOverride); expect(findFadeUpwardsPageTransition(), findsOneWidget); await tester.tap(find.text('push')); @@ -87,7 +85,7 @@ void main() { '/': (BuildContext context) => Material( child: TextButton( child: const Text('push'), - onPressed: () { Navigator.of(context).pushNamed('/b'); }, + onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, ), ), '/b': (BuildContext context) => const Text('page b'), @@ -113,7 +111,7 @@ void main() { ); } - expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride); + expect(Theme.of(tester.element(find.text('push')))!.platform, debugDefaultTargetPlatformOverride); expect(findOpenUpwardsPageTransition(), findsOneWidget); await tester.tap(find.text('push')); @@ -127,7 +125,7 @@ void main() { '/': (BuildContext context) => Material( child: TextButton( child: const Text('push'), - onPressed: () { Navigator.of(context).pushNamed('/b'); }, + onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, ), ), '/b': (BuildContext context) => const Text('page b'), @@ -153,7 +151,7 @@ void main() { ); } - expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride); + expect(Theme.of(tester.element(find.text('push')))!.platform, debugDefaultTargetPlatformOverride); expect(findZoomPageTransition(), findsOneWidget); await tester.tap(find.text('push')); @@ -171,7 +169,7 @@ void main() { '/': (BuildContext context) => Material( child: TextButton( child: const Text('push'), - onPressed: () { Navigator.of(context).pushNamed('/b'); }, + onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, ), ), '/b': (BuildContext context) => StatefulBuilder( diff --git a/packages/flutter/test/material/paginated_data_table_test.dart b/packages/flutter/test/material/paginated_data_table_test.dart index 05470da3be..0e9a7bb170 100644 --- a/packages/flutter/test/material/paginated_data_table_test.dart +++ b/packages/flutter/test/material/paginated_data_table_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/gestures.dart' show DragStartBehavior; @@ -15,7 +13,7 @@ class TestDataSource extends DataTableSource { this.onSelectChanged, }); - final void Function(bool) onSelectChanged; + final void Function(bool?)? onSelectChanged; int get generation => _generation; int _generation = 0; @@ -68,7 +66,7 @@ void main() { availableRowsPerPage: const [ 2, 4, 8, 16, ], - onRowsPerPageChanged: (int rowsPerPage) { + onRowsPerPageChanged: (int? rowsPerPage) { log.add('rows-per-page-changed: $rowsPerPage'); }, onPageChanged: (int rowIndex) { @@ -218,7 +216,7 @@ void main() { availableRowsPerPage: const [ 8, 9, ], - onRowsPerPageChanged: (int rowsPerPage) { }, + onRowsPerPageChanged: (int? rowsPerPage) { }, columns: const [ DataColumn(label: Text('COL1')), DataColumn(label: Text('COL2')), @@ -243,7 +241,7 @@ void main() { source: source, rowsPerPage: 501, availableRowsPerPage: const [ 501 ], - onRowsPerPageChanged: (int rowsPerPage) { }, + onRowsPerPageChanged: (int? rowsPerPage) { }, columns: const [ DataColumn(label: Text('COL1')), DataColumn(label: Text('COL2')), @@ -280,7 +278,7 @@ void main() { rowsPerPage: 5, dragStartBehavior: DragStartBehavior.down, availableRowsPerPage: const [ 5 ], - onRowsPerPageChanged: (int rowsPerPage) { }, + onRowsPerPageChanged: (int? rowsPerPage) { }, columns: const [ DataColumn(label: Text('COL1')), DataColumn(label: Text('COL2')), @@ -315,7 +313,7 @@ void main() { availableRowsPerPage: const [ 2, 4, 8, 16, ], - onRowsPerPageChanged: (int rowsPerPage) {}, + onRowsPerPageChanged: (int? rowsPerPage) {}, onPageChanged: (int rowIndex) {}, columns: const [ DataColumn(label: Text('Name')), @@ -336,7 +334,7 @@ void main() { availableRowsPerPage: const [ 2, 4, 8, 16, ], - onRowsPerPageChanged: (int rowsPerPage) {}, + onRowsPerPageChanged: (int? rowsPerPage) {}, onPageChanged: (int rowIndex) {}, columns: const [ DataColumn(label: Text('Name')), @@ -398,7 +396,7 @@ void main() { await binding.setSurfaceSize(const Size(_width, _height)); final TestDataSource source = TestDataSource( - onSelectChanged: (bool value) {}, + onSelectChanged: (bool? value) {}, ); Finder cellContent; Finder checkbox; @@ -412,9 +410,9 @@ void main() { availableRowsPerPage: const [ 2, 4, ], - onRowsPerPageChanged: (int rowsPerPage) {}, + onRowsPerPageChanged: (int? rowsPerPage) {}, onPageChanged: (int rowIndex) {}, - onSelectAll: (bool value) {}, + onSelectAll: (bool? value) {}, columns: const [ DataColumn(label: Text('Name')), DataColumn(label: Text('Calories'), numeric: true), @@ -481,9 +479,9 @@ void main() { availableRowsPerPage: const [ 2, 4, ], - onRowsPerPageChanged: (int rowsPerPage) {}, + onRowsPerPageChanged: (int? rowsPerPage) {}, onPageChanged: (int rowIndex) {}, - onSelectAll: (bool value) {}, + onSelectAll: (bool? value) {}, columns: const [ DataColumn(label: Text('Name')), DataColumn(label: Text('Calories'), numeric: true), @@ -564,7 +562,7 @@ void main() { availableRowsPerPage: const [ 2, 4, 8, 16, ], - onRowsPerPageChanged: (int rowsPerPage) {}, + onRowsPerPageChanged: (int? rowsPerPage) {}, onPageChanged: (int rowIndex) {}, columns: const [ DataColumn(label: Text('Name')), @@ -620,7 +618,7 @@ void main() { availableRowsPerPage: const [ 2, 4, 8, 16, ], - onRowsPerPageChanged: (int rowsPerPage) {}, + onRowsPerPageChanged: (int? rowsPerPage) {}, onPageChanged: (int rowIndex) {}, columns: const [ DataColumn(label: Text('Name')), @@ -691,7 +689,7 @@ void main() { availableRowsPerPage: const [ 2, 4, 8, 16, ], - onRowsPerPageChanged: (int rowsPerPage) {}, + onRowsPerPageChanged: (int? rowsPerPage) {}, onPageChanged: (int rowIndex) {}, columns: const [ DataColumn(label: Text('Name')), @@ -735,7 +733,7 @@ void main() { Widget buildTable(bool checkbox) => MaterialApp( home: PaginatedDataTable( header: const Text('Test table'), - source: TestDataSource(onSelectChanged: (bool value) {}), + source: TestDataSource(onSelectChanged: (bool? value) {}), showCheckboxColumn: checkbox, columns: const [ DataColumn(label: Text('Name')), diff --git a/packages/flutter/test/material/persistent_bottom_sheet_test.dart b/packages/flutter/test/material/persistent_bottom_sheet_test.dart index 374666364c..75bf88e897 100644 --- a/packages/flutter/test/material/persistent_bottom_sheet_test.dart +++ b/packages/flutter/test/material/persistent_bottom_sheet_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/material.dart'; @@ -25,7 +23,6 @@ void main() { testWidgets('Verify that a BottomSheet can be rebuilt with ScaffoldFeatureController.setState()', (WidgetTester tester) async { final GlobalKey scaffoldKey = GlobalKey(); - PersistentBottomSheetController bottomSheet; int buildCount = 0; await tester.pumpWidget(MaterialApp( @@ -35,7 +32,7 @@ void main() { ), )); - bottomSheet = scaffoldKey.currentState.showBottomSheet((_) { + final PersistentBottomSheetController bottomSheet = scaffoldKey.currentState!.showBottomSheet((_) { return Builder( builder: (BuildContext context) { buildCount += 1; @@ -46,7 +43,7 @@ void main() { await tester.pump(); expect(buildCount, equals(1)); - bottomSheet.setState(() { }); + bottomSheet.setState!(() { }); await tester.pump(); expect(buildCount, equals(2)); }); @@ -92,7 +89,7 @@ void main() { ), )); - scaffoldKey.currentState.showBottomSheet((BuildContext context) { + scaffoldKey.currentState!.showBottomSheet((BuildContext context) { return ListView( shrinkWrap: true, primary: false, @@ -124,7 +121,7 @@ void main() { ), )); - scaffoldKey.currentState.showBottomSheet((BuildContext context) { + scaffoldKey.currentState!.showBottomSheet((BuildContext context) { return ListView( shrinkWrap: true, primary: false, @@ -159,7 +156,7 @@ void main() { ), )); - scaffoldKey.currentState.showBottomSheet( + scaffoldKey.currentState!.showBottomSheet( (BuildContext context) { return DraggableScrollableSheet( expand: false, @@ -313,7 +310,7 @@ void main() { ), )); - scaffoldKey.currentState.showBottomSheet( + scaffoldKey.currentState!.showBottomSheet( (BuildContext context) { return DraggableScrollableSheet( expand: false, @@ -363,7 +360,7 @@ void main() { int buildCount = 0; showBottomSheet( - context: key.currentContext, + context: key.currentContext!, builder: (BuildContext context) { return Builder( builder: (BuildContext context) { @@ -378,8 +375,8 @@ void main() { }); testWidgets('Scaffold removes top MediaQuery padding', (WidgetTester tester) async { - BuildContext scaffoldContext; - BuildContext bottomSheetContext; + late BuildContext scaffoldContext; + late BuildContext bottomSheetContext; await tester.pumpWidget(MaterialApp( home: MediaQuery( @@ -411,7 +408,7 @@ void main() { await tester.pump(); expect( - MediaQuery.of(bottomSheetContext).padding, + MediaQuery.of(bottomSheetContext)!.padding, const EdgeInsets.only( bottom: 50.0, left: 50.0, @@ -492,7 +489,7 @@ void main() { ), )); - scaffoldKey.currentState.showBottomSheet((BuildContext context) { + scaffoldKey.currentState!.showBottomSheet((BuildContext context) { return ListView( shrinkWrap: true, primary: false, @@ -522,7 +519,7 @@ void main() { ), )); - final PersistentBottomSheetController bottomSheet = scaffoldKey.currentState.showBottomSheet((_) { + final PersistentBottomSheetController bottomSheet = scaffoldKey.currentState!.showBottomSheet((_) { return Builder( builder: (BuildContext context) { return Container(height: 200.0); diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index df817df69a..292ebd4c91 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:ui' show window, SemanticsFlag; import 'package:flutter_test/flutter_test.dart'; @@ -66,7 +64,7 @@ void main() { testWidgets('PopupMenuButton calls onCanceled callback when an item is not selected', (WidgetTester tester) async { int cancels = 0; - BuildContext popupContext; + late BuildContext popupContext; final Key noCallbackKey = UniqueKey(); final Key withCallbackKey = UniqueKey(); @@ -125,7 +123,7 @@ void main() { await tester.tap(find.byKey(withCallbackKey)); await tester.pump(); await tester.pump(const Duration(seconds: 1)); - Navigator.of(popupContext).pop(); + Navigator.of(popupContext)!.pop(); await tester.pump(); expect(cancels, equals(2)); }); @@ -140,7 +138,7 @@ void main() { return MaterialApp( home: Builder(builder: (BuildContext context) { return MediaQuery( - data: MediaQuery.of(context).copyWith( + data: MediaQuery.of(context)!.copyWith( navigationMode: NavigationMode.directional, ), child: Material( @@ -191,7 +189,7 @@ void main() { await tester.pumpWidget(buildApp(directional: true)); // Try to bring up the popup menu and select the first item from it - Focus.of(popupButtonKey.currentContext).requestFocus(); + Focus.of(popupButtonKey.currentContext!)!.requestFocus(); await tester.pumpAndSettle(); await tester.tap(find.byKey(popupButtonKey)); await tester.pumpAndSettle(); @@ -240,10 +238,10 @@ void main() { ), ), ); - Focus.of(childKey.currentContext, nullOk: true).requestFocus(); + Focus.of(childKey.currentContext!)!.requestFocus(); await tester.pump(); - expect(Focus.of(childKey.currentContext, nullOk: true).hasPrimaryFocus, isFalse); + expect(Focus.of(childKey.currentContext!)!.hasPrimaryFocus, isFalse); expect(itemBuilderCalled, isFalse); expect(onSelectedCalled, isFalse); }); @@ -256,7 +254,7 @@ void main() { MaterialApp( home: Builder(builder: (BuildContext context) { return MediaQuery( - data: MediaQuery.of(context).copyWith( + data: MediaQuery.of(context)!.copyWith( navigationMode: NavigationMode.directional, ), child: Material( @@ -283,10 +281,10 @@ void main() { }), ), ); - Focus.of(childKey.currentContext, nullOk: true).requestFocus(); + Focus.of(childKey.currentContext!)!.requestFocus(); await tester.pump(); - expect(Focus.of(childKey.currentContext, nullOk: true).hasPrimaryFocus, isTrue); + expect(Focus.of(childKey.currentContext!)!.hasPrimaryFocus, isTrue); }); testWidgets('PopupMenuItem is only focusable when enabled', (WidgetTester tester) async { @@ -321,7 +319,7 @@ void main() { // Open the popup to build and show the menu contents. await tester.tap(find.byKey(popupButtonKey)); await tester.pumpAndSettle(); - final FocusNode childNode = Focus.of(childKey.currentContext, nullOk: true); + final FocusNode childNode = Focus.of(childKey.currentContext!)!; // Now that the contents are shown, request focus on the child text. childNode.requestFocus(); await tester.pumpAndSettle(); @@ -364,7 +362,7 @@ void main() { await tester.pumpAndSettle(); expect(itemBuilderCalled, isTrue); - expect(Focus.of(childKey.currentContext, nullOk: true).hasPrimaryFocus, isFalse); + expect(Focus.of(childKey.currentContext!)!.hasPrimaryFocus, isFalse); }); testWidgets('PopupMenuButton is horizontal on iOS', (WidgetTester tester) async { @@ -637,7 +635,7 @@ void main() { }); testWidgets('PopupMenu removes MediaQuery padding', (WidgetTester tester) async { - BuildContext popupContext; + late BuildContext popupContext; await tester.pumpWidget(MaterialApp( home: MediaQuery( @@ -674,7 +672,7 @@ void main() { await tester.pump(); - expect(MediaQuery.of(popupContext).padding, EdgeInsets.zero); + expect(MediaQuery.of(popupContext)!.padding, EdgeInsets.zero); }); testWidgets('Popup Menu Offset Test', (WidgetTester tester) async { @@ -1042,7 +1040,7 @@ void main() { testWidgets('PopupMenuButton PopupMenuDivider', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/27072 - String selectedValue; + late String selectedValue; await tester.pumpWidget( MaterialApp( home: Scaffold( @@ -1093,41 +1091,6 @@ void main() { expect(selectedValue, '2'); }); - testWidgets('showMenu position required', (WidgetTester tester) async { - // Test for https://github.com/flutter/flutter/issues/22256 - await tester.pumpWidget( - MaterialApp( - home: Material( - child: Center( - child: Builder( - builder: (BuildContext context) { - return ElevatedButton( - onPressed: () { - // Ensure showMenu throws an assertion without a position - expect(() { - // ignore: missing_required_param - showMenu( - context: context, - items: >[ - const PopupMenuItem( - value: 1, child: Text('1'), - ), - ], - ); - }, throwsAssertionError); - }, - child: const Text('Menu Button'), - ); - }, - ), - ), - ), - ), - ); - - await tester.tap(find.text('Menu Button')); - }); - testWidgets('PopupMenuItem child height is a minimum, child is vertically centered', (WidgetTester tester) async { final Key popupMenuButtonKey = UniqueKey(); final Type menuItemType = const PopupMenuItem(child: Text('item')).runtimeType; @@ -1219,14 +1182,14 @@ void main() { double fontSize = 24, }) { return MaterialApp( - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Directionality( textDirection: textDirection, child: PopupMenuTheme( data: PopupMenuTheme.of(context).copyWith( - textStyle: Theme.of(context).textTheme.subtitle1.copyWith(fontSize: fontSize), + textStyle: Theme.of(context)!.textTheme.subtitle1!.copyWith(fontSize: fontSize), ), - child: child, + child: child!, ), ); }, @@ -1533,7 +1496,7 @@ void main() { expect(find.text('Tap me please!'), findsNothing); - globalKey.currentState.showButtonMenu(); + globalKey.currentState!.showButtonMenu(); // The PopupMenuItem will appear after an animation, hence, // we have to first wait for the tester to settle. await tester.pumpAndSettle(); @@ -1571,7 +1534,7 @@ void main() { await tester.pump(); - expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text); + expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text); // Test default cursor await tester.pumpWidget( @@ -1594,7 +1557,7 @@ void main() { ), ); - expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click); + expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click); // Test default cursor when disabled await tester.pumpWidget( @@ -1618,19 +1581,19 @@ void main() { ), ); - expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); + expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); }); } class TestApp extends StatefulWidget { const TestApp({ - Key key, - this.textDirection, + Key? key, + required this.textDirection, this.child, }) : super(key: key); final TextDirection textDirection; - final Widget child; + final Widget? child; @override _TestAppState createState() => _TestAppState(); @@ -1670,7 +1633,7 @@ class MenuObserver extends NavigatorObserver { int menuCount = 0; @override - void didPush(Route route, Route previousRoute) { + void didPush(Route route, Route? previousRoute) { if (route.toString().contains('_PopupMenuRoute')) { menuCount++; } diff --git a/packages/flutter/test/material/popup_menu_theme_test.dart b/packages/flutter/test/material/popup_menu_theme_test.dart index a9645217e6..124254c0b3 100644 --- a/packages/flutter/test/material/popup_menu_theme_test.dart +++ b/packages/flutter/test/material/popup_menu_theme_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -79,7 +77,7 @@ void main() { PopupMenuButton( key: popupButtonKey, itemBuilder: (BuildContext context) { - return >[ + return >[ PopupMenuItem( key: popupItemKey, child: const Text('Example'), @@ -139,7 +137,7 @@ void main() { key: popupButtonKey, itemBuilder: (BuildContext context) { return >[ - PopupMenuItem( + PopupMenuItem( key: popupItemKey, child: const Text('Example'), ), @@ -206,7 +204,7 @@ void main() { color: color, shape: shape, itemBuilder: (BuildContext context) { - return >[ + return >[ PopupMenuItem( key: popupItemKey, textStyle: textStyle, @@ -270,7 +268,7 @@ void main() { child: PopupMenuButton( key: popupButtonKey, itemBuilder: (BuildContext context) { - return >[ + return >[ PopupMenuItem( key: popupItemKey, child: const Text('Example'),