Unverified Commit e48c9b55 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

[NNBD] Migrating some Material tests (#67689)

parent d6d06ed9
......@@ -2,13 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
MaterialApp _appWithDialog(WidgetTester tester, Widget dialog, { ThemeData theme }) {
MaterialApp _appWithDialog(WidgetTester tester, Widget dialog, { ThemeData? theme }) {
return MaterialApp(
theme: theme,
home: Material(
......@@ -40,7 +38,7 @@ Material _getMaterialFromDialog(WidgetTester tester) {
}
RenderParagraph _getTextRenderObject(WidgetTester tester, String text) {
return tester.element<StatelessElement>(find.text(text)).renderObject as RenderParagraph;
return tester.element<StatelessElement>(find.text(text)).renderObject! as RenderParagraph;
}
void main() {
......@@ -184,7 +182,7 @@ void main() {
await tester.pumpAndSettle();
final RenderParagraph title = _getTextRenderObject(tester, titleText);
expect(title.text.style.color, titleTextStyle.color);
expect(title.text.style!.color, titleTextStyle.color);
});
testWidgets('Simple Dialog - Custom Title Text Style - Constructor Param', (WidgetTester tester) async {
......@@ -232,7 +230,7 @@ void main() {
await tester.pumpAndSettle();
final RenderParagraph title = _getTextRenderObject(tester, titleText);
expect(title.text.style.color, titleTextStyle.color);
expect(title.text.style!.color, titleTextStyle.color);
});
testWidgets('Custom Content Text Style - Constructor Param', (WidgetTester tester) async {
......@@ -283,6 +281,6 @@ void main() {
await tester.pumpAndSettle();
final RenderParagraph content = _getTextRenderObject(tester, contentText);
expect(content.text.style.color, contentTextStyle.color);
expect(content.text.style!.color, contentTextStyle.color);
});
}
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/painting.dart';
......@@ -22,8 +20,8 @@ void main() {
final RenderBox box = tester.firstRenderObject(find.byType(Divider));
expect(box.size.height, 16.0);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration as BoxDecoration;
expect(decoration.border.bottom.width, 0.0);
final BoxDecoration decoration = container.decoration! as BoxDecoration;
expect(decoration.border!.bottom.width, 0.0);
});
testWidgets('Divider custom thickness', (WidgetTester tester) async {
......@@ -38,8 +36,8 @@ void main() {
),
);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration as BoxDecoration;
expect(decoration.border.bottom.width, 5.0);
final BoxDecoration decoration = container.decoration! as BoxDecoration;
expect(decoration.border!.bottom.width, 5.0);
});
testWidgets('Horizontal divider custom indentation', (WidgetTester tester) async {
......@@ -107,8 +105,8 @@ void main() {
final RenderBox box = tester.firstRenderObject(find.byType(VerticalDivider));
expect(box.size.width, 16.0);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration as BoxDecoration;
final Border border = decoration.border as Border;
final BoxDecoration decoration = container.decoration! as BoxDecoration;
final Border border = decoration.border! as Border;
expect(border.left.width, 0.0);
});
......@@ -124,8 +122,8 @@ void main() {
),
);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration as BoxDecoration;
final Border border = decoration.border as Border;
final BoxDecoration decoration = container.decoration! as BoxDecoration;
final Border border = decoration.border! as Border;
expect(border.left.width, 5.0);
});
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -71,11 +69,11 @@ void main() {
expect(box.size.height, 16.0);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration as BoxDecoration;
expect(decoration.border.bottom.width, 0.0);
final BoxDecoration decoration = container.decoration! as BoxDecoration;
expect(decoration.border!.bottom.width, 0.0);
final ThemeData theme = ThemeData();
expect(decoration.border.bottom.color, theme.dividerColor);
expect(decoration.border!.bottom.color, theme.dividerColor);
final Rect dividerRect = tester.getRect(find.byType(Divider));
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
......@@ -96,14 +94,14 @@ void main() {
expect(box.size.height, dividerTheme.space);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration as BoxDecoration;
expect(decoration.border.bottom.width, dividerTheme.thickness);
expect(decoration.border.bottom.color, dividerTheme.color);
final BoxDecoration decoration = container.decoration! as BoxDecoration;
expect(decoration.border!.bottom.width, dividerTheme.thickness);
expect(decoration.border!.bottom.color, dividerTheme.color);
final Rect dividerRect = tester.getRect(find.byType(Divider));
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.left, dividerRect.left + dividerTheme.indent);
expect(lineRect.right, dividerRect.right - dividerTheme.endIndent);
expect(lineRect.left, dividerRect.left + dividerTheme.indent!);
expect(lineRect.right, dividerRect.right - dividerTheme.endIndent!);
});
testWidgets('Widget properties take priority over theme', (WidgetTester tester) async {
......@@ -131,9 +129,9 @@ void main() {
expect(box.size.height, height);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration as BoxDecoration;
expect(decoration.border.bottom.width, thickness);
expect(decoration.border.bottom.color, color);
final BoxDecoration decoration = container.decoration! as BoxDecoration;
expect(decoration.border!.bottom.width, thickness);
expect(decoration.border!.bottom.color, color);
final Rect dividerRect = tester.getRect(find.byType(Divider));
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
......@@ -154,8 +152,8 @@ void main() {
expect(box.size.width, 16.0);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration as BoxDecoration;
final Border border = decoration.border as Border;
final BoxDecoration decoration = container.decoration! as BoxDecoration;
final Border border = decoration.border! as Border;
expect(border.left.width, 0.0);
final ThemeData theme = ThemeData();
......@@ -180,15 +178,15 @@ void main() {
expect(box.size.width, dividerTheme.space);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration as BoxDecoration;
final Border border = decoration.border as Border;
final BoxDecoration decoration = container.decoration! as BoxDecoration;
final Border border = decoration.border! as Border;
expect(border.left.width, dividerTheme.thickness);
expect(border.left.color, dividerTheme.color);
final Rect dividerRect = tester.getRect(find.byType(VerticalDivider));
final Rect lineRect = tester.getRect(find.byType(DecoratedBox));
expect(lineRect.top, dividerRect.top + dividerTheme.indent);
expect(lineRect.bottom, dividerRect.bottom - dividerTheme.endIndent);
expect(lineRect.top, dividerRect.top + dividerTheme.indent!);
expect(lineRect.bottom, dividerRect.bottom - dividerTheme.endIndent!);
});
testWidgets('Widget properties take priority over theme', (WidgetTester tester) async {
......@@ -216,8 +214,8 @@ void main() {
expect(box.size.width, width);
final Container container = tester.widget(find.byType(Container));
final BoxDecoration decoration = container.decoration as BoxDecoration;
final Border border = decoration.border as Border;
final BoxDecoration decoration = container.decoration! as BoxDecoration;
final Border border = decoration.border! as Border;
expect(border.left.width, thickness);
expect(border.left.color, color);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
......@@ -126,7 +124,7 @@ void main() {
}
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
Widget buildFrame({ Color drawerScrimColor }) {
Widget buildFrame({ Color? drawerScrimColor }) {
return MaterialApp(
home: Scaffold(
key: scaffoldKey,
......@@ -147,7 +145,7 @@ void main() {
// Default drawerScrimColor
await tester.pumpWidget(buildFrame(drawerScrimColor: null));
scaffoldKey.currentState.openDrawer();
scaffoldKey.currentState!.openDrawer();
await tester.pumpAndSettle();
expect(getScrim().color, Colors.black54);
......@@ -159,7 +157,7 @@ void main() {
// Specific drawerScrimColor
await tester.pumpWidget(buildFrame(drawerScrimColor: const Color(0xFF323232)));
scaffoldKey.currentState.openDrawer();
scaffoldKey.currentState!.openDrawer();
await tester.pumpAndSettle();
expect(getScrim().color, const Color(0xFF323232));
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math;
import 'dart:ui' show window;
......@@ -14,7 +12,7 @@ import 'package:flutter/rendering.dart';
import '../rendering/mock_canvas.dart';
const List<String> menuItems = <String>['one', 'two', 'three', 'four'];
final ValueChanged<String> onChanged = (_) { };
final ValueChanged<String?> onChanged = (_) { };
final Type dropdownButtonType = DropdownButton<String>(
onChanged: (_) { },
items: const <DropdownMenuItem<String>>[],
......@@ -28,22 +26,22 @@ Finder _iconRichText(Key iconKey) {
}
Widget buildFormFrame({
Key buttonKey,
Key? buttonKey,
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
int elevation = 8,
String value = 'two',
ValueChanged<String> onChanged,
VoidCallback onTap,
Widget icon,
Color iconDisabledColor,
Color iconEnabledColor,
String? value = 'two',
ValueChanged<String?>? onChanged,
VoidCallback? onTap,
Widget? icon,
Color? iconDisabledColor,
Color? iconEnabledColor,
double iconSize = 24.0,
bool isDense = true,
bool isExpanded = false,
Widget hint,
Widget disabledHint,
Widget underline,
List<String> items = menuItems,
Widget? hint,
Widget? disabledHint,
Widget? underline,
List<String>? items = menuItems,
Alignment alignment = Alignment.center,
TextDirection textDirection = TextDirection.ltr,
}) {
......@@ -112,15 +110,15 @@ class _TestAppState extends State<TestApp> {
class TestApp extends StatefulWidget {
const TestApp({
Key key,
this.textDirection,
this.child,
Key? key,
required this.textDirection,
required this.child,
this.mediaSize,
}) : super(key: key);
final TextDirection textDirection;
final Widget child;
final Size mediaSize;
final Size? mediaSize;
@override
_TestAppState createState() => _TestAppState();
......@@ -129,7 +127,7 @@ class TestApp extends StatefulWidget {
void verifyPaintedShadow(Finder customPaint, int elevation) {
const Rect originalRectangle = Rect.fromLTRB(0.0, 0.0, 800, 208.0);
final List<BoxShadow> boxShadows = List<BoxShadow>.generate(3, (int index) => kElevationToShadow[elevation][index]);
final List<BoxShadow> boxShadows = List<BoxShadow>.generate(3, (int index) => kElevationToShadow[elevation]![index]);
final List<RRect> rrects = List<RRect>.generate(3, (int index) {
return RRect.fromRectAndRadius(
originalRectangle.shift(
......@@ -151,7 +149,7 @@ void verifyPaintedShadow(Finder customPaint, int elevation) {
void main() {
testWidgets('DropdownButtonFormField with autovalidation test', (WidgetTester tester) async {
String value = 'one';
String? value = 'one';
int _validateCalled = 0;
await tester.pumpWidget(
......@@ -171,12 +169,12 @@ void main() {
child: Text(value),
);
}).toList(),
onChanged: (String newValue) {
onChanged: (String? newValue) {
setState(() {
value = newValue;
});
},
validator: (String currentValue) {
validator: (String? currentValue) {
_validateCalled++;
return currentValue == null ? 'Must select value' : null;
},
......@@ -340,14 +338,14 @@ void main() {
),
);
expect(richText.text.style.color, Colors.amber);
expect(richText.text.style.fontSize, 20.0);
expect(richText.text.style!.color, Colors.amber);
expect(richText.text.style!.fontSize, 20.0);
});
testWidgets('DropdownButtonFormField - disabledHint displays when the items list is empty, when items is null', (WidgetTester tester) async {
final Key buttonKey = UniqueKey();
Widget build({ List<String> items }){
Widget build({ List<String>? items }){
return buildFormFrame(
items: items,
buttonKey: buttonKey,
......@@ -373,7 +371,7 @@ void main() {
(WidgetTester tester) async {
final Key buttonKey = UniqueKey();
Widget build({ List<String> items }){
Widget build({ List<String>? items }){
return buildFormFrame(
items: items,
buttonKey: buttonKey,
......@@ -395,7 +393,7 @@ void main() {
testWidgets('DropdownButtonFormField - disabledHint is null by default', (WidgetTester tester) async {
final Key buttonKey = UniqueKey();
Widget build({ List<String> items }){
Widget build({ List<String>? items }){
return buildFormFrame(
items: items,
buttonKey: buttonKey,
......@@ -415,7 +413,7 @@ void main() {
testWidgets('DropdownButtonFormField - disabledHint is null by default', (WidgetTester tester) async {
final Key buttonKey = UniqueKey();
Widget build({ List<String> items }){
Widget build({ List<String>? items }){
return buildFormFrame(
items: items,
buttonKey: buttonKey,
......@@ -435,7 +433,7 @@ void main() {
testWidgets('DropdownButtonFormField - disabledHint displays when onChanged is null', (WidgetTester tester) async {
final Key buttonKey = UniqueKey();
Widget build({ List<String> items, ValueChanged<String> onChanged }){
Widget build({ List<String>? items, ValueChanged<String?>? onChanged }){
return buildFormFrame(
items: items,
buttonKey: buttonKey,
......@@ -453,7 +451,7 @@ void main() {
testWidgets('DropdownButtonFormField - disabled hint should be of same size as enabled hint', (WidgetTester tester) async {
final Key buttonKey = UniqueKey();
Widget build({ List<String> items}){
Widget build({ List<String>? items}){
return buildFormFrame(
items: items,
buttonKey: buttonKey,
......@@ -493,7 +491,7 @@ void main() {
// test for enabled color
final RichText enabledRichText = tester.widget<RichText>(_iconRichText(iconKey));
expect(enabledRichText.text.style.color, Colors.pink);
expect(enabledRichText.text.style!.color, Colors.pink);
// test for disabled color
await tester.pumpWidget(buildFormFrame(
......@@ -505,7 +503,7 @@ void main() {
));
final RichText disabledRichText = tester.widget<RichText>(_iconRichText(iconKey));
expect(disabledRichText.text.style.color, Colors.orange);
expect(disabledRichText.text.style!.color, Colors.orange);
});
testWidgets('DropdownButtonFormField - default elevation', (WidgetTester tester) async {
......@@ -583,7 +581,7 @@ void main() {
home: Scaffold(
body: DropdownButtonFormField<String>(
value: 'c',
onChanged: (String newValue) {},
onChanged: (String? newValue) {},
items: itemsWithDuplicateValues,
),
),
......@@ -614,7 +612,7 @@ void main() {
home: Scaffold(
body: DropdownButton<String>(
value: 'e',
onChanged: (String newValue) {},
onChanged: (String? newValue) {},
items: itemsWithDuplicateValues,
),
),
......@@ -636,7 +634,7 @@ void main() {
'Two',
'Three',
];
String selectedItem = items[0];
String? selectedItem = items[0];
await tester.pumpWidget(
StatefulBuilder(
......@@ -645,7 +643,7 @@ void main() {
home: Scaffold(
body: DropdownButtonFormField<String>(
value: selectedItem,
onChanged: (String string) => setState(() => selectedItem = string),
onChanged: (String? string) => setState(() => selectedItem = string),
selectedItemBuilder: (BuildContext context) {
int index = 0;
return items.map((String string) {
......@@ -676,8 +674,10 @@ void main() {
testWidgets('DropdownButton onTap callback is called when defined', (WidgetTester tester) async {
int dropdownButtonTapCounter = 0;
String value = 'one';
void onChanged(String newValue) { value = newValue; }
String? value = 'one';
void onChanged(String? newValue) {
value = newValue;
}
void onTap() { dropdownButtonTapCounter += 1; }
Widget build() => buildFormFrame(
......@@ -780,7 +780,7 @@ void main() {
);
}).toList(),
onChanged: onChanged,
validator: (String value) {
validator: (String? value) {
_validateCalled++;
return null;
},
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -37,10 +35,10 @@ void main() {
expect(material.elevation, 2);
expect(material.shadowColor, const Color(0xff000000));
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)));
expect(material.textStyle.color, colorScheme.onPrimary);
expect(material.textStyle.fontFamily, 'Roboto');
expect(material.textStyle.fontSize, 14);
expect(material.textStyle.fontWeight, FontWeight.w500);
expect(material.textStyle!.color, colorScheme.onPrimary);
expect(material.textStyle!.fontFamily, 'Roboto');
expect(material.textStyle!.fontSize, 14);
expect(material.textStyle!.fontWeight, FontWeight.w500);
});
group('[Theme, TextTheme, ElevatedButton style overrides]', () {
......@@ -78,7 +76,7 @@ void main() {
enableFeedback: enableFeedback,
);
Widget buildFrame({ ButtonStyle buttonStyle, ButtonStyle themeStyle, ButtonStyle overallStyle }) {
Widget buildFrame({ ButtonStyle? buttonStyle, ButtonStyle? themeStyle, ButtonStyle? overallStyle }) {
final Widget child = Builder(
builder: (BuildContext context) {
return ElevatedButton(
......@@ -124,16 +122,16 @@ void main() {
void checkButton(WidgetTester tester) {
final Material material = tester.widget<Material>(findMaterial);
final InkWell inkWell = tester.widget<InkWell>(findInkWell);
expect(material.textStyle.color, onPrimaryColor);
expect(material.textStyle.fontSize, 12);
expect(material.textStyle!.color, onPrimaryColor);
expect(material.textStyle!.fontSize, 12);
expect(material.color, primaryColor);
expect(material.shadowColor, shadowColor);
expect(material.elevation, elevation);
expect(MaterialStateProperty.resolveAs<MouseCursor>(inkWell.mouseCursor, enabled), enabledMouseCursor);
expect(MaterialStateProperty.resolveAs<MouseCursor>(inkWell.mouseCursor, disabled), disabledMouseCursor);
expect(inkWell.overlayColor.resolve(hovered), onPrimaryColor.withOpacity(0.08));
expect(inkWell.overlayColor.resolve(focused), onPrimaryColor.withOpacity(0.24));
expect(inkWell.overlayColor.resolve(pressed), onPrimaryColor.withOpacity(0.24));
expect(MaterialStateProperty.resolveAs<MouseCursor>(inkWell.mouseCursor!, enabled), enabledMouseCursor);
expect(MaterialStateProperty.resolveAs<MouseCursor>(inkWell.mouseCursor!, disabled), disabledMouseCursor);
expect(inkWell.overlayColor!.resolve(hovered), onPrimaryColor.withOpacity(0.08));
expect(inkWell.overlayColor!.resolve(focused), onPrimaryColor.withOpacity(0.24));
expect(inkWell.overlayColor!.resolve(pressed), onPrimaryColor.withOpacity(0.24));
expect(inkWell.enableFeedback, enableFeedback);
expect(material.borderRadius, null);
expect(material.shape, shape);
......@@ -185,7 +183,7 @@ void main() {
const Color shadowColor = Color(0xff000001);
const Color overiddenColor = Color(0xff000002);
Widget buildFrame({ Color overallShadowColor, Color themeShadowColor, Color shadowColor }) {
Widget buildFrame({ Color? overallShadowColor, Color? themeShadowColor, Color? shadowColor }) {
return MaterialApp(
theme: ThemeData.from(colorScheme: colorScheme).copyWith(
shadowColor: overallShadowColor,
......
......@@ -2,12 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Widget wrap({ Widget child, ThemeData theme }) {
Widget wrap({ required Widget child, ThemeData? theme }) {
return MaterialApp(
theme: theme,
home: Center(
......
......@@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
class SimpleExpansionPanelListTestWidget extends StatefulWidget {
const SimpleExpansionPanelListTestWidget({
Key key,
Key? key,
this.firstPanelKey,
this.secondPanelKey,
this.canTapOnHeader = false,
......@@ -18,14 +16,14 @@ class SimpleExpansionPanelListTestWidget extends StatefulWidget {
this.elevation = 2,
}) : super(key: key);
final Key firstPanelKey;
final Key secondPanelKey;
final Key? firstPanelKey;
final Key? secondPanelKey;
final bool canTapOnHeader;
final Color dividerColor;
final Color? dividerColor;
final int elevation;
/// If null, the default [ExpansionPanelList]'s expanded header padding value is applied via [defaultExpandedHeaderPadding]
final EdgeInsets expandedHeaderPadding;
final EdgeInsets? expandedHeaderPadding;
/// Mirrors the default expanded header padding as its source constants are private.
static EdgeInsets defaultExpandedHeaderPadding()
......@@ -74,7 +72,7 @@ class _SimpleExpansionPanelListTestWidgetState extends State<SimpleExpansionPane
}
class ExpansionPanelListSemanticsTest extends StatefulWidget {
const ExpansionPanelListSemanticsTest({ Key key, this.headerKey }) : super(key: key);
const ExpansionPanelListSemanticsTest({ Key? key, required this.headerKey }) : super(key: key);
final Key headerKey;
......@@ -118,8 +116,8 @@ class ExpansionPanelListSemanticsTestState extends State<ExpansionPanelListSeman
void main() {
testWidgets('ExpansionPanelList test', (WidgetTester tester) async {
int index;
bool isExpanded;
late int index;
late bool isExpanded;
await tester.pumpWidget(
MaterialApp(
......@@ -1364,7 +1362,7 @@ void main() {
final BoxDecoration decoration = decoratedBox.decoration as BoxDecoration;
// For the last DecoratedBox, we will have a Border.top with the provided dividerColor.
expect(decoration.border.top.color, dividerColor);
expect(decoration.border!.top.color, dividerColor);
});
testWidgets('ExpansionPanelList.radio respects DividerColor', (WidgetTester tester) async {
......@@ -1397,7 +1395,7 @@ void main() {
final BoxDecoration boxDecoration = decoratedBox.decoration as BoxDecoration;
// For the last DecoratedBox, we will have a Border.top with the provided dividerColor.
expect(boxDecoration.border.top.color, dividerColor);
expect(boxDecoration.border!.top.color, dividerColor);
});
testWidgets('elevation is propagated properly to MergeableMaterial', (WidgetTester tester) async {
......
......@@ -2,21 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
class TestIcon extends StatefulWidget {
const TestIcon({Key key}) : super(key: key);
const TestIcon({Key? key}) : super(key: key);
@override
TestIconState createState() => TestIconState();
}
class TestIconState extends State<TestIcon> {
IconThemeData iconTheme;
late IconThemeData iconTheme;
@override
Widget build(BuildContext context) {
......@@ -26,7 +24,7 @@ class TestIconState extends State<TestIcon> {
}
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;
......@@ -35,7 +33,7 @@ class TestText extends StatefulWidget {
}
class TestTextState extends State<TestText> {
TextStyle textStyle;
late TextStyle textStyle;
@override
Widget build(BuildContext context) {
......@@ -113,15 +111,15 @@ void main() {
expect(getHeight(topKey), getHeight(collapsedKey) - 2.0);
expect(getHeight(topKey), getHeight(defaultKey) - 2.0);
BoxDecoration expandedContainerDecoration = getContainer(expandedKey).decoration as BoxDecoration;
BoxDecoration expandedContainerDecoration = getContainer(expandedKey).decoration! as BoxDecoration;
expect(expandedContainerDecoration.color, Colors.red);
expect(expandedContainerDecoration.border.top.color, _dividerColor);
expect(expandedContainerDecoration.border.bottom.color, _dividerColor);
expect(expandedContainerDecoration.border!.top.color, _dividerColor);
expect(expandedContainerDecoration.border!.bottom.color, _dividerColor);
BoxDecoration collapsedContainerDecoration = getContainer(collapsedKey).decoration as BoxDecoration;
BoxDecoration collapsedContainerDecoration = getContainer(collapsedKey).decoration! as BoxDecoration;
expect(collapsedContainerDecoration.color, Colors.transparent);
expect(collapsedContainerDecoration.border.top.color, Colors.transparent);
expect(collapsedContainerDecoration.border.bottom.color, Colors.transparent);
expect(collapsedContainerDecoration.border!.top.color, Colors.transparent);
expect(collapsedContainerDecoration.border!.bottom.color, Colors.transparent);
await tester.tap(find.text('Expanded'));
await tester.tap(find.text('Collapsed'));
......@@ -131,11 +129,11 @@ void main() {
// Pump to the middle of the animation for expansion.
await tester.pump(const Duration(milliseconds: 100));
final BoxDecoration collapsingContainerDecoration = getContainer(collapsedKey).decoration as BoxDecoration;
final BoxDecoration collapsingContainerDecoration = getContainer(collapsedKey).decoration! as BoxDecoration;
expect(collapsingContainerDecoration.color, Colors.transparent);
// Opacity should change but color component should remain the same.
expect(collapsingContainerDecoration.border.top.color, const Color(0x15333333));
expect(collapsingContainerDecoration.border.bottom.color, const Color(0x15333333));
expect(collapsingContainerDecoration.border!.top.color, const Color(0x15333333));
expect(collapsingContainerDecoration.border!.bottom.color, const Color(0x15333333));
// Pump all the way to the end now.
await tester.pump(const Duration(seconds: 1));
......@@ -145,16 +143,16 @@ void main() {
expect(getHeight(topKey), getHeight(defaultKey) - getHeight(tileKey) - 2.0);
// Expanded should be collapsed now.
expandedContainerDecoration = getContainer(expandedKey).decoration as BoxDecoration;
expandedContainerDecoration = getContainer(expandedKey).decoration! as BoxDecoration;
expect(expandedContainerDecoration.color, Colors.transparent);
expect(expandedContainerDecoration.border.top.color, Colors.transparent);
expect(expandedContainerDecoration.border.bottom.color, Colors.transparent);
expect(expandedContainerDecoration.border!.top.color, Colors.transparent);
expect(expandedContainerDecoration.border!.bottom.color, Colors.transparent);
// Collapsed should be expanded now.
collapsedContainerDecoration = getContainer(collapsedKey).decoration as BoxDecoration;
collapsedContainerDecoration = getContainer(collapsedKey).decoration! as BoxDecoration;
expect(collapsedContainerDecoration.color, Colors.transparent);
expect(collapsedContainerDecoration.border.top.color, _dividerColor);
expect(collapsedContainerDecoration.border.bottom.color, _dividerColor);
expect(collapsedContainerDecoration.border!.top.color, _dividerColor);
expect(collapsedContainerDecoration.border!.bottom.color, _dividerColor);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('ListTileTheme', (WidgetTester tester) async {
......@@ -195,8 +193,8 @@ void main() {
),
);
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 iconColor(Key key) => tester.state<TestIconState>(find.byKey(key)).iconTheme.color!;
Color textColor(Key key) => tester.state<TestTextState>(find.byKey(key)).textStyle.color!;
expect(textColor(expandedTitleKey), _accentColor);
expect(textColor(collapsedTitleKey), _headerColor);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -14,18 +12,18 @@ import 'feedback_tester.dart';
void main () {
const Duration kWaitDuration = Duration(seconds: 1);
FeedbackTester feedback;
late FeedbackTester feedback;
setUp(() {
feedback = FeedbackTester();
});
tearDown(() {
feedback?.dispose();
feedback.dispose();
});
group('Feedback on Android', () {
List<Map<String, Object>> semanticEvents;
late List<Map<String, Object>> semanticEvents;
setUp(() {
semanticEvents = <Map<String, Object>>[];
......@@ -60,10 +58,10 @@ void main () {
expect(feedback.clickSoundCount, 1);
expect(semanticEvents.single, <String, dynamic>{
'type': 'tap',
'nodeId': object.debugSemantics.id,
'nodeId': object.debugSemantics!.id,
'data': <String, dynamic>{},
});
expect(object.debugSemantics.getSemanticsData().hasAction(SemanticsAction.tap), true);
expect(object.debugSemantics!.getSemanticsData().hasAction(SemanticsAction.tap), true);
semanticsTester.dispose();
});
......@@ -78,7 +76,7 @@ void main () {
await tester.pumpWidget(TestWidget(
tapHandler: (BuildContext context) {
return Feedback.wrapForTap(callback, context);
return Feedback.wrapForTap(callback, context)!;
},
));
await tester.pumpAndSettle(kWaitDuration);
......@@ -95,10 +93,10 @@ void main () {
expect(callbackCount, 1);
expect(semanticEvents.single, <String, dynamic>{
'type': 'tap',
'nodeId': object.debugSemantics.id,
'nodeId': object.debugSemantics!.id,
'data': <String, dynamic>{},
});
expect(object.debugSemantics.getSemanticsData().hasAction(SemanticsAction.tap), true);
expect(object.debugSemantics!.getSemanticsData().hasAction(SemanticsAction.tap), true);
semanticsTester.dispose();
});
......@@ -123,10 +121,10 @@ void main () {
expect(feedback.clickSoundCount, 0);
expect(semanticEvents.single, <String, dynamic>{
'type': 'longPress',
'nodeId': object.debugSemantics.id,
'nodeId': object.debugSemantics!.id,
'data': <String, dynamic>{},
});
expect(object.debugSemantics.getSemanticsData().hasAction(SemanticsAction.longPress), true);
expect(object.debugSemantics!.getSemanticsData().hasAction(SemanticsAction.longPress), true);
semanticsTester.dispose();
});
......@@ -140,7 +138,7 @@ void main () {
await tester.pumpWidget(TestWidget(
longPressHandler: (BuildContext context) {
return Feedback.wrapForLongPress(callback, context);
return Feedback.wrapForLongPress(callback, context)!;
},
));
await tester.pumpAndSettle(kWaitDuration);
......@@ -157,10 +155,10 @@ void main () {
expect(callbackCount, 1);
expect(semanticEvents.single, <String, dynamic>{
'type': 'longPress',
'nodeId': object.debugSemantics.id,
'nodeId': object.debugSemantics!.id,
'data': <String, dynamic>{},
});
expect(object.debugSemantics.getSemanticsData().hasAction(SemanticsAction.longPress), true);
expect(object.debugSemantics!.getSemanticsData().hasAction(SemanticsAction.longPress), true);
semanticsTester.dispose();
});
......@@ -204,7 +202,7 @@ void main () {
class TestWidget extends StatelessWidget {
const TestWidget({
Key key,
Key? key,
this.tapHandler = nullHandler,
this.longPressHandler = nullHandler,
}) : super(key: key);
......@@ -212,7 +210,7 @@ class TestWidget extends StatelessWidget {
final HandlerCreator tapHandler;
final HandlerCreator longPressHandler;
static VoidCallback nullHandler(BuildContext context) => null;
static VoidCallback? nullHandler(BuildContext context) => null;
@override
Widget build(BuildContext context) {
......@@ -224,4 +222,4 @@ class TestWidget extends StatelessWidget {
}
}
typedef HandlerCreator = VoidCallback Function(BuildContext context);
typedef HandlerCreator = VoidCallback? Function(BuildContext context);
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