Unverified Commit 46238de8 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

[NNBD] Migrate some Material tests to NNBD (#67887)

Migrates the following files to NNBD: 
* input_decorator_test.dart
* list_tile_test.dart
* localizations_test.dart
* material_button_test.dart
* material_state_property_test.dart
* material_test.dart
* mergeable_material_test.dart
parent 244f5ab5
...@@ -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:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -14,15 +12,15 @@ import '../rendering/mock_canvas.dart'; ...@@ -14,15 +12,15 @@ import '../rendering/mock_canvas.dart';
Widget buildInputDecorator({ Widget buildInputDecorator({
InputDecoration decoration = const InputDecoration(), InputDecoration decoration = const InputDecoration(),
InputDecorationTheme inputDecorationTheme, InputDecorationTheme? inputDecorationTheme,
TextDirection textDirection = TextDirection.ltr, TextDirection textDirection = TextDirection.ltr,
bool expands = false, bool expands = false,
bool isEmpty = false, bool isEmpty = false,
bool isFocused = false, bool isFocused = false,
bool isHovering = false, bool isHovering = false,
TextStyle baseStyle, TextStyle? baseStyle,
TextAlignVertical textAlignVertical, TextAlignVertical? textAlignVertical,
VisualDensity visualDensity, VisualDensity? visualDensity,
bool fixTextFieldOutlineLabel = false, bool fixTextFieldOutlineLabel = false,
Widget child = const Text( Widget child = const Text(
'text', 'text',
...@@ -34,7 +32,7 @@ Widget buildInputDecorator({ ...@@ -34,7 +32,7 @@ Widget buildInputDecorator({
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return Theme( return Theme(
data: Theme.of(context).copyWith( data: Theme.of(context)!.copyWith(
inputDecorationTheme: inputDecorationTheme, inputDecorationTheme: inputDecorationTheme,
visualDensity: visualDensity, visualDensity: visualDensity,
fixTextFieldOutlineLabel: fixTextFieldOutlineLabel, fixTextFieldOutlineLabel: fixTextFieldOutlineLabel,
...@@ -70,7 +68,7 @@ Finder findBorderPainter() { ...@@ -70,7 +68,7 @@ Finder findBorderPainter() {
} }
double getBorderBottom(WidgetTester tester) { double getBorderBottom(WidgetTester tester) {
final RenderBox box = InputDecorator.containerOf(tester.element(findBorderPainter())); final RenderBox box = InputDecorator.containerOf(tester.element(findBorderPainter()))!;
return box.size.height; return box.size.height;
} }
...@@ -85,7 +83,7 @@ Rect getLabelRect(WidgetTester tester) { ...@@ -85,7 +83,7 @@ Rect getLabelRect(WidgetTester tester) {
return tester.getRect(findLabel()); return tester.getRect(findLabel());
} }
InputBorder getBorder(WidgetTester tester) { InputBorder? getBorder(WidgetTester tester) {
if (!tester.any(findBorderPainter())) if (!tester.any(findBorderPainter()))
return null; return null;
final CustomPaint customPaint = tester.widget(findBorderPainter()); final CustomPaint customPaint = tester.widget(findBorderPainter());
...@@ -96,21 +94,21 @@ InputBorder getBorder(WidgetTester tester) { ...@@ -96,21 +94,21 @@ InputBorder getBorder(WidgetTester tester) {
return border; return border;
} }
BorderSide getBorderSide(WidgetTester tester) { BorderSide? getBorderSide(WidgetTester tester) {
return getBorder(tester)?.borderSide; return getBorder(tester)!.borderSide;
} }
BorderRadius getBorderRadius(WidgetTester tester) { BorderRadius? getBorderRadius(WidgetTester tester) {
final InputBorder border = getBorder(tester); final InputBorder border = getBorder(tester)!;
if (border is UnderlineInputBorder) { if (border is UnderlineInputBorder) {
return border.borderRadius; return border.borderRadius;
} }
return null; return null;
} }
double getBorderWeight(WidgetTester tester) => getBorderSide(tester)?.width; double getBorderWeight(WidgetTester tester) => getBorderSide(tester)!.width;
Color getBorderColor(WidgetTester tester) => getBorderSide(tester)?.color; Color getBorderColor(WidgetTester tester) => getBorderSide(tester)!.color;
Color getContainerColor(WidgetTester tester) { Color getContainerColor(WidgetTester tester) {
final CustomPaint customPaint = tester.widget(findBorderPainter()); final CustomPaint customPaint = tester.widget(findBorderPainter());
...@@ -925,10 +923,10 @@ void main() { ...@@ -925,10 +923,10 @@ void main() {
testWidgets('InputDecorator counter text, widget, and null', (WidgetTester tester) async { testWidgets('InputDecorator counter text, widget, and null', (WidgetTester tester) async {
Widget buildFrame({ Widget buildFrame({
InputCounterWidgetBuilder buildCounter, InputCounterWidgetBuilder? buildCounter,
String counterText, String? counterText,
Widget counter, Widget? counter,
int maxLength, int? maxLength,
}) { }) {
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
...@@ -953,7 +951,7 @@ void main() { ...@@ -953,7 +951,7 @@ void main() {
// When counter, counterText, and buildCounter are null, defaults to showing // When counter, counterText, and buildCounter are null, defaults to showing
// the built-in counter. // the built-in counter.
int maxLength = 10; int? maxLength = 10;
await tester.pumpWidget(buildFrame(maxLength: maxLength)); await tester.pumpWidget(buildFrame(maxLength: maxLength));
Finder counterFinder = find.byType(Text); Finder counterFinder = find.byType(Text);
expect(counterFinder, findsOneWidget); expect(counterFinder, findsOneWidget);
...@@ -966,13 +964,18 @@ void main() { ...@@ -966,13 +964,18 @@ void main() {
final Key buildCounterKey = UniqueKey(); final Key buildCounterKey = UniqueKey();
const String counterText = 'I show instead of count'; const String counterText = 'I show instead of count';
final Widget counter = Text('hello', key: counterKey); final Widget counter = Text('hello', key: counterKey);
final InputCounterWidgetBuilder buildCounter = final InputCounterWidgetBuilder buildCounter = (
(BuildContext context, { int currentLength, int maxLength, bool isFocused }) { BuildContext context, {
return Text( required int currentLength,
'${currentLength.toString()} of ${maxLength.toString()}', required int? maxLength,
key: buildCounterKey, required bool isFocused,
); }) {
}; return Text(
'${currentLength.toString()} of ${maxLength.toString()}',
key: buildCounterKey,
);
};
await tester.pumpWidget(buildFrame( await tester.pumpWidget(buildFrame(
counterText: counterText, counterText: counterText,
counter: counter, counter: counter,
...@@ -3021,10 +3024,10 @@ void main() { ...@@ -3021,10 +3024,10 @@ void main() {
expect(tester.getTopRight(find.text('counter')), const Offset(800.0, 64.0)); expect(tester.getTopRight(find.text('counter')), const Offset(800.0, 64.0));
// Verify that the styles were passed along // Verify that the styles were passed along
expect(tester.widget<Text>(find.text('prefix')).style.color, prefixStyle.color); expect(tester.widget<Text>(find.text('prefix')).style!.color, prefixStyle.color);
expect(tester.widget<Text>(find.text('suffix')).style.color, suffixStyle.color); expect(tester.widget<Text>(find.text('suffix')).style!.color, suffixStyle.color);
expect(tester.widget<Text>(find.text('helper')).style.color, helperStyle.color); expect(tester.widget<Text>(find.text('helper')).style!.color, helperStyle.color);
expect(tester.widget<Text>(find.text('counter')).style.color, counterStyle.color); expect(tester.widget<Text>(find.text('counter')).style!.color, counterStyle.color);
TextStyle getLabelStyle() { TextStyle getLabelStyle() {
return tester.firstWidget<AnimatedDefaultTextStyle>( return tester.firstWidget<AnimatedDefaultTextStyle>(
...@@ -3073,7 +3076,7 @@ void main() { ...@@ -3073,7 +3076,7 @@ void main() {
final RenderObject renderer = tester.renderObject(find.byType(InputDecorator)); final RenderObject renderer = tester.renderObject(find.byType(InputDecorator));
final Iterable<String> nodeNames = renderer.debugDescribeChildren() final Iterable<String> nodeNames = renderer.debugDescribeChildren()
.map((DiagnosticsNode node) => node.name); .map((DiagnosticsNode node) => node.name!);
expect(nodeNames, unorderedEquals(<String>[ expect(nodeNames, unorderedEquals(<String>[
'container', 'container',
'counter', 'counter',
...@@ -3089,7 +3092,7 @@ void main() { ...@@ -3089,7 +3092,7 @@ void main() {
])); ]));
final Set<Object> nodeValues = Set<Object>.from( final Set<Object> nodeValues = Set<Object>.from(
renderer.debugDescribeChildren().map<Object>((DiagnosticsNode node) => node.value) renderer.debugDescribeChildren().map<Object>((DiagnosticsNode node) => node.value!)
); );
expect(nodeValues.length, 11); expect(nodeValues.length, 11);
}); });
...@@ -3347,7 +3350,11 @@ void main() { ...@@ -3347,7 +3350,11 @@ void main() {
const Color disabledColor = Color(0x05000000); const Color disabledColor = Color(0x05000000);
const Color enabledBorderColor = Color(0x61000000); const Color enabledBorderColor = Color(0x61000000);
Future<void> pumpDecorator({bool hovering, bool enabled = true, bool filled = true}) async { Future<void> pumpDecorator({
required bool hovering,
bool enabled = true,
bool filled = true,
}) async {
return await tester.pumpWidget( return await tester.pumpWidget(
buildInputDecorator( buildInputDecorator(
isHovering: hovering, isHovering: hovering,
...@@ -3422,7 +3429,11 @@ void main() { ...@@ -3422,7 +3429,11 @@ void main() {
const Color disabledColor = Color(0x05000000); const Color disabledColor = Color(0x05000000);
const Color enabledBorderColor = Color(0x61000000); const Color enabledBorderColor = Color(0x61000000);
Future<void> pumpDecorator({bool focused, bool enabled = true, bool filled = true}) async { Future<void> pumpDecorator({
required bool focused,
bool enabled = true,
bool filled = true,
}) async {
return await tester.pumpWidget( return await tester.pumpWidget(
buildInputDecorator( buildInputDecorator(
isFocused: focused, isFocused: focused,
...@@ -3467,7 +3478,13 @@ void main() { ...@@ -3467,7 +3478,13 @@ void main() {
}); });
testWidgets('InputDecorator withdraws label when not empty or focused', (WidgetTester tester) async { testWidgets('InputDecorator withdraws label when not empty or focused', (WidgetTester tester) async {
Future<void> pumpDecorator({bool focused, bool enabled = true, bool filled = false, bool empty = true, bool directional = false}) async { Future<void> pumpDecorator({
required bool focused,
bool enabled = true,
bool filled = false,
bool empty = true,
bool directional = false,
}) async {
return await tester.pumpWidget( return await tester.pumpWidget(
buildInputDecorator( buildInputDecorator(
isEmpty: empty, isEmpty: empty,
...@@ -4140,8 +4157,8 @@ void main() { ...@@ -4140,8 +4157,8 @@ void main() {
testWidgets('textAlignVertical can be updated', (WidgetTester tester) async { testWidgets('textAlignVertical can be updated', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/56933 // Regression test for https://github.com/flutter/flutter/issues/56933
const String hintText = 'hint'; const String hintText = 'hint';
TextAlignVertical alignment = TextAlignVertical.top; TextAlignVertical? alignment = TextAlignVertical.top;
StateSetter setState; late StateSetter setState;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: StatefulBuilder( home: StatefulBuilder(
...@@ -4187,7 +4204,7 @@ void main() { ...@@ -4187,7 +4204,7 @@ void main() {
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return Theme( return Theme(
data: Theme.of(context), data: Theme.of(context)!,
child: Align( child: Align(
alignment: Alignment.topLeft, alignment: Alignment.topLeft,
child: TextField( child: TextField(
...@@ -4247,7 +4264,7 @@ void main() { ...@@ -4247,7 +4264,7 @@ void main() {
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return Theme( return Theme(
data: Theme.of(context).copyWith(visualDensity: visualDensity), data: Theme.of(context)!.copyWith(visualDensity: visualDensity),
child: Center( child: Center(
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
...@@ -4320,7 +4337,7 @@ void main() { ...@@ -4320,7 +4337,7 @@ void main() {
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return Theme( return Theme(
data: Theme.of(context).copyWith(visualDensity: VisualDensity.compact), data: Theme.of(context)!.copyWith(visualDensity: VisualDensity.compact),
child: Center( child: Center(
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
......
...@@ -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:math' as math; import 'dart:math' as math;
import 'dart:ui'; import 'dart:ui';
...@@ -17,14 +15,14 @@ import '../rendering/mock_canvas.dart'; ...@@ -17,14 +15,14 @@ import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart'; import '../widgets/semantics_tester.dart';
class TestIcon extends StatefulWidget { class TestIcon extends StatefulWidget {
const TestIcon({ Key key }) : super(key: key); const TestIcon({ Key? key }) : super(key: key);
@override @override
TestIconState createState() => TestIconState(); TestIconState createState() => TestIconState();
} }
class TestIconState extends State<TestIcon> { class TestIconState extends State<TestIcon> {
IconThemeData iconTheme; late IconThemeData iconTheme;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -34,7 +32,7 @@ class TestIconState extends State<TestIcon> { ...@@ -34,7 +32,7 @@ class TestIconState extends State<TestIcon> {
} }
class TestText extends StatefulWidget { class TestText extends StatefulWidget {
const TestText(this.text, { Key key }) : super(key: key); const TestText(this.text, { Key? key }) : super(key: key);
final String text; final String text;
...@@ -43,7 +41,7 @@ class TestText extends StatefulWidget { ...@@ -43,7 +41,7 @@ class TestText extends StatefulWidget {
} }
class TestTextState extends State<TestText> { class TestTextState extends State<TestText> {
TextStyle textStyle; late TextStyle textStyle;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -58,11 +56,11 @@ void main() { ...@@ -58,11 +56,11 @@ void main() {
final Key leadingKey = GlobalKey(); final Key leadingKey = GlobalKey();
final Key trailingKey = GlobalKey(); final Key trailingKey = GlobalKey();
bool hasSubtitle; late bool hasSubtitle;
const double leftPadding = 10.0; const double leftPadding = 10.0;
const double rightPadding = 20.0; const double rightPadding = 20.0;
Widget buildFrame({ bool dense = false, bool isTwoLine = false, bool isThreeLine = false, double textScaleFactor = 1.0, double subtitleScaleFactor }) { Widget buildFrame({ bool dense = false, bool isTwoLine = false, bool isThreeLine = false, double textScaleFactor = 1.0, double? subtitleScaleFactor }) {
hasSubtitle = isTwoLine || isThreeLine; hasSubtitle = isTwoLine || isThreeLine;
subtitleScaleFactor ??= textScaleFactor; subtitleScaleFactor ??= textScaleFactor;
return MaterialApp( return MaterialApp(
...@@ -259,16 +257,16 @@ void main() { ...@@ -259,16 +257,16 @@ void main() {
final Key subtitleKey = UniqueKey(); final Key subtitleKey = UniqueKey();
final Key leadingKey = UniqueKey(); final Key leadingKey = UniqueKey();
final Key trailingKey = UniqueKey(); final Key trailingKey = UniqueKey();
ThemeData theme; late ThemeData theme;
Widget buildFrame({ Widget buildFrame({
bool enabled = true, bool enabled = true,
bool dense = false, bool dense = false,
bool selected = false, bool selected = false,
ShapeBorder shape, ShapeBorder? shape,
Color selectedColor, Color? selectedColor,
Color iconColor, Color? iconColor,
Color textColor, Color? textColor,
}) { }) {
return MaterialApp( return MaterialApp(
home: Material( home: Material(
...@@ -281,7 +279,7 @@ void main() { ...@@ -281,7 +279,7 @@ void main() {
textColor: textColor, textColor: textColor,
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
theme = Theme.of(context); theme = Theme.of(context)!;
return ListTile( return ListTile(
enabled: enabled, enabled: enabled,
selected: selected, selected: selected,
...@@ -304,9 +302,9 @@ void main() { ...@@ -304,9 +302,9 @@ void main() {
borderRadius: BorderRadius.all(Radius.circular(4.0)), borderRadius: BorderRadius.all(Radius.circular(4.0)),
); );
Color iconColor(Key key) => tester.state<TestIconState>(find.byKey(key)).iconTheme.color; Color iconColor(Key key) => tester.state<TestIconState>(find.byKey(key)).iconTheme.color!;
Color textColor(Key key) => tester.state<TestTextState>(find.byKey(key)).textStyle.color; Color textColor(Key key) => tester.state<TestTextState>(find.byKey(key)).textStyle.color!;
ShapeBorder inkWellBorder() => tester.widget<InkWell>(find.descendant(of: find.byType(ListTile), matching: find.byType(InkWell))).customBorder; ShapeBorder inkWellBorder() => tester.widget<InkWell>(find.descendant(of: find.byType(ListTile), matching: find.byType(InkWell))).customBorder!;
// A selected ListTile's leading, trailing, and text get the primary color by default // A selected ListTile's leading, trailing, and text get the primary color by default
await tester.pumpWidget(buildFrame(selected: true)); await tester.pumpWidget(buildFrame(selected: true));
...@@ -1175,10 +1173,10 @@ void main() { ...@@ -1175,10 +1173,10 @@ void main() {
); );
await tester.pump(); // Let the focus take effect. await tester.pump(); // Let the focus take effect.
final FocusNode tileNode = Focus.of(childKey.currentContext); final FocusNode? tileNode = Focus.of(childKey.currentContext!);
tileNode.requestFocus(); tileNode!.requestFocus();
await tester.pump(); // Let the focus take effect. await tester.pump(); // Let the focus take effect.
expect(Focus.of(childKey.currentContext, nullOk: true).hasPrimaryFocus, isTrue); expect(Focus.of(childKey.currentContext!, nullOk: true)!.hasPrimaryFocus, isTrue);
expect(tileNode.hasPrimaryFocus, isTrue); expect(tileNode.hasPrimaryFocus, isTrue);
await tester.pumpWidget( await tester.pumpWidget(
...@@ -1199,7 +1197,7 @@ void main() { ...@@ -1199,7 +1197,7 @@ void main() {
); );
expect(tester.binding.focusManager.primaryFocus, isNot(equals(tileNode))); expect(tester.binding.focusManager.primaryFocus, isNot(equals(tileNode)));
expect(Focus.of(childKey.currentContext, nullOk: true).hasPrimaryFocus, isFalse); expect(Focus.of(childKey.currentContext!, nullOk: true)!.hasPrimaryFocus, isFalse);
}); });
testWidgets('ListTile can autofocus unless disabled.', (WidgetTester tester) async { testWidgets('ListTile can autofocus unless disabled.', (WidgetTester tester) async {
...@@ -1224,7 +1222,7 @@ void main() { ...@@ -1224,7 +1222,7 @@ void main() {
); );
await tester.pump(); await tester.pump();
expect(Focus.of(childKey.currentContext, nullOk: true).hasPrimaryFocus, isTrue); expect(Focus.of(childKey.currentContext!, nullOk: true)!.hasPrimaryFocus, isTrue);
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
...@@ -1245,7 +1243,7 @@ void main() { ...@@ -1245,7 +1243,7 @@ void main() {
); );
await tester.pump(); await tester.pump();
expect(Focus.of(childKey.currentContext, nullOk: true).hasPrimaryFocus, isFalse); expect(Focus.of(childKey.currentContext!, nullOk: true)!.hasPrimaryFocus, isFalse);
}); });
testWidgets('ListTile is focusable and has correct focus color', (WidgetTester tester) async { testWidgets('ListTile is focusable and has correct focus color', (WidgetTester tester) async {
...@@ -1480,7 +1478,7 @@ void main() { ...@@ -1480,7 +1478,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(
...@@ -1498,7 +1496,7 @@ void main() { ...@@ -1498,7 +1496,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(
...@@ -1516,7 +1514,7 @@ void main() { ...@@ -1516,7 +1514,7 @@ void main() {
), ),
); );
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
// Test default cursor when onTap or onLongPress is null // Test default cursor when onTap or onLongPress is null
await tester.pumpWidget( await tester.pumpWidget(
...@@ -1532,7 +1530,7 @@ void main() { ...@@ -1532,7 +1530,7 @@ void main() {
), ),
); );
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
}); });
testWidgets('ListTile respects tileColor & selectedTileColor', (WidgetTester tester) async { testWidgets('ListTile respects tileColor & selectedTileColor', (WidgetTester tester) async {
...@@ -1612,7 +1610,7 @@ void main() { ...@@ -1612,7 +1610,7 @@ void main() {
}); });
testWidgets('ListTile respects ListTileTheme\'s tileColor & selectedTileColor', (WidgetTester tester) async { testWidgets('ListTile respects ListTileTheme\'s tileColor & selectedTileColor', (WidgetTester tester) async {
ListTileTheme theme; late ListTileTheme theme;
bool isSelected = false; bool isSelected = false;
await tester.pumpWidget( await tester.pumpWidget(
......
...@@ -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';
......
...@@ -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/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -42,10 +40,10 @@ void main() { ...@@ -42,10 +40,10 @@ void main() {
expect(material.elevation, 2.0); expect(material.elevation, 2.0);
expect(material.shadowColor, null); expect(material.shadowColor, null);
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0))); expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0)));
expect(material.textStyle.color, const Color(0xdd000000)); expect(material.textStyle!.color, const Color(0xdd000000));
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.transparency); expect(material.type, MaterialType.transparency);
final Offset center = tester.getCenter(find.byType(MaterialButton)); final Offset center = tester.getCenter(find.byType(MaterialButton));
...@@ -62,10 +60,10 @@ void main() { ...@@ -62,10 +60,10 @@ void main() {
expect(material.elevation, 8.0); expect(material.elevation, 8.0);
expect(material.shadowColor, null); expect(material.shadowColor, null);
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0))); expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0)));
expect(material.textStyle.color, const Color(0xdd000000)); expect(material.textStyle!.color, const Color(0xdd000000));
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.transparency); expect(material.type, MaterialType.transparency);
// Disabled MaterialButton // Disabled MaterialButton
...@@ -87,10 +85,10 @@ void main() { ...@@ -87,10 +85,10 @@ void main() {
expect(material.elevation, 0.0); expect(material.elevation, 0.0);
expect(material.shadowColor, null); expect(material.shadowColor, null);
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0))); expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(2.0)));
expect(material.textStyle.color, const Color(0x61000000)); expect(material.textStyle!.color, const Color(0x61000000));
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.transparency); expect(material.type, MaterialType.transparency);
}); });
...@@ -192,7 +190,7 @@ void main() { ...@@ -192,7 +190,7 @@ void main() {
expect(material.elevation, equals(focusElevation)); expect(material.elevation, equals(focusElevation));
// Hover elevation overrides focus // Hover elevation overrides focus
TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); TestGesture? gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
await gesture.addPointer(); await gesture.addPointer();
addTearDown(() => gesture?.removePointer()); addTearDown(() => gesture?.removePointer());
await gesture.moveTo(tester.getCenter(find.byType(MaterialButton))); await gesture.moveTo(tester.getCenter(find.byType(MaterialButton)));
...@@ -305,7 +303,7 @@ void main() { ...@@ -305,7 +303,7 @@ void main() {
bool wasPressed; bool wasPressed;
Finder materialButton; Finder materialButton;
Widget buildFrame({ VoidCallback onPressed, VoidCallback onLongPress }) { Widget buildFrame({ VoidCallback? onPressed, VoidCallback? onLongPress }) {
return Directionality( return Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: MaterialButton( child: MaterialButton(
...@@ -395,7 +393,7 @@ void main() { ...@@ -395,7 +393,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(
...@@ -410,7 +408,7 @@ void main() { ...@@ -410,7 +408,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(
...@@ -425,7 +423,7 @@ void main() { ...@@ -425,7 +423,7 @@ void main() {
), ),
); );
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
}); });
// This test is very similar to the '...explicit splashColor and highlightColor' test // This test is very similar to the '...explicit splashColor and highlightColor' test
...@@ -654,7 +652,7 @@ void main() { ...@@ -654,7 +652,7 @@ void main() {
}); });
testWidgets('MaterialButton minWidth and height parameters', (WidgetTester tester) async { testWidgets('MaterialButton minWidth and height parameters', (WidgetTester tester) async {
Widget buildFrame({ double minWidth, double height, EdgeInsets padding = EdgeInsets.zero, Widget child }) { Widget buildFrame({ double? minWidth, double? height, EdgeInsets padding = EdgeInsets.zero, Widget? child }) {
return Directionality( return Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Center( child: Center(
......
...@@ -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';
......
...@@ -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/painting.dart'; import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -13,7 +11,7 @@ import '../rendering/mock_canvas.dart'; ...@@ -13,7 +11,7 @@ import '../rendering/mock_canvas.dart';
import '../widgets/test_border.dart' show TestBorder; import '../widgets/test_border.dart' show TestBorder;
class NotifyMaterial extends StatelessWidget { class NotifyMaterial extends StatelessWidget {
const NotifyMaterial({ Key key }) : super(key: key); const NotifyMaterial({ Key? key }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
LayoutChangedNotification().dispatch(context); LayoutChangedNotification().dispatch(context);
...@@ -380,22 +378,6 @@ void main() { ...@@ -380,22 +378,6 @@ void main() {
expect(find.byKey(materialKey), hasNoImmediateClip); expect(find.byKey(materialKey), hasNoImmediateClip);
}); });
testWidgets('Null clipBehavior asserts', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey();
Future<void> doPump() async {
await tester.pumpWidget(
Material(
key: materialKey,
type: MaterialType.transparency,
child: const SizedBox(width: 100.0, height: 100.0),
clipBehavior: null,
),
);
}
expect(() async => doPump(), throwsAssertionError);
});
testWidgets('clips to bounding rect by default given Clip.antiAlias', (WidgetTester tester) async { testWidgets('clips to bounding rect by default given Clip.antiAlias', (WidgetTester tester) async {
final GlobalKey materialKey = GlobalKey(); final GlobalKey materialKey = GlobalKey();
await tester.pumpWidget( await tester.pumpWidget(
......
...@@ -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';
...@@ -15,55 +13,55 @@ enum RadiusType { ...@@ -15,55 +13,55 @@ enum RadiusType {
Round Round
} }
void matches(BorderRadius borderRadius, RadiusType top, RadiusType bottom) { void matches(BorderRadius? borderRadius, RadiusType top, RadiusType bottom) {
final Radius cardRadius = kMaterialEdges[MaterialType.card].topLeft; final Radius cardRadius = kMaterialEdges[MaterialType.card]!.topLeft;
if (top == RadiusType.Sharp) { if (top == RadiusType.Sharp) {
expect(borderRadius.topLeft, equals(Radius.zero)); expect(borderRadius?.topLeft, equals(Radius.zero));
expect(borderRadius.topRight, equals(Radius.zero)); expect(borderRadius?.topRight, equals(Radius.zero));
} else if (top == RadiusType.Shifting) { } else if (top == RadiusType.Shifting) {
expect(borderRadius.topLeft.x, greaterThan(0.0)); expect(borderRadius?.topLeft.x, greaterThan(0.0));
expect(borderRadius.topLeft.x, lessThan(cardRadius.x)); expect(borderRadius?.topLeft.x, lessThan(cardRadius.x));
expect(borderRadius.topLeft.y, greaterThan(0.0)); expect(borderRadius?.topLeft.y, greaterThan(0.0));
expect(borderRadius.topLeft.y, lessThan(cardRadius.y)); expect(borderRadius?.topLeft.y, lessThan(cardRadius.y));
expect(borderRadius.topRight.x, greaterThan(0.0)); expect(borderRadius?.topRight.x, greaterThan(0.0));
expect(borderRadius.topRight.x, lessThan(cardRadius.x)); expect(borderRadius?.topRight.x, lessThan(cardRadius.x));
expect(borderRadius.topRight.y, greaterThan(0.0)); expect(borderRadius?.topRight.y, greaterThan(0.0));
expect(borderRadius.topRight.y, lessThan(cardRadius.y)); expect(borderRadius?.topRight.y, lessThan(cardRadius.y));
} else { } else {
expect(borderRadius.topLeft, equals(cardRadius)); expect(borderRadius?.topLeft, equals(cardRadius));
expect(borderRadius.topRight, equals(cardRadius)); expect(borderRadius?.topRight, equals(cardRadius));
} }
if (bottom == RadiusType.Sharp) { if (bottom == RadiusType.Sharp) {
expect(borderRadius.bottomLeft, equals(Radius.zero)); expect(borderRadius?.bottomLeft, equals(Radius.zero));
expect(borderRadius.bottomRight, equals(Radius.zero)); expect(borderRadius?.bottomRight, equals(Radius.zero));
} else if (bottom == RadiusType.Shifting) { } else if (bottom == RadiusType.Shifting) {
expect(borderRadius.bottomLeft.x, greaterThan(0.0)); expect(borderRadius?.bottomLeft.x, greaterThan(0.0));
expect(borderRadius.bottomLeft.x, lessThan(cardRadius.x)); expect(borderRadius?.bottomLeft.x, lessThan(cardRadius.x));
expect(borderRadius.bottomLeft.y, greaterThan(0.0)); expect(borderRadius?.bottomLeft.y, greaterThan(0.0));
expect(borderRadius.bottomLeft.y, lessThan(cardRadius.y)); expect(borderRadius?.bottomLeft.y, lessThan(cardRadius.y));
expect(borderRadius.bottomRight.x, greaterThan(0.0)); expect(borderRadius?.bottomRight.x, greaterThan(0.0));
expect(borderRadius.bottomRight.x, lessThan(cardRadius.x)); expect(borderRadius?.bottomRight.x, lessThan(cardRadius.x));
expect(borderRadius.bottomRight.y, greaterThan(0.0)); expect(borderRadius?.bottomRight.y, greaterThan(0.0));
expect(borderRadius.bottomRight.y, lessThan(cardRadius.y)); expect(borderRadius?.bottomRight.y, lessThan(cardRadius.y));
} else { } else {
expect(borderRadius.bottomLeft, equals(cardRadius)); expect(borderRadius?.bottomLeft, equals(cardRadius));
expect(borderRadius.bottomRight, equals(cardRadius)); expect(borderRadius?.bottomRight, equals(cardRadius));
} }
} }
// Returns the border radius decoration of an item within a MergeableMaterial. // Returns the border radius decoration of an item within a MergeableMaterial.
// This depends on the exact structure of objects built by the Material and // This depends on the exact structure of objects built by the Material and
// MergeableMaterial widgets. // MergeableMaterial widgets.
BorderRadius getBorderRadius(WidgetTester tester, int index) { BorderRadius? getBorderRadius(WidgetTester tester, int index) {
final List<Element> containers = tester.elementList(find.byType(Container)) final List<Element> containers = tester.elementList(find.byType(Container))
.toList(); .toList();
final Container container = containers[index].widget as Container; final Container container = containers[index].widget as Container;
final BoxDecoration boxDecoration = container.decoration as BoxDecoration; final BoxDecoration? boxDecoration = container.decoration as BoxDecoration?;
return boxDecoration.borderRadius as BorderRadius; return boxDecoration!.borderRadius as BorderRadius?;
} }
void main() { void main() {
...@@ -221,8 +219,8 @@ void main() { ...@@ -221,8 +219,8 @@ void main() {
), ),
); );
final BoxShadow boxShadow = kElevationToShadow[2][0]; final BoxShadow boxShadow = kElevationToShadow[2]![0];
final RRect rrect = kMaterialEdges[MaterialType.card].toRRect( final RRect rrect = kMaterialEdges[MaterialType.card]!.toRRect(
const Rect.fromLTRB(0.0, 0.0, 800.0, 100.0) const Rect.fromLTRB(0.0, 0.0, 800.0, 100.0)
); );
expect( expect(
...@@ -1201,6 +1199,6 @@ void main() { ...@@ -1201,6 +1199,6 @@ void main() {
final DecoratedBox decoratedBox = tester.widget(find.byType(DecoratedBox).last); final DecoratedBox decoratedBox = tester.widget(find.byType(DecoratedBox).last);
final BoxDecoration decoration = decoratedBox.decoration as BoxDecoration; final BoxDecoration decoration = decoratedBox.decoration as BoxDecoration;
// Since we are getting the last DecoratedBox, it will have a Border.top. // Since we are getting the last DecoratedBox, it will have a Border.top.
expect(decoration.border.top.color, dividerColor); expect(decoration.border!.top.color, dividerColor);
}); });
} }
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