Unverified Commit 3961a12a authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Migrate some material tests to nnbd (#67477)

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