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

[NNBD] Migrating some Material tests (#67689)

parent d6d06ed9
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:ui';
import 'package:flutter/material.dart';
......@@ -13,7 +11,7 @@ import 'package:matcher/matcher.dart';
import '../widgets/semantics_tester.dart';
MaterialApp _buildAppWithDialog(Widget dialog, { ThemeData theme, double textScaleFactor = 1.0 }) {
MaterialApp _buildAppWithDialog(Widget dialog, { ThemeData? theme, double textScaleFactor = 1.0 }) {
return MaterialApp(
theme: theme,
home: Material(
......@@ -27,7 +25,7 @@ MaterialApp _buildAppWithDialog(Widget dialog, { ThemeData theme, double textSca
context: context,
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor),
child: dialog,
);
},
......@@ -46,7 +44,7 @@ Material _getMaterialFromDialog(WidgetTester tester) {
}
RenderParagraph _getTextRenderObjectFromDialog(WidgetTester tester, String text) {
return tester.element<StatelessElement>(find.descendant(of: find.byType(AlertDialog), matching: find.text(text))).renderObject as RenderParagraph;
return tester.element<StatelessElement>(find.descendant(of: find.byType(AlertDialog), matching: find.text(text))).renderObject! as RenderParagraph;
}
const ShapeBorder _defaultDialogShape = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)));
......@@ -276,7 +274,7 @@ void main() {
);
final Future<int> result = showDialog<int>(
context: navigator.currentContext,
context: navigator.currentContext!,
builder: (BuildContext context) {
return SimpleDialog(
title: const Text('Title'),
......@@ -678,73 +676,73 @@ void main() {
void expectLeftEdgePadding(
WidgetTester tester, {
Finder finder,
double textScaleFactor,
double unscaledValue,
required Finder finder,
required double textScaleFactor,
required double unscaledValue,
}) {
expect(
tester.getTopLeft(dialogFinder).dx,
moreOrLessEquals(tester.getTopLeft(finder).dx - unscaledValue * paddingScaleFactors[textScaleFactor]),
moreOrLessEquals(tester.getTopLeft(finder).dx - unscaledValue * paddingScaleFactors[textScaleFactor]!),
);
expect(
tester.getBottomLeft(dialogFinder).dx,
moreOrLessEquals(tester.getBottomLeft(finder).dx - unscaledValue * paddingScaleFactors[textScaleFactor]),
moreOrLessEquals(tester.getBottomLeft(finder).dx - unscaledValue * paddingScaleFactors[textScaleFactor]!),
);
}
void expectRightEdgePadding(
WidgetTester tester, {
Finder finder,
double textScaleFactor,
double unscaledValue,
required Finder finder,
required double textScaleFactor,
required double unscaledValue,
}) {
expect(
tester.getTopRight(dialogFinder).dx,
moreOrLessEquals(tester.getTopRight(finder).dx + unscaledValue * paddingScaleFactors[textScaleFactor]),
moreOrLessEquals(tester.getTopRight(finder).dx + unscaledValue * paddingScaleFactors[textScaleFactor]!),
);
expect(
tester.getBottomRight(dialogFinder).dx,
moreOrLessEquals(tester.getBottomRight(finder).dx + unscaledValue * paddingScaleFactors[textScaleFactor]),
moreOrLessEquals(tester.getBottomRight(finder).dx + unscaledValue * paddingScaleFactors[textScaleFactor]!),
);
}
void expectTopEdgePadding(
WidgetTester tester, {
Finder finder,
double textScaleFactor,
double unscaledValue,
required Finder finder,
required double textScaleFactor,
required double unscaledValue,
}) {
expect(
tester.getTopLeft(dialogFinder).dy,
moreOrLessEquals(tester.getTopLeft(finder).dy - unscaledValue * paddingScaleFactors[textScaleFactor]),
moreOrLessEquals(tester.getTopLeft(finder).dy - unscaledValue * paddingScaleFactors[textScaleFactor]!),
);
expect(
tester.getTopRight(dialogFinder).dy,
moreOrLessEquals(tester.getTopRight(finder).dy - unscaledValue * paddingScaleFactors[textScaleFactor]),
moreOrLessEquals(tester.getTopRight(finder).dy - unscaledValue * paddingScaleFactors[textScaleFactor]!),
);
}
void expectBottomEdgePadding(
WidgetTester tester, {
Finder finder,
double textScaleFactor,
double unscaledValue,
required Finder finder,
required double textScaleFactor,
required double unscaledValue,
}) {
expect(
tester.getBottomLeft(dialogFinder).dy,
moreOrLessEquals(tester.getBottomRight(finder).dy + unscaledValue * paddingScaleFactors[textScaleFactor]),
moreOrLessEquals(tester.getBottomRight(finder).dy + unscaledValue * paddingScaleFactors[textScaleFactor]!),
);
expect(
tester.getBottomRight(dialogFinder).dy,
moreOrLessEquals(tester.getBottomRight(finder).dy + unscaledValue * paddingScaleFactors[textScaleFactor]),
moreOrLessEquals(tester.getBottomRight(finder).dy + unscaledValue * paddingScaleFactors[textScaleFactor]!),
);
}
void expectVerticalInnerPadding(
WidgetTester tester, {
Finder top,
Finder bottom,
double value,
required Finder top,
required Finder bottom,
required double value,
}) {
expect(
tester.getBottomLeft(top).dy,
......@@ -1144,9 +1142,9 @@ void main() {
});
testWidgets('Dialogs removes MediaQuery padding and view insets', (WidgetTester tester) async {
BuildContext outerContext;
BuildContext routeContext;
BuildContext dialogContext;
late BuildContext outerContext;
late BuildContext routeContext;
late BuildContext dialogContext;
await tester.pumpWidget(Localizations(
locale: const Locale('en', 'US'),
......@@ -1190,12 +1188,12 @@ void main() {
await tester.pump();
expect(MediaQuery.of(outerContext).padding, const EdgeInsets.all(50.0));
expect(MediaQuery.of(routeContext).padding, EdgeInsets.zero);
expect(MediaQuery.of(dialogContext).padding, EdgeInsets.zero);
expect(MediaQuery.of(outerContext).viewInsets, const EdgeInsets.only(left: 25.0, bottom: 75.0));
expect(MediaQuery.of(routeContext).viewInsets, const EdgeInsets.only(left: 25.0, bottom: 75.0));
expect(MediaQuery.of(dialogContext).viewInsets, EdgeInsets.zero);
expect(MediaQuery.of(outerContext)!.padding, const EdgeInsets.all(50.0));
expect(MediaQuery.of(routeContext)!.padding, EdgeInsets.zero);
expect(MediaQuery.of(dialogContext)!.padding, EdgeInsets.zero);
expect(MediaQuery.of(outerContext)!.viewInsets, const EdgeInsets.only(left: 25.0, bottom: 75.0));
expect(MediaQuery.of(routeContext)!.viewInsets, const EdgeInsets.only(left: 25.0, bottom: 75.0));
expect(MediaQuery.of(dialogContext)!.viewInsets, EdgeInsets.zero);
});
testWidgets('Dialog widget insets by viewInsets', (WidgetTester tester) async {
......@@ -1386,7 +1384,7 @@ void main() {
// Dismiss is confirmed IFF confirmDismiss() returns true.
Future<bool> confirmDismiss (DismissDirection dismissDirection) {
return showDialog<bool>(
context: _scaffoldKey.currentContext,
context: _scaffoldKey.currentContext!,
barrierDismissible: true, // showDialog() returns null if tapped outside the dialog
builder: (BuildContext context) {
return AlertDialog(
......@@ -1551,11 +1549,11 @@ void main() {
testWidgets('showDialog safe area', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
builder: (BuildContext context, Widget child) {
builder: (BuildContext context, Widget? child) {
return MediaQuery(
// Set up the safe area to be 20 pixels in from each side
data: const MediaQueryData(padding: EdgeInsets.all(20.0)),
child: child,
child: child!,
);
},
home: const Center(child: Text('Test')),
......@@ -1741,13 +1739,13 @@ void main() {
});
testWidgets('Dialog with RouteSettings', (WidgetTester tester) async {
RouteSettings currentRouteSetting;
late RouteSettings currentRouteSetting;
await tester.pumpWidget(
MaterialApp(
navigatorObservers: <NavigatorObserver>[
_ClosureNavigatorObserver(onDidChange: (Route<dynamic> newRoute) {
currentRouteSetting = newRoute?.settings;
currentRouteSetting = newRoute.settings;
})
],
home: const Material(
......@@ -1773,7 +1771,7 @@ void main() {
SimpleDialogOption(
child: const Text('X'),
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context)!.pop();
},
),
],
......@@ -1791,7 +1789,7 @@ void main() {
expect(await result, isNull);
await tester.pumpAndSettle();
expect(currentRouteSetting?.name, '/');
expect(currentRouteSetting.name, '/');
});
}
......@@ -1799,7 +1797,7 @@ class DialogObserver extends NavigatorObserver {
int dialogCount = 0;
@override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (route.toString().contains('_DialogRoute')) {
dialogCount++;
}
......@@ -1808,19 +1806,19 @@ class DialogObserver extends NavigatorObserver {
}
class _ClosureNavigatorObserver extends NavigatorObserver {
_ClosureNavigatorObserver({@required this.onDidChange});
_ClosureNavigatorObserver({required this.onDidChange});
final void Function(Route<dynamic> newRoute) onDidChange;
@override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) => onDidChange(route);
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) => onDidChange(route);
@override
void didPop(Route<dynamic> route, Route<dynamic> previousRoute) => onDidChange(previousRoute);
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) => onDidChange(previousRoute!);
@override
void didRemove(Route<dynamic> route, Route<dynamic> previousRoute) => onDidChange(previousRoute);
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) => onDidChange(previousRoute!);
@override
void didReplace({Route<dynamic> newRoute, Route<dynamic> oldRoute}) => onDidChange(newRoute);
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) => onDidChange(newRoute!);
}
......@@ -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 'dart:math' as math;
import 'dart:ui' show window;
......@@ -18,7 +16,7 @@ import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart';
const List<String> menuItems = <String>['one', 'two', 'three', 'four'];
final ValueChanged<String> onChanged = (_) { };
final ValueChanged<String?> onChanged = (_) { };
final Type dropdownButtonType = DropdownButton<String>(
onChanged: (_) { },
......@@ -33,32 +31,32 @@ Finder _iconRichText(Key iconKey) {
}
Widget buildDropdown({
bool isFormField,
Key buttonKey,
String value = 'two',
ValueChanged<String> onChanged,
VoidCallback onTap,
Widget icon,
Color iconDisabledColor,
Color iconEnabledColor,
required bool isFormField,
Key? buttonKey,
String? value = 'two',
ValueChanged<String?>? onChanged,
VoidCallback? onTap,
Widget? icon,
Color? iconDisabledColor,
Color? iconEnabledColor,
double iconSize = 24.0,
bool isDense = false,
bool isExpanded = false,
Widget hint,
Widget disabledHint,
Widget underline,
List<String> items = menuItems,
List<Widget> Function(BuildContext) selectedItemBuilder,
double itemHeight = kMinInteractiveDimension,
Widget? hint,
Widget? disabledHint,
Widget? underline,
List<String>? items = menuItems,
List<Widget> Function(BuildContext)? selectedItemBuilder,
double? itemHeight = kMinInteractiveDimension,
Alignment alignment = Alignment.center,
TextDirection textDirection = TextDirection.ltr,
Size mediaSize,
FocusNode focusNode,
Size? mediaSize,
FocusNode? focusNode,
bool autofocus = false,
Color focusColor,
Color dropdownColor,
Color? focusColor,
Color? dropdownColor,
}) {
final List<DropdownMenuItem<String>> listItems = items == null
final List<DropdownMenuItem<String>>? listItems = items == null
? null
: items.map<DropdownMenuItem<String>>((String item) {
return DropdownMenuItem<String>(
......@@ -119,29 +117,29 @@ Widget buildDropdown({
}
Widget buildFrame({
Key buttonKey,
String value = 'two',
ValueChanged<String> onChanged,
VoidCallback onTap,
Widget icon,
Color iconDisabledColor,
Color iconEnabledColor,
Key? buttonKey,
String? value = 'two',
ValueChanged<String?>? onChanged,
VoidCallback? onTap,
Widget? icon,
Color? iconDisabledColor,
Color? iconEnabledColor,
double iconSize = 24.0,
bool isDense = false,
bool isExpanded = false,
Widget hint,
Widget disabledHint,
Widget underline,
List<String> items = menuItems,
List<Widget> Function(BuildContext) selectedItemBuilder,
double itemHeight = kMinInteractiveDimension,
Widget? hint,
Widget? disabledHint,
Widget? underline,
List<String>? items = menuItems,
List<Widget> Function(BuildContext)? selectedItemBuilder,
double? itemHeight = kMinInteractiveDimension,
Alignment alignment = Alignment.center,
TextDirection textDirection = TextDirection.ltr,
Size mediaSize,
FocusNode focusNode,
Size? mediaSize,
FocusNode? focusNode,
bool autofocus = false,
Color focusColor,
Color dropdownColor,
Color? focusColor,
Color? dropdownColor,
bool isFormField = false,
}) {
return TestApp(
......@@ -181,15 +179,15 @@ Widget buildFrame({
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();
......@@ -239,7 +237,7 @@ void checkSelectedItemTextGeometry(WidgetTester tester, String value) {
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(
......@@ -259,7 +257,7 @@ void verifyPaintedShadow(Finder customPaint, int elevation) {
);
}
Future<void> checkDropdownColor(WidgetTester tester, {Color color, bool isFormField = false }) async {
Future<void> checkDropdownColor(WidgetTester tester, {Color? color, bool isFormField = false }) async {
const String text = 'foo';
await tester.pumpWidget(
MaterialApp(
......@@ -340,8 +338,8 @@ void main() {
});
testWidgets('Dropdown button control test', (WidgetTester tester) async {
String value = 'one';
void didChangeValue(String newValue) {
String? value = 'one';
void didChangeValue(String? newValue) {
value = newValue;
}
......@@ -379,8 +377,8 @@ void main() {
});
testWidgets('Dropdown button with no app', (WidgetTester tester) async {
String value = 'one';
void didChangeValue(String newValue) {
String? value = 'one';
void didChangeValue(String? newValue) {
value = newValue;
}
......@@ -449,7 +447,7 @@ void main() {
home: Scaffold(
body: DropdownButton<String>(
value: 'c',
onChanged: (String newValue) {},
onChanged: (String? newValue) {},
items: itemsWithDuplicateValues,
),
),
......@@ -480,7 +478,7 @@ void main() {
home: Scaffold(
body: DropdownButton<String>(
value: 'e',
onChanged: (String newValue) {},
onChanged: (String? newValue) {},
items: itemsWithDuplicateValues,
),
),
......@@ -499,7 +497,7 @@ void main() {
testWidgets('Dropdown form field uses form field state', (WidgetTester tester) async {
final Key buttonKey = UniqueKey();
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
String value;
String? value;
await tester.pumpWidget(
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
......@@ -520,9 +518,9 @@ void main() {
child: Text(val)
);
}).toList(),
validator: (String v) => v == null ? 'Must select value' : null,
onChanged: (String newValue) {},
onSaved: (String v) {
validator: (String? v) => v == null ? 'Must select value' : null,
onChanged: (String? newValue) {},
onSaved: (String? v) {
setState(() {
value = v;
});
......@@ -536,7 +534,7 @@ void main() {
);
int getIndex() {
final IndexedStack stack = tester.element(find.byType(IndexedStack)).widget as IndexedStack;
return stack.index;
return stack.index!;
}
// Initial value of null displays hint
expect(value, equals(null));
......@@ -548,7 +546,7 @@ void main() {
expect(getIndex(), 2);
// Changes only made to FormField state until form saved
expect(value, equals(null));
final FormState form = formKey.currentState;
final FormState form = formKey.currentState!;
form.save();
expect(value, equals('three'));
});
......@@ -589,12 +587,12 @@ void main() {
});
testWidgets('Dropdown screen edges', (WidgetTester tester) async {
int value = 4;
int? value = 4;
final List<DropdownMenuItem<int>> items = <DropdownMenuItem<int>>[
for (int i = 0; i < 20; ++i) DropdownMenuItem<int>(value: i, child: Text('$i')),
];
void handleChanged(int newValue) {
void handleChanged(int? newValue) {
value = newValue;
}
......@@ -748,7 +746,7 @@ void main() {
// test for enabled color
final RichText enabledRichText = tester.widget<RichText>(_iconRichText(iconKey));
expect(enabledRichText.text.style.color, Colors.grey.shade700);
expect(enabledRichText.text.style!.color, Colors.grey.shade700);
// test for disabled color
await tester.pumpWidget(buildFrame(
......@@ -757,7 +755,7 @@ void main() {
));
final RichText disabledRichText = tester.widget<RichText>(_iconRichText(iconKey));
expect(disabledRichText.text.style.color, Colors.grey.shade400);
expect(disabledRichText.text.style!.color, Colors.grey.shade400);
});
testWidgets('Dropdown button icon should have the passed in size and color instead of defaults', (WidgetTester tester) async {
......@@ -778,7 +776,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(buildFrame(
......@@ -790,7 +788,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('Dropdown button should use its own size and color properties over those defined by the theme', (WidgetTester tester) async {
......@@ -817,7 +815,7 @@ void main() {
// test for enabled color
final RichText enabledRichText = tester.widget<RichText>(_iconRichText(iconKey));
expect(enabledRichText.text.style.color, Colors.yellow);
expect(enabledRichText.text.style!.color, Colors.yellow);
// test for disabled color
await tester.pumpWidget(buildFrame(
......@@ -829,7 +827,7 @@ void main() {
));
final RichText disabledRichText = tester.widget<RichText>(_iconRichText(iconKey));
expect(disabledRichText.text.style.color, Colors.yellow);
expect(disabledRichText.text.style!.color, Colors.yellow);
});
testWidgets('Dropdown button with isDense:true aligns selected menu item', (WidgetTester tester) async {
......@@ -950,7 +948,7 @@ void main() {
testWidgets('Size of DropdownButton with null value', (WidgetTester tester) async {
final Key buttonKey = UniqueKey();
String value;
String? value;
Widget build() => buildFrame(buttonKey: buttonKey, value: value, onChanged: onChanged);
......@@ -972,7 +970,7 @@ void main() {
testWidgets('Size of DropdownButton with no items', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/26419
final Key buttonKey = UniqueKey();
List<String> items;
List<String>? items;
Widget build() => buildFrame(buttonKey: buttonKey, items: items, onChanged: onChanged);
......@@ -998,9 +996,9 @@ void main() {
testWidgets('Layout of a DropdownButton with null value', (WidgetTester tester) async {
final Key buttonKey = UniqueKey();
String value;
String? value;
void onChanged(String newValue) {
void onChanged(String? newValue) {
value = newValue;
}
......@@ -1026,7 +1024,7 @@ void main() {
testWidgets('Size of DropdownButton with null value and a hint', (WidgetTester tester) async {
final Key buttonKey = UniqueKey();
String value;
String? value;
// The hint will define the dropdown's width
Widget build() => buildFrame(buttonKey: buttonKey, value: value, hint: const Text('onetwothree'));
......@@ -1052,10 +1050,10 @@ void main() {
// The dropdown menu isn't readily accessible. To find it we're assuming that it
// contains a ListView and that it's an instance of _DropdownMenu.
Rect getMenuRect() {
Rect menuRect;
late Rect menuRect;
tester.element(find.byType(ListView)).visitAncestorElements((Element element) {
if (element.toString().startsWith('_DropdownMenu')) {
final RenderBox box = element.findRenderObject() as RenderBox;
final RenderBox box = element.findRenderObject()! as RenderBox;
assert(box != null);
menuRect = box.localToGlobal(Offset.zero) & box.size;
return false;
......@@ -1077,8 +1075,8 @@ void main() {
return buttonPadding.inflateRect(buttonRect);
}
Rect buttonRect;
Rect menuRect;
late Rect buttonRect;
late Rect menuRect;
Future<void> popUpAndDown(Widget frame) async {
await tester.pumpWidget(frame);
......@@ -1197,7 +1195,7 @@ void main() {
buttonKey: key,
value: null,
items: menuItems,
onChanged: (String _) { },
onChanged: (String? _) { },
hint: const Text('test'),
));
......@@ -1309,7 +1307,7 @@ void main() {
testWidgets('disabledHint displays on empty items or onChanged', (WidgetTester tester) async {
final Key buttonKey = UniqueKey();
Widget build({ List<String> items, ValueChanged<String> onChanged }) => buildFrame(
Widget build({ List<String>? items, ValueChanged<String?>? onChanged }) => buildFrame(
items: items,
onChanged: onChanged,
buttonKey: buttonKey,
......@@ -1349,7 +1347,7 @@ void main() {
(WidgetTester tester) async {
final Key buttonKey = UniqueKey();
Widget build({ List<String> items }){
Widget build({ List<String>? items }){
return buildFrame(
items: items,
buttonKey: buttonKey,
......@@ -1371,7 +1369,7 @@ void main() {
testWidgets('DropdownButton disabledHint is null by default', (WidgetTester tester) async {
final Key buttonKey = UniqueKey();
Widget build({ List<String> items }){
Widget build({ List<String>? items }){
return buildFrame(
items: items,
buttonKey: buttonKey,
......@@ -1408,7 +1406,7 @@ void main() {
);
}).toList();
},
onChanged: (String newValue) {},
onChanged: (String? newValue) {},
));
final RenderBox dropdownButtonRenderBox = tester.renderObject<RenderBox>(
......@@ -1445,7 +1443,7 @@ void main() {
);
}).toList();
},
onChanged: (String newValue) {},
onChanged: (String? newValue) {},
));
final RenderBox dropdownButtonRenderBox = tester.renderObject<RenderBox>(
......@@ -1487,7 +1485,7 @@ void main() {
);
}).toList();
},
onChanged: (String newValue) {},
onChanged: (String? newValue) {},
));
final RenderBox dropdownButtonRenderBox = tester.renderObject<RenderBox>(
......@@ -1659,14 +1657,14 @@ void main() {
final DropdownButton<int> button = DropdownButton<int>(
value: 50,
onChanged: (int newValue) { },
onChanged: (int? newValue) { },
items: items,
);
double getMenuScroll() {
double scrollPosition;
final ListView listView = tester.element(find.byType(ListView)).widget as ListView;
final ScrollController scrollController = listView.controller;
final ScrollController scrollController = listView.controller!;
assert(scrollController != null);
scrollPosition = scrollController.position.pixels;
assert(scrollPosition != null);
......@@ -1696,14 +1694,14 @@ void main() {
final DropdownButton<int> button = DropdownButton<int>(
value: 99,
onChanged: (int newValue) { },
onChanged: (int? newValue) { },
items: items,
);
double getMenuScroll() {
double scrollPosition;
final ListView listView = tester.element(find.byType(ListView)).widget as ListView;
final ScrollController scrollController = listView.controller;
final ScrollController scrollController = listView.controller!;
assert(scrollController != null);
scrollPosition = scrollController.position.pixels;
assert(scrollPosition != null);
......@@ -1733,14 +1731,14 @@ void main() {
final DropdownButton<int> button = DropdownButton<int>(
value: 0,
onChanged: (int newValue) { },
onChanged: (int? newValue) { },
items: items,
);
double getMenuScroll() {
double scrollPosition;
final ListView listView = tester.element(find.byType(ListView)).widget as ListView;
final ScrollController scrollController = listView.controller;
final ScrollController scrollController = listView.controller!;
assert(scrollController != null);
scrollPosition = scrollController.position.pixels;
assert(scrollPosition != null);
......@@ -1770,14 +1768,14 @@ void main() {
final DropdownButton<int> button = DropdownButton<int>(
value: 99,
onChanged: (int newValue) { },
onChanged: (int? newValue) { },
items: items,
);
double getMenuScroll() {
double scrollPosition;
final ListView listView = tester.element(find.byType(ListView)).widget as ListView;
final ScrollController scrollController = listView.controller;
final ScrollController scrollController = listView.controller!;
assert(scrollController != null);
scrollPosition = scrollController.position.pixels;
assert(scrollPosition != null);
......@@ -1802,8 +1800,7 @@ void main() {
testWidgets('Dropdown menu respects parent size limits', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/24417
int selectedIndex;
int? selectedIndex;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
......@@ -1821,7 +1818,9 @@ void main() {
padding: const EdgeInsetsDirectional.only(start: 16.0, end: 24.0),
child: DropdownButton<int>(
value: 12,
onChanged: (int i) { selectedIndex = i; },
onChanged: (int? i) {
selectedIndex = i;
},
items: List<DropdownMenuItem<int>>.generate(100, (int i) {
return DropdownMenuItem<int>(value: i, child: Text('$i'));
}),
......@@ -1875,7 +1874,7 @@ void main() {
'Two',
'Three',
];
String selectedItem = items[0];
String? selectedItem = items[0];
await tester.pumpWidget(
StatefulBuilder(
......@@ -1884,7 +1883,9 @@ void main() {
home: Scaffold(
body: DropdownButton<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) {
......@@ -1928,7 +1929,7 @@ void main() {
testWidgets('DropdownButton hint displays properly when selectedItemBuilder is defined', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/42340
final List<String> items = <String>['1', '2', '3'];
String selectedItem;
String? selectedItem;
await tester.pumpWidget(
StatefulBuilder(
......@@ -1938,9 +1939,11 @@ void main() {
body: DropdownButton<String>(
hint: const Text('Please select an item'),
value: selectedItem,
onChanged: (String string) => setState(() {
onChanged: (String? string) {
setState(() {
selectedItem = string;
}),
});
},
selectedItemBuilder: (BuildContext context) {
return items.map<Widget>((String item) {
return Text('You have selected: $item');
......@@ -1971,7 +1974,7 @@ void main() {
testWidgets('Variable size and oversized menu items', (WidgetTester tester) async {
final List<double> itemHeights = <double>[30, 40, 50, 60];
double dropdownValue = itemHeights[0];
double? dropdownValue = itemHeights[0];
Widget buildFrame() {
return MaterialApp(
......@@ -1980,7 +1983,7 @@ void main() {
child: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return DropdownButton<double>(
onChanged: (double value) {
onChanged: (double? value) {
setState(() { dropdownValue = value; });
},
value: dropdownValue,
......@@ -2075,18 +2078,18 @@ void main() {
'two',
'three',
];
String item = items[0];
MediaQueryData mediaQuery;
String? item = items[0];
late MediaQueryData mediaQuery;
await tester.pumpWidget(
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return MaterialApp(
builder: (BuildContext context, Widget child) {
mediaQuery ??= MediaQuery.of(context);
builder: (BuildContext context, Widget? child) {
mediaQuery = MediaQuery.of(context)!;
return MediaQuery(
data: mediaQuery,
child: child,
child: child!,
);
},
home: Scaffold(
......@@ -2096,7 +2099,7 @@ void main() {
value: item,
child: Text(item),
)).toList(),
onChanged: (String newItem) {
onChanged: (String? newItem) {
setState(() {
item = newItem;
mediaQuery = mediaQuery.copyWith(
......@@ -2127,7 +2130,7 @@ void main() {
testWidgets('DropdownButton hint is selected item', (WidgetTester tester) async {
const double hintPaddingOffset = 8;
const List<String> itemValues = <String>['item0', 'item1', 'item2', 'item3'];
String selectedItem = 'item0';
String? selectedItem = 'item0';
Widget buildFrame() {
return MaterialApp(
......@@ -2163,7 +2166,7 @@ void main() {
);
},
),
onChanged: (String value) {
onChanged: (String? value) {
setState(() { selectedItem = value; });
},
icon: Container(),
......@@ -2232,7 +2235,7 @@ void main() {
testWidgets('DropdownButton is activated with the enter/space key', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(debugLabel: 'DropdownButton');
String value = 'one';
String? value = 'one';
Widget buildFrame() {
return MaterialApp(
......@@ -2243,7 +2246,7 @@ void main() {
return DropdownButton<String>(
focusNode: focusNode,
autofocus: true,
onChanged: (String newValue) {
onChanged: (String? newValue) {
setState(() {
value = newValue;
});
......@@ -2288,7 +2291,7 @@ void main() {
testWidgets('Selected element is focused when dropdown is opened', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(debugLabel: 'DropdownButton');
String value = 'one';
String? value = 'one';
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: Center(
......@@ -2297,7 +2300,7 @@ void main() {
return DropdownButton<String>(
focusNode: focusNode,
autofocus: true,
onChanged: (String newValue) {
onChanged: (String? newValue) {
setState(() {
value = newValue;
});
......@@ -2325,7 +2328,7 @@ void main() {
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // finish the menu open animation
expect(value, equals('one'));
expect(Focus.of(tester.element(find.byKey(const ValueKey<String>('one')).last)).hasPrimaryFocus, isTrue);
expect(Focus.of(tester.element(find.byKey(const ValueKey<String>('one')).last))!.hasPrimaryFocus, isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.tab); // Focus 'two'
await tester.pump();
......@@ -2342,13 +2345,13 @@ void main() {
await tester.pump(const Duration(seconds: 1)); // finish the menu open animation
expect(value, equals('two'));
final Element element = tester.element(find.byKey(const ValueKey<String>('two')).last);
final FocusNode node = Focus.of(element);
final FocusNode node = Focus.of(element)!;
expect(node.hasFocus, isTrue);
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/55320
testWidgets('Selected element is correctly focused with dropdown that more items than fit on the screen', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(debugLabel: 'DropdownButton');
int value = 1;
int? value = 1;
final List<int> hugeMenuItems = List<int>.generate(50, (int index) => index);
await tester.pumpWidget(
......@@ -2360,7 +2363,7 @@ void main() {
return DropdownButton<int>(
focusNode: focusNode,
autofocus: true,
onChanged: (int newValue) {
onChanged: (int? newValue) {
setState(() {
value = newValue;
});
......@@ -2389,7 +2392,7 @@ void main() {
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // finish the menu open animation
expect(value, equals(1));
expect(Focus.of(tester.element(find.byKey(const ValueKey<int>(1)).last)).hasPrimaryFocus, isTrue);
expect(Focus.of(tester.element(find.byKey(const ValueKey<int>(1)).last))!.hasPrimaryFocus, isTrue);
for (int i = 0; i < 41; ++i) {
await tester.sendKeyEvent(LogicalKeyboardKey.tab); // Move to the next one.
......@@ -2405,13 +2408,13 @@ void main() {
await tester.pump(const Duration(seconds: 1)); // finish the menu open animation
expect(value, equals(42));
final Element element = tester.element(find.byKey(const ValueKey<int>(42)).last);
final FocusNode node = Focus.of(element);
final FocusNode node = Focus.of(element)!;
expect(node.hasFocus, isTrue);
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/55320
testWidgets("Having a focused element doesn't interrupt scroll when flung by touch", (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(debugLabel: 'DropdownButton');
int value = 1;
int? value = 1;
final List<int> hugeMenuItems = List<int>.generate(100, (int index) => index);
await tester.pumpWidget(
......@@ -2423,7 +2426,7 @@ void main() {
return DropdownButton<int>(
focusNode: focusNode,
autofocus: true,
onChanged: (int newValue) {
onChanged: (int? newValue) {
setState(() {
value = newValue;
});
......@@ -2451,14 +2454,14 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(value, equals(1));
expect(Focus.of(tester.element(find.byKey(const ValueKey<int>(1)).last)).hasPrimaryFocus, isTrue);
expect(Focus.of(tester.element(find.byKey(const ValueKey<int>(1)).last))!.hasPrimaryFocus, isTrue);
// Move to an item very far down the menu.
for (int i = 0; i < 90; ++i) {
await tester.sendKeyEvent(LogicalKeyboardKey.tab); // Move to the next one.
await tester.pumpAndSettle(); // Wait for it to animate the menu.
}
expect(Focus.of(tester.element(find.byKey(const ValueKey<int>(91)).last)).hasPrimaryFocus, isTrue);
expect(Focus.of(tester.element(find.byKey(const ValueKey<int>(91)).last))!.hasPrimaryFocus, isTrue);
// Scroll back to the top using touch, and make sure we end up there.
final Finder menu = find.byWidgetPredicate((Widget widget) {
......@@ -2480,14 +2483,14 @@ void main() {
// Scrolling to the top again has removed the one the focus was on from the
// tree, causing it to lose focus.
expect(Focus.of(tester.element(find.byKey(const ValueKey<int>(91)).last)).hasPrimaryFocus, isFalse);
expect(Focus.of(tester.element(find.byKey(const ValueKey<int>(91)).last))!.hasPrimaryFocus, isFalse);
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/55320
testWidgets('DropdownButton onTap callback is called when defined', (WidgetTester tester) async {
int dropdownButtonTapCounter = 0;
String value = 'one';
String? value = 'one';
void onChanged(String newValue) { value = newValue; }
void onChanged(String? newValue) { value = newValue; }
void onTap() { dropdownButtonTapCounter += 1; }
Widget build() => buildFrame(
......@@ -2529,9 +2532,9 @@ void main() {
});
testWidgets('DropdownMenuItem onTap callback is called when defined', (WidgetTester tester) async {
String value = 'one';
String? value = 'one';
final List<int> menuItemTapCounters = <int>[0, 0, 0, 0];
void onChanged(String newValue) { value = newValue; }
void onChanged(String? newValue) { value = newValue; }
final List<VoidCallback> onTapCallbacks = <VoidCallback>[
() { menuItemTapCounters[0] += 1; },
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -44,10 +42,10 @@ void main() {
expect(material.elevation, 2);
expect(material.shadowColor, const Color(0xff000000));
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)));
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);
expect(material.type, MaterialType.button);
final Offset center = tester.getCenter(find.byType(ElevatedButton));
......@@ -67,10 +65,10 @@ void main() {
expect(material.elevation, 8);
expect(material.shadowColor, const Color(0xff000000));
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)));
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);
expect(material.type, MaterialType.button);
await gesture.up();
......@@ -101,10 +99,10 @@ void main() {
expect(material.elevation, 0.0);
expect(material.shadowColor, const Color(0xff000000));
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)));
expect(material.textStyle.color, colorScheme.onSurface.withOpacity(0.38));
expect(material.textStyle.fontFamily, 'Roboto');
expect(material.textStyle.fontSize, 14);
expect(material.textStyle.fontWeight, FontWeight.w500);
expect(material.textStyle!.color, colorScheme.onSurface.withOpacity(0.38));
expect(material.textStyle!.fontFamily, 'Roboto');
expect(material.textStyle!.fontSize, 14);
expect(material.textStyle!.fontWeight, FontWeight.w500);
expect(material.type, MaterialType.button);
});
......@@ -197,7 +195,7 @@ void main() {
);
Color textColor() {
return tester.renderObject<RenderParagraph>(find.text('ElevatedButton')).text.style.color;
return tester.renderObject<RenderParagraph>(find.text('ElevatedButton')).text.style!.color!;
}
// Default, not disabled.
......@@ -276,7 +274,7 @@ void main() {
),
);
Color iconColor() => _iconStyle(tester, Icons.add).color;
Color iconColor() => _iconStyle(tester, Icons.add).color!;
// Default, not disabled.
expect(iconColor(), equals(defaultColor));
......@@ -307,7 +305,7 @@ void main() {
bool wasPressed;
Finder elevatedButton;
Widget buildFrame({ VoidCallback onPressed, VoidCallback onLongPress }) {
Widget buildFrame({ VoidCallback? onPressed, VoidCallback? onLongPress }) {
return Directionality(
textDirection: TextDirection.ltr,
child: ElevatedButton(
......@@ -385,7 +383,7 @@ void main() {
textDirection: TextDirection.ltr,
child: ElevatedButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
overlayColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
return states.contains(MaterialState.hovered) ? hoverColor : null;
}),
),
......@@ -415,7 +413,7 @@ void main() {
textDirection: TextDirection.ltr,
child: ElevatedButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
overlayColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
return states.contains(MaterialState.focused) ? focusColor : null;
}),
),
......@@ -437,7 +435,7 @@ void main() {
testWidgets('Does ElevatedButton work with autofocus', (WidgetTester tester) async {
const Color focusColor = Color(0xff001122);
Color getOverlayColor(Set<MaterialState> states) {
Color? getOverlayColor(Set<MaterialState> states) {
return states.contains(MaterialState.focused) ? focusColor : null;
}
......@@ -448,7 +446,7 @@ void main() {
child: ElevatedButton(
autofocus: true,
style: ButtonStyle(
overlayColor: MaterialStateProperty.resolveWith<Color>(getOverlayColor),
overlayColor: MaterialStateProperty.resolveWith<Color?>(getOverlayColor),
),
focusNode: focusNode,
onPressed: () { },
......@@ -683,7 +681,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<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.
final Map<double, double> paddingWithoutIconStart = <double, double>{
......@@ -743,7 +741,7 @@ void main() {
}
/// Computes the padding between two [Rect]s, one inside the other.
EdgeInsets paddingBetween({ Rect parent, Rect child }) {
EdgeInsets paddingBetween({ required Rect parent, required Rect child }) {
assert (parent.intersect(child) == child);
return EdgeInsets.fromLTRB(
child.left - parent.left,
......@@ -755,7 +753,7 @@ void main() {
for (final double textScaleFactor in textScaleFactorOptions) {
for (final TextDirection textDirection in textDirectionOptions) {
for (final Widget icon in iconOptions) {
for (final Widget? icon in iconOptions) {
final String testName = 'ElevatedButton'
', text scale $textScaleFactor'
'${icon != null ? ", with icon" : ""}'
......@@ -768,7 +766,7 @@ void main() {
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
data: MediaQuery.of(context)!.copyWith(
textScaleFactor: textScaleFactor,
),
child: Directionality(
......@@ -808,11 +806,11 @@ void main() {
// Compute expected padding, and check.
final double expectedStart = icon != null
? paddingWithIconStart[textScaleFactor]
: paddingWithoutIconStart[textScaleFactor];
? paddingWithIconStart[textScaleFactor]!
: paddingWithoutIconStart[textScaleFactor]!;
final double expectedEnd = icon != null
? paddingWithIconEnd[textScaleFactor]
: paddingWithoutIconEnd[textScaleFactor];
? paddingWithIconEnd[textScaleFactor]!
: paddingWithoutIconEnd[textScaleFactor]!;
final EdgeInsets expectedPadding = EdgeInsetsDirectional.fromSTEB(expectedStart, 0, expectedEnd, 0)
.resolve(textDirection);
......@@ -823,9 +821,9 @@ void main() {
final RenderBox labelRenderBox = tester.renderObject<RenderBox>(find.byKey(labelKey));
final Rect labelBounds = globalBounds(labelRenderBox);
final RenderBox iconRenderBox = icon == null ? null : tester.renderObject<RenderBox>(find.byKey(iconKey));
final Rect iconBounds = icon == null ? null : globalBounds(iconRenderBox);
final Rect childBounds = icon == null ? labelBounds : labelBounds.expandToInclude(iconBounds);
final RenderBox? iconRenderBox = icon == null ? null : tester.renderObject<RenderBox>(find.byKey(iconKey));
final Rect? iconBounds = icon == null ? null : globalBounds(iconRenderBox!);
final Rect childBounds = icon == null ? labelBounds : labelBounds.expandToInclude(iconBounds!);
// We measure the `InkResponse` descendant of the button
// element, because the button has a larger `RenderBox`
......@@ -874,8 +872,8 @@ void main() {
// Check the gap between the icon and the label
if (icon != null) {
final double gapWidth = textDirection == TextDirection.ltr
? labelBounds.left - iconBounds.right
: iconBounds.left - labelBounds.right;
? labelBounds.left - iconBounds!.right
: iconBounds!.left - labelBounds.right;
expect(gapWidth, paddingWithIconGap[textScaleFactor]);
}
......@@ -904,7 +902,7 @@ void main() {
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
data: MediaQuery.of(context)!.copyWith(
textScaleFactor: 2,
),
child: Scaffold(
......@@ -938,7 +936,7 @@ void main() {
final Color backgroundColor = colorScheme.primary;
final Color disabledBackgroundColor = colorScheme.onSurface.withOpacity(0.12);
Widget buildFrame({ bool enabled }) {
Widget buildFrame({ required bool enabled }) {
return MaterialApp(
theme: ThemeData.from(colorScheme: colorScheme),
home: Center(
......@@ -983,5 +981,5 @@ TextStyle _iconStyle(WidgetTester tester, IconData icon) {
final RichText iconRichText = tester.widget<RichText>(
find.descendant(of: find.byIcon(icon), matching: find.byType(RichText)),
);
return iconRichText.text.style;
return iconRichText.text.style!;
}
......@@ -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