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

[NNBD] Migrate some Cupertino tests (#67086)

parent 2cdf2f00
......@@ -344,7 +344,7 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer
///
/// If a border is null, the navigation bar will not display a border.
/// {@endtemplate}
final Border border;
final Border? border;
/// {@template flutter.cupertino.navBar.actionsForegroundColor}
/// Default color used for text and icons of the [leading] and [trailing]
......@@ -652,7 +652,7 @@ class CupertinoSliverNavigationBar extends StatefulWidget {
final EdgeInsetsDirectional? padding;
/// {@macro flutter.cupertino.navBar.border}
final Border border;
final Border? border;
/// {@macro flutter.cupertino.navBar.actionsForegroundColor}
///
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart';
import 'package:flutter/widgets.dart';
......@@ -63,7 +61,7 @@ void main() {
final DefaultTextStyle widget = tester.widget(find.widgetWithText(DefaultTextStyle, 'Ok'));
expect(widget.style.color, const CupertinoDynamicColor.withBrightnessAndContrast(
expect(widget.style!.color, const CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 255, 59, 48),
darkColor: Color.fromARGB(255, 255, 69, 58),
highContrastColor: Color.fromARGB(255, 215, 0, 21),
......@@ -78,7 +76,7 @@ void main() {
);
Brightness brightness = Brightness.light;
StateSetter stateSetter;
late StateSetter stateSetter;
TextStyle actionTextStyle(String text) {
return tester.widget<DefaultTextStyle>(
......@@ -86,7 +84,7 @@ void main() {
of: find.widgetWithText(CupertinoActionSheetAction, text),
matching: find.byType(DefaultTextStyle),
),
).style;
).style!;
}
await tester.pumpWidget(
......@@ -115,7 +113,7 @@ void main() {
await tester.pump();
expect(
actionTextStyle('action').color.value,
actionTextStyle('action').color!.value,
const Color.fromARGB(255, 0, 122, 255).value,
);
......@@ -123,7 +121,7 @@ void main() {
await tester.pump();
expect(
actionTextStyle('action').color.value,
actionTextStyle('action').color!.value,
const Color.fromARGB(255, 10, 132, 255).value,
);
});
......@@ -141,7 +139,7 @@ void main() {
final DefaultTextStyle widget = tester.widget(find.widgetWithText(DefaultTextStyle, 'Ok'));
expect(widget.style.fontWeight, equals(FontWeight.w600));
expect(widget.style!.fontWeight, equals(FontWeight.w600));
});
testWidgets('Action sheet text styles are correct when both title and message are included', (WidgetTester tester) async {
......@@ -162,8 +160,8 @@ void main() {
final DefaultTextStyle messageStyle = tester.firstWidget(find.widgetWithText(DefaultTextStyle,
'An action sheet'));
expect(titleStyle.style.fontWeight, FontWeight.w600);
expect(messageStyle.style.fontWeight, FontWeight.w400);
expect(titleStyle.style!.fontWeight, FontWeight.w600);
expect(messageStyle.style!.fontWeight, FontWeight.w400);
});
testWidgets('Action sheet text styles are correct when title but no message is included', (WidgetTester tester) async {
......@@ -181,7 +179,7 @@ void main() {
final DefaultTextStyle titleStyle = tester.firstWidget(find.widgetWithText(DefaultTextStyle,
'Action Sheet'));
expect(titleStyle.style.fontWeight, FontWeight.w400);
expect(titleStyle.style!.fontWeight, FontWeight.w400);
});
testWidgets('Action sheet text styles are correct when message but no title is included', (WidgetTester tester) async {
......@@ -199,7 +197,7 @@ void main() {
final DefaultTextStyle messageStyle = tester.firstWidget(find.widgetWithText(DefaultTextStyle,
'An action sheet'));
expect(messageStyle.style.fontWeight, FontWeight.w600);
expect(messageStyle.style!.fontWeight, FontWeight.w600);
});
testWidgets('Content section but no actions', (WidgetTester tester) async {
......@@ -285,7 +283,7 @@ void main() {
createAppWithButtonThatLaunchesActionSheet(
Builder(builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
child: CupertinoActionSheet(
title: const Text('The title'),
message: const Text('The message.'),
......@@ -346,13 +344,13 @@ void main() {
testWidgets('Content section is scrollable', (WidgetTester tester) async {
final ScrollController messageScrollController = ScrollController();
double screenHeight;
late double screenHeight;
await tester.pumpWidget(
createAppWithButtonThatLaunchesActionSheet(
Builder(builder: (BuildContext context) {
screenHeight = MediaQuery.of(context).size.height;
screenHeight = MediaQuery.of(context)!.size.height;
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
child: CupertinoActionSheet(
title: const Text('The title'),
message: Text('Very long content' * 200),
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -14,18 +12,18 @@ void main() {
testWidgets('Activity indicator animate property works',
(WidgetTester tester) async {
await tester.pumpWidget(buildCupertinoActivityIndicator());
expect(SchedulerBinding.instance.transientCallbackCount, equals(1));
expect(SchedulerBinding.instance!.transientCallbackCount, equals(1));
await tester.pumpWidget(buildCupertinoActivityIndicator(false));
expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
expect(SchedulerBinding.instance!.transientCallbackCount, equals(0));
await tester.pumpWidget(Container());
await tester.pumpWidget(buildCupertinoActivityIndicator(false));
expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
expect(SchedulerBinding.instance!.transientCallbackCount, equals(0));
await tester.pumpWidget(buildCupertinoActivityIndicator());
expect(SchedulerBinding.instance.transientCallbackCount, equals(1));
expect(SchedulerBinding.instance!.transientCallbackCount, equals(1));
});
testWidgets('Activity indicator dark mode', (WidgetTester tester) async {
......@@ -161,7 +159,7 @@ void main() {
});
}
Widget buildCupertinoActivityIndicator([bool animating]) {
Widget buildCupertinoActivityIndicator([bool? animating]) {
return MediaQuery(
data: const MediaQueryData(platformBrightness: Brightness.light),
child: CupertinoActivityIndicator(
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
......@@ -52,8 +50,8 @@ void main() {
builder: (BuildContext context) {
return Column(
children: <Widget>[
Text(CupertinoLocalizations.of(context).selectAllButtonLabel),
Text(CupertinoLocalizations.of(context).datePickerMediumDate(
Text(CupertinoLocalizations.of(context)!.selectAllButtonLabel),
Text(CupertinoLocalizations.of(context)!.datePickerMediumDate(
DateTime(2018, 10, 4),
)),
],
......@@ -126,7 +124,7 @@ void main() {
expect(find.text('non-regular page one'), findsNothing);
expect(find.text('regular page one'), findsNothing);
expect(find.text('regular page two'), findsNothing);
navigatorKey.currentState.pop();
navigatorKey.currentState!.pop();
await tester.pumpAndSettle();
expect(find.text('non-regular page two'), findsNothing);
expect(find.text('non-regular page one'), findsOneWidget);
......@@ -158,7 +156,7 @@ void main() {
);
final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate(
builder: (BuildContext context, RouteInformation information) {
return Text(information.location);
return Text(information.location!);
},
onPopPage: (Route<void> route, void result, SimpleNavigatorRouterDelegate delegate) {
delegate.routeInformation = const RouteInformation(
......@@ -176,7 +174,7 @@ void main() {
// Simulate android back button intent.
final ByteData message = const JSONMethodCodec().encodeMethodCall(const MethodCall('popRoute'));
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
await tester.pumpAndSettle();
expect(find.text('popped'), findsOneWidget);
});
......@@ -201,7 +199,7 @@ class SimpleRouteInformationParser extends RouteInformationParser<RouteInformati
class SimpleNavigatorRouterDelegate extends RouterDelegate<RouteInformation> with PopNavigatorRouterDelegateMixin<RouteInformation>, ChangeNotifier {
SimpleNavigatorRouterDelegate({
@required this.builder,
required this.builder,
this.onPopPage,
});
......@@ -209,14 +207,14 @@ class SimpleNavigatorRouterDelegate extends RouterDelegate<RouteInformation> wit
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
RouteInformation get routeInformation => _routeInformation;
RouteInformation _routeInformation;
late RouteInformation _routeInformation;
set routeInformation(RouteInformation newValue) {
_routeInformation = newValue;
notifyListeners();
}
SimpleRouterDelegateBuilder builder;
SimpleNavigatorRouterDelegatePopPage<void> onPopPage;
SimpleNavigatorRouterDelegatePopPage<void>? onPopPage;
@override
Future<void> setNewRoutePath(RouteInformation configuration) {
......@@ -225,7 +223,7 @@ class SimpleNavigatorRouterDelegate extends RouterDelegate<RouteInformation> wit
}
bool _handlePopPage(Route<void> route, void data) {
return onPopPage(route, data, this);
return onPopPage!(route, data, this);
}
@override
......@@ -240,7 +238,7 @@ class SimpleNavigatorRouterDelegate extends RouterDelegate<RouteInformation> wit
child: Text('base'),
),
CupertinoPage<void>(
key: ValueKey<String>(routeInformation?.location),
key: ValueKey<String?>(routeInformation.location),
child: builder(context, routeInformation),
)
],
......
......@@ -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:typed_data';
import 'package:flutter/cupertino.dart';
......@@ -72,13 +70,13 @@ Future<void> main() async {
of: find.text('Tab 1'),
matching: find.byType(RichText),
));
expect(actualInactive.text.style.color, const Color(0xFF654321));
expect(actualInactive.text.style!.color, const Color(0xFF654321));
final RichText actualActive = tester.widget(find.descendant(
of: find.text('Tab 2'),
matching: find.byType(RichText),
));
expect(actualActive.text.style.color, const Color(0xFF123456));
expect(actualActive.text.style!.color, const Color(0xFF123456));
});
......@@ -138,13 +136,13 @@ Future<void> main() async {
of: find.text('Tab 1'),
matching: find.byType(RichText),
));
expect(actualInactive.text.style.color.value, 0xFF000002);
expect(actualInactive.text.style!.color!.value, 0xFF000002);
RichText actualActive = tester.widget(find.descendant(
of: find.text('Tab 2'),
matching: find.byType(RichText),
));
expect(actualActive.text.style.color.value, 0xFF000000);
expect(actualActive.text.style!.color!.value, 0xFF000000);
final RenderDecoratedBox renderDecoratedBox = tester.renderObject(find.descendant(
of: find.byType(BackdropFilter),
......@@ -153,7 +151,7 @@ Future<void> main() async {
// Border color is resolved correctly.
final BoxDecoration decoration1 = renderDecoratedBox.decoration as BoxDecoration;
expect(decoration1.border.top.color.value, 0x4C000000);
expect(decoration1.border!.top.color.value, 0x4C000000);
// Switch to dark mode.
await pumpWidgetWithBoilerplate(tester, MediaQuery(
......@@ -179,17 +177,17 @@ Future<void> main() async {
of: find.text('Tab 1'),
matching: find.byType(RichText),
));
expect(actualInactive.text.style.color.value, 0xFF000003);
expect(actualInactive.text.style!.color!.value, 0xFF000003);
actualActive = tester.widget(find.descendant(
of: find.text('Tab 2'),
matching: find.byType(RichText),
));
expect(actualActive.text.style.color.value, 0xFF000001);
expect(actualActive.text.style!.color!.value, 0xFF000001);
// Border color is resolved correctly.
final BoxDecoration decoration2 = renderDecoratedBox.decoration as BoxDecoration;
expect(decoration2.border.top.color.value, 0x29000000);
expect(decoration2.border!.top.color.value, 0x29000000);
});
testWidgets('Tabs respects themes', (WidgetTester tester) async {
......@@ -215,13 +213,13 @@ Future<void> main() async {
of: find.text('Tab 1'),
matching: find.byType(RichText),
));
expect(actualInactive.text.style.color.value, 0xFF999999);
expect(actualInactive.text.style!.color!.value, 0xFF999999);
RichText actualActive = tester.widget(find.descendant(
of: find.text('Tab 2'),
matching: find.byType(RichText),
));
expect(actualActive.text.style.color, CupertinoColors.activeBlue);
expect(actualActive.text.style!.color, CupertinoColors.activeBlue);
await tester.pumpWidget(
CupertinoApp(
......@@ -246,14 +244,14 @@ Future<void> main() async {
of: find.text('Tab 1'),
matching: find.byType(RichText),
));
expect(actualInactive.text.style.color.value, 0xFF757575);
expect(actualInactive.text.style!.color!.value, 0xFF757575);
actualActive = tester.widget(find.descendant(
of: find.text('Tab 2'),
matching: find.byType(RichText),
));
expect(actualActive.text.style.color, isSameColorAs(CupertinoColors.activeBlue.darkColor));
expect(actualActive.text.style!.color, isSameColorAs(CupertinoColors.activeBlue.darkColor));
});
testWidgets('Use active icon', (WidgetTester tester) async {
......@@ -368,7 +366,7 @@ Future<void> main() async {
});
testWidgets('Tap callback', (WidgetTester tester) async {
int callbackTab;
late int callbackTab;
await pumpWidgetWithBoilerplate(tester, MediaQuery(
data: const MediaQueryData(),
......
......@@ -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/rendering.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/scheduler.dart';
......@@ -151,11 +149,11 @@ void main() {
expect(value, isFalse);
// No animating by default.
expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
expect(SchedulerBinding.instance!.transientCallbackCount, equals(0));
await tester.tap(find.byType(CupertinoButton));
expect(value, isTrue);
// Animates.
expect(SchedulerBinding.instance.transientCallbackCount, equals(1));
expect(SchedulerBinding.instance!.transientCallbackCount, equals(1));
});
testWidgets("Disabled button doesn't animate", (WidgetTester tester) async {
......@@ -163,10 +161,10 @@ void main() {
child: Text('Tap me'),
onPressed: null,
)));
expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
expect(SchedulerBinding.instance!.transientCallbackCount, equals(0));
await tester.tap(find.byType(CupertinoButton));
// Still doesn't animate.
expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
expect(SchedulerBinding.instance!.transientCallbackCount, equals(0));
});
testWidgets('pressedOpacity defaults to 0.1', (WidgetTester tester) async {
......@@ -295,7 +293,7 @@ void main() {
find.widgetWithText(DecoratedBox, 'Skeuomorph me')
).decoration as BoxDecoration;
expect(boxDecoration.color.value, 0xFF654321);
expect(boxDecoration.color!.value, 0xFF654321);
await tester.pumpWidget(
MediaQuery(
......@@ -314,18 +312,18 @@ void main() {
).decoration as BoxDecoration;
// Disabled color.
expect(boxDecoration.color.value, 0xFF111111);
expect(boxDecoration.color!.value, 0xFF111111);
});
testWidgets('Button respects themes', (WidgetTester tester) async {
TextStyle textStyle;
late TextStyle textStyle;
await tester.pumpWidget(
CupertinoApp(
home: CupertinoButton(
onPressed: () { },
child: Builder(builder: (BuildContext context) {
textStyle = DefaultTextStyle.of(context).style;
textStyle = DefaultTextStyle.of(context).style!;
return const Placeholder();
}),
),
......@@ -339,7 +337,7 @@ void main() {
home: CupertinoButton.filled(
onPressed: () { },
child: Builder(builder: (BuildContext context) {
textStyle = DefaultTextStyle.of(context).style;
textStyle = DefaultTextStyle.of(context).style!;
return const Placeholder();
}),
),
......@@ -361,7 +359,7 @@ void main() {
home: CupertinoButton(
onPressed: () { },
child: Builder(builder: (BuildContext context) {
textStyle = DefaultTextStyle.of(context).style;
textStyle = DefaultTextStyle.of(context).style!;
return const Placeholder();
}),
),
......@@ -375,7 +373,7 @@ void main() {
home: CupertinoButton.filled(
onPressed: () { },
child: Builder(builder: (BuildContext context) {
textStyle = DefaultTextStyle.of(context).style;
textStyle = DefaultTextStyle.of(context).style!;
return const Placeholder();
}),
),
......@@ -392,7 +390,7 @@ void main() {
});
}
Widget boilerplate({ Widget child }) {
Widget boilerplate({ required Widget child }) {
return Directionality(
textDirection: TextDirection.ltr,
child: Center(child: child),
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -13,15 +11,15 @@ import '../rendering/mock_canvas.dart';
class DependentWidget extends StatelessWidget {
const DependentWidget({
Key key,
this.color,
Key? key,
required this.color,
}) : super(key: key);
final Color color;
@override
Widget build(BuildContext context) {
final Color resolved = CupertinoDynamicColor.resolve(color, context, nullOk: false);
final Color resolved = CupertinoDynamicColor.resolve(color, context, nullOk: false)!;
return DecoratedBox(
decoration: BoxDecoration(color: resolved),
child: const SizedBox.expand(),
......@@ -422,7 +420,7 @@ void main() {
});
testWidgets('CupertinoDynamicColor used in a CupertinoTheme', (WidgetTester tester) async {
CupertinoDynamicColor color;
late CupertinoDynamicColor color;
await tester.pumpWidget(
CupertinoApp(
theme: const CupertinoThemeData(
......@@ -503,7 +501,7 @@ void main() {
});
group('MaterialApp:', () {
Color color;
Color? color;
setUp(() { color = null; });
testWidgets('dynamic color works in cupertino override theme', (WidgetTester tester) async {
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/cupertino.dart';
......@@ -15,7 +13,7 @@ void main() {
const Color _kDestructiveActionColor = CupertinoColors.destructiveRed;
const FontWeight _kDefaultActionWeight = FontWeight.w600;
Widget _getApp({VoidCallback onPressed, bool isDestructiveAction = false, bool isDefaultAction = false}) {
Widget _getApp({VoidCallback? onPressed, bool isDestructiveAction = false, bool isDefaultAction = false}) {
final UniqueKey actionKey = UniqueKey();
final CupertinoContextMenuAction action = CupertinoContextMenuAction(
key: actionKey,
......@@ -52,7 +50,7 @@ void main() {
);
expect(finder, findsOneWidget);
final DefaultTextStyle defaultStyle = tester.widget(finder);
return defaultStyle.style;
return defaultStyle.style!;
}
Icon _getIcon(WidgetTester tester) {
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
......@@ -24,7 +22,7 @@ void main() {
Widget _getContextMenu({
Alignment alignment = Alignment.center,
Size screenSize = const Size(800.0, 600.0),
Widget child,
Widget? child,
}) {
return CupertinoApp(
home: CupertinoPageScaffold(
......
......@@ -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/cupertino.dart';
......@@ -16,15 +14,6 @@ const Offset _kRowOffset = Offset(0.0, -50.0);
void main() {
group('Countdown timer picker', () {
testWidgets('onTimerDurationChanged is not null', (WidgetTester tester) async {
expect(
() {
CupertinoTimerPicker(onTimerDurationChanged: null);
},
throwsAssertionError,
);
});
testWidgets('initialTimerDuration falls within limit', (WidgetTester tester) async {
expect(
() {
......@@ -245,7 +234,7 @@ void main() {
});
testWidgets('picker honors minuteInterval and secondInterval', (WidgetTester tester) async {
Duration duration;
late Duration duration;
await tester.pumpWidget(
CupertinoApp(
home: SizedBox(
......@@ -277,31 +266,6 @@ void main() {
});
group('Date picker', () {
testWidgets('mode is not null', (WidgetTester tester) async {
expect(
() {
CupertinoDatePicker(
mode: null,
onDateTimeChanged: (_) { },
initialDateTime: DateTime.now(),
);
},
throwsAssertionError,
);
});
testWidgets('onDateTimeChanged is not null', (WidgetTester tester) async {
expect(
() {
CupertinoDatePicker(
onDateTimeChanged: null,
initialDateTime: DateTime.now(),
);
},
throwsAssertionError,
);
});
testWidgets('initial date is set to default value', (WidgetTester tester) async {
final CupertinoDatePicker picker = CupertinoDatePicker(
onDateTimeChanged: (_) { },
......@@ -350,7 +314,7 @@ void main() {
});
testWidgets('initial date honors minuteInterval', (WidgetTester tester) async {
DateTime newDateTime;
late DateTime newDateTime;
await tester.pumpWidget(
CupertinoApp(
home: Center(
......@@ -399,7 +363,7 @@ void main() {
});
testWidgets('changing initialDateTime after first build does not do anything', (WidgetTester tester) async {
DateTime selectedDateTime;
late DateTime selectedDateTime;
await tester.pumpWidget(
CupertinoApp(
home: Center(
......@@ -622,7 +586,7 @@ void main() {
});
testWidgets('picker automatically scrolls away from invalid date on month change', (WidgetTester tester) async {
DateTime date;
late DateTime date;
await tester.pumpWidget(
CupertinoApp(
home: Center(
......@@ -666,7 +630,7 @@ void main() {
'date picker automatically scrolls away from invalid date, '
"and onDateTimeChanged doesn't report these dates",
(WidgetTester tester) async {
DateTime date;
late DateTime date;
// 2016 is a leap year.
final DateTime minimum = DateTime(2016, 2, 29);
final DateTime maximum = DateTime(2018, 12, 31);
......@@ -695,7 +659,7 @@ void main() {
// 2017 has 28 days in Feb so 29 is greyed out.
expect(
tester.widget<Text>(find.text('29')).style.color,
tester.widget<Text>(find.text('29')).style!.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
......@@ -710,7 +674,7 @@ void main() {
// 2016 has 29 days in Feb so 29 is not greyed out.
expect(
tester.widget<Text>(find.text('29')).style.color,
tester.widget<Text>(find.text('29')).style!.color,
isNot(isSameColorAs(CupertinoColors.inactiveGray.color)),
);
......@@ -724,7 +688,7 @@ void main() {
);
expect(
tester.widget<Text>(find.text('29')).style.color,
tester.widget<Text>(find.text('29')).style!.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
});
......@@ -733,7 +697,7 @@ void main() {
'dateTime picker automatically scrolls away from invalid date, '
"and onDateTimeChanged doesn't report these dates",
(WidgetTester tester) async {
DateTime date;
late DateTime date;
final DateTime minimum = DateTime(2019, 11, 11, 3, 30);
final DateTime maximum = DateTime(2019, 11, 11, 14, 59, 59);
await tester.pumpWidget(
......@@ -761,18 +725,18 @@ void main() {
// 3:00 is valid but 2:00 should be invalid.
expect(
tester.widget<Text>(find.text('3')).style.color,
tester.widget<Text>(find.text('3')).style!.color,
isNot(isSameColorAs(CupertinoColors.inactiveGray.color)),
);
expect(
tester.widget<Text>(find.text('2')).style.color,
tester.widget<Text>(find.text('2')).style!.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
// 'PM' is greyed out.
expect(
tester.widget<Text>(find.text('PM')).style.color,
tester.widget<Text>(find.text('PM')).style!.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
......@@ -787,11 +751,11 @@ void main() {
// 3'o clock and 'AM' are now greyed out.
expect(
tester.widget<Text>(find.text('AM')).style.color,
tester.widget<Text>(find.text('AM')).style!.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
expect(
tester.widget<Text>(find.text('3')).style.color,
tester.widget<Text>(find.text('3')).style!.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
......@@ -810,7 +774,7 @@ void main() {
'time picker automatically scrolls away from invalid date, '
"and onDateTimeChanged doesn't report these dates",
(WidgetTester tester) async {
DateTime date;
late DateTime date;
final DateTime minimum = DateTime(2019, 11, 11, 3, 30);
final DateTime maximum = DateTime(2019, 11, 11, 14, 59, 59);
await tester.pumpWidget(
......@@ -838,18 +802,18 @@ void main() {
// 3:00 is valid but 2:00 should be invalid.
expect(
tester.widget<Text>(find.text('3')).style.color,
tester.widget<Text>(find.text('3')).style!.color,
isNot(isSameColorAs(CupertinoColors.inactiveGray.color)),
);
expect(
tester.widget<Text>(find.text('2')).style.color,
tester.widget<Text>(find.text('2')).style!.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
// 'PM' is greyed out.
expect(
tester.widget<Text>(find.text('PM')).style.color,
tester.widget<Text>(find.text('PM')).style!.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
......@@ -864,11 +828,11 @@ void main() {
// 3'o clock and 'AM' are now greyed out.
expect(
tester.widget<Text>(find.text('AM')).style.color,
tester.widget<Text>(find.text('AM')).style!.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
expect(
tester.widget<Text>(find.text('3')).style.color,
tester.widget<Text>(find.text('3')).style!.color,
isSameColorAs(CupertinoColors.inactiveGray.color),
);
......@@ -884,7 +848,7 @@ void main() {
});
testWidgets('picker automatically scrolls away from invalid date on day change', (WidgetTester tester) async {
DateTime date;
late DateTime date;
await tester.pumpWidget(
CupertinoApp(
home: Center(
......@@ -941,7 +905,7 @@ void main() {
'date picker should only take into account the date part of minimumDate and maximumDate',
(WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/49606.
DateTime date;
late DateTime date;
final DateTime minDate = DateTime(2020, 1, 1, 12);
await tester.pumpWidget(
CupertinoApp(
......@@ -972,7 +936,7 @@ void main() {
group('Picker handles initial noon/midnight times', () {
testWidgets('midnight', (WidgetTester tester) async {
DateTime date;
late DateTime date;
await tester.pumpWidget(
CupertinoApp(
home: Center(
......@@ -1000,7 +964,7 @@ void main() {
});
testWidgets('noon', (WidgetTester tester) async {
DateTime date;
late DateTime date;
await tester.pumpWidget(
CupertinoApp(
home: Center(
......@@ -1028,7 +992,7 @@ void main() {
});
testWidgets('noon in 24 hour time', (WidgetTester tester) async {
DateTime date;
late DateTime date;
await tester.pumpWidget(
CupertinoApp(
home: Center(
......@@ -1058,7 +1022,7 @@ void main() {
});
testWidgets('picker persists am/pm value when scrolling hours', (WidgetTester tester) async {
DateTime date;
late DateTime date;
await tester.pumpWidget(
CupertinoApp(
home: Center(
......@@ -1107,7 +1071,7 @@ void main() {
});
testWidgets('picker automatically scrolls the am/pm column when the hour column changes enough', (WidgetTester tester) async {
DateTime date;
late DateTime date;
await tester.pumpWidget(
CupertinoApp(
home: Center(
......@@ -1285,7 +1249,7 @@ void main() {
});
testWidgets('TimerPicker only changes hour label after scrolling stops', (WidgetTester tester) async {
Duration duration;
Duration? duration;
await tester.pumpWidget(
CupertinoApp(
home: Center(
......@@ -1308,13 +1272,13 @@ void main() {
await tester.drag(find.text('2'), Offset(0, -_kRowOffset.dy));
// Duration should change but not the label.
expect(duration?.inHours, 1);
expect(duration!.inHours, 1);
expect(find.text('hour'), findsNothing);
expect(find.text('hours'), findsOneWidget);
await tester.pumpAndSettle();
// Now the label should change.
expect(duration?.inHours, 1);
expect(duration!.inHours, 1);
expect(find.text('hours'), findsNothing);
expect(find.text('hour'), findsOneWidget);
});
......@@ -1368,7 +1332,7 @@ void main() {
testWidgets('scrollController can be removed or added', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
int lastSelectedItem;
late int lastSelectedItem;
void onSelectedItemChanged(int index) {
lastSelectedItem = index;
}
......@@ -1377,7 +1341,7 @@ void main() {
onSelectedItemChanged: onSelectedItemChanged,
));
tester.binding.pipelineOwner.semanticsOwner.performAction(1, SemanticsAction.increase);
tester.binding.pipelineOwner.semanticsOwner!.performAction(1, SemanticsAction.increase);
await tester.pumpAndSettle();
expect(lastSelectedItem, 1);
......@@ -1385,7 +1349,7 @@ void main() {
onSelectedItemChanged: onSelectedItemChanged,
));
tester.binding.pipelineOwner.semanticsOwner.performAction(1, SemanticsAction.increase);
tester.binding.pipelineOwner.semanticsOwner!.performAction(1, SemanticsAction.increase);
await tester.pumpAndSettle();
expect(lastSelectedItem, 2);
......@@ -1394,7 +1358,7 @@ void main() {
onSelectedItemChanged: onSelectedItemChanged,
));
tester.binding.pipelineOwner.semanticsOwner.performAction(1, SemanticsAction.increase);
tester.binding.pipelineOwner.semanticsOwner!.performAction(1, SemanticsAction.increase);
await tester.pumpAndSettle();
expect(lastSelectedItem, 3);
......@@ -1404,7 +1368,7 @@ void main() {
testWidgets('CupertinoDataPicker does not provide invalid MediaQuery', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/47989.
Brightness brightness = Brightness.light;
StateSetter setState;
late StateSetter setState;
await tester.pumpWidget(
CupertinoApp(
......@@ -1421,7 +1385,7 @@ void main() {
home: StatefulBuilder(builder: (BuildContext context, StateSetter stateSetter) {
setState = stateSetter;
return MediaQuery(
data: MediaQuery.of(context).copyWith(platformBrightness: brightness),
data: MediaQuery.of(context)!.copyWith(platformBrightness: brightness),
child: CupertinoDatePicker(
initialDateTime: DateTime(2019),
mode: CupertinoDatePickerMode.date,
......@@ -1433,7 +1397,7 @@ void main() {
);
expect(
tester.widget<Text>(find.text('2019')).style.color,
tester.widget<Text>(find.text('2019')).style!.color,
isSameColorAs(const Color(0xFFFFFFFF)),
);
......@@ -1441,7 +1405,7 @@ void main() {
await tester.pump();
expect(
tester.widget<Text>(find.text('2019')).style.color,
tester.widget<Text>(find.text('2019')).style!.color,
isSameColorAs(const Color(0xFF000000)),
);
});
......@@ -1449,7 +1413,7 @@ void main() {
testWidgets('picker exports semantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
debugResetSemanticsIdCounter();
int lastSelectedItem;
int? lastSelectedItem;
await tester.pumpWidget(_buildPicker(onSelectedItemChanged: (int index) {
lastSelectedItem = index;
}));
......@@ -1466,7 +1430,7 @@ void main() {
],
));
tester.binding.pipelineOwner.semanticsOwner.performAction(1, SemanticsAction.increase);
tester.binding.pipelineOwner.semanticsOwner!.performAction(1, SemanticsAction.increase);
await tester.pumpAndSettle();
expect(tester.getSemantics(find.byType(CupertinoPicker)), matchesSemantics(
......@@ -1486,7 +1450,10 @@ void main() {
});
}
Widget _buildPicker({ FixedExtentScrollController controller, ValueChanged<int> onSelectedItemChanged }) {
Widget _buildPicker({
FixedExtentScrollController? controller,
required ValueChanged<int> onSelectedItemChanged,
}) {
return Directionality(
textDirection: TextDirection.ltr,
child: CupertinoPicker(
......
......@@ -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';
import 'package:flutter/cupertino.dart';
......@@ -118,7 +116,7 @@ void main() {
final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle));
expect(widget.style.color.withAlpha(255), CupertinoColors.systemRed.color);
expect(widget.style!.color!.withAlpha(255), CupertinoColors.systemRed.color);
});
testWidgets('Dialog dark theme', (WidgetTester tester) async {
......@@ -143,7 +141,7 @@ void main() {
);
expect(
cancelText.text.style.color.value,
cancelText.text.style!.color!.value,
0xFF0A84FF, // dark elevated color of systemBlue.
);
......@@ -233,7 +231,7 @@ void main() {
final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle));
expect(widget.style.fontWeight, equals(FontWeight.w600));
expect(widget.style!.fontWeight, equals(FontWeight.w600));
});
testWidgets('Dialog default and destructive action styles', (WidgetTester tester) async {
......@@ -245,8 +243,8 @@ void main() {
final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle));
expect(widget.style.color.withAlpha(255), CupertinoColors.systemRed.color);
expect(widget.style.fontWeight, equals(FontWeight.w600));
expect(widget.style!.color!.withAlpha(255), CupertinoColors.systemRed.color);
expect(widget.style!.fontWeight, equals(FontWeight.w600));
});
testWidgets('Dialog disabled action style', (WidgetTester tester) async {
......@@ -256,8 +254,8 @@ void main() {
final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle));
expect(widget.style.color.opacity, greaterThanOrEqualTo(127 / 255));
expect(widget.style.color.opacity, lessThanOrEqualTo(128 / 255));
expect(widget.style!.color!.opacity, greaterThanOrEqualTo(127 / 255));
expect(widget.style!.color!.opacity, lessThanOrEqualTo(128 / 255));
});
testWidgets('Dialog enabled action style', (WidgetTester tester) async {
......@@ -268,7 +266,7 @@ void main() {
final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle));
expect(widget.style.color.opacity, equals(1.0));
expect(widget.style!.color!.opacity, equals(1.0));
});
testWidgets('Message is scrollable, has correct padding with large text sizes', (WidgetTester tester) async {
......@@ -277,7 +275,7 @@ void main() {
createAppWithButtonThatLaunchesDialog(
dialogBuilder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
child: CupertinoAlertDialog(
title: const Text('The Title'),
content: Text('Very long content ' * 20),
......@@ -377,7 +375,7 @@ void main() {
createAppWithButtonThatLaunchesDialog(
dialogBuilder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
child: CupertinoAlertDialog(
title: const Text('The title'),
content: const Text('The content.'),
......@@ -438,7 +436,7 @@ void main() {
createAppWithButtonThatLaunchesDialog(
dialogBuilder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor),
child: CupertinoAlertDialog(
actions: const <Widget>[
CupertinoDialogAction(
......@@ -489,7 +487,7 @@ void main() {
createAppWithButtonThatLaunchesDialog(
dialogBuilder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor),
child: CupertinoAlertDialog(
title: const Text('The title'),
content: const Text('The content.'),
......@@ -554,11 +552,11 @@ void main() {
testWidgets('Actions section height for 2 side-by-side buttons is height of tallest button.', (WidgetTester tester) async {
final ScrollController scrollController = ScrollController();
double dividerWidth; // Will be set when the dialog builder runs. Needs a BuildContext.
late double dividerWidth; // Will be set when the dialog builder runs. Needs a BuildContext.
await tester.pumpWidget(
createAppWithButtonThatLaunchesDialog(
dialogBuilder: (BuildContext context) {
dividerWidth = 1.0 / MediaQuery.of(context).devicePixelRatio;
dividerWidth = 1.0 / MediaQuery.of(context)!.devicePixelRatio;
return CupertinoAlertDialog(
title: const Text('The Title'),
content: const Text('The message'),
......@@ -599,11 +597,11 @@ void main() {
testWidgets('Actions section height for 2 stacked buttons with enough room is height of both buttons.', (WidgetTester tester) async {
final ScrollController scrollController = ScrollController();
double dividerThickness; // Will be set when the dialog builder runs. Needs a BuildContext.
late double dividerThickness; // Will be set when the dialog builder runs. Needs a BuildContext.
await tester.pumpWidget(
createAppWithButtonThatLaunchesDialog(
dialogBuilder: (BuildContext context) {
dividerThickness = 1.0 / MediaQuery.of(context).devicePixelRatio;
dividerThickness = 1.0 / MediaQuery.of(context)!.devicePixelRatio;
return CupertinoAlertDialog(
title: const Text('The Title'),
content: const Text('The message'),
......@@ -679,7 +677,7 @@ void main() {
createAppWithButtonThatLaunchesDialog(
dialogBuilder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
child: CupertinoAlertDialog(
title: const Text('The Title'),
content: Text('The message\n' * 20),
......@@ -807,11 +805,11 @@ void main() {
testWidgets('Pressed button changes appearance and dividers disappear.', (WidgetTester tester) async {
final ScrollController scrollController = ScrollController();
double dividerThickness; // Will be set when the dialog builder runs. Needs a BuildContext.
late double dividerThickness; // Will be set when the dialog builder runs. Needs a BuildContext.
await tester.pumpWidget(
createAppWithButtonThatLaunchesDialog(
dialogBuilder: (BuildContext context) {
dividerThickness = 1.0 / MediaQuery.of(context).devicePixelRatio;
dividerThickness = 1.0 / MediaQuery.of(context)!.devicePixelRatio;
return CupertinoAlertDialog(
title: const Text('The Title'),
content: const Text('The message'),
......@@ -1153,7 +1151,7 @@ void main() {
createAppWithButtonThatLaunchesDialog(
dialogBuilder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 3.0),
child: const RepaintBoundary(
child: CupertinoAlertDialog(
title: Text('Title'),
......@@ -1195,7 +1193,9 @@ RenderBox findScrollableActionsSectionRenderBox(WidgetTester tester) {
return actionsSection as RenderBox;
}
Widget createAppWithButtonThatLaunchesDialog({ WidgetBuilder dialogBuilder }) {
Widget createAppWithButtonThatLaunchesDialog({
required WidgetBuilder dialogBuilder
}) {
return MaterialApp(
home: Material(
child: Center(
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -11,7 +9,7 @@ void main() {
testWidgets('IconTheme.of works', (WidgetTester tester) async {
const IconThemeData data = IconThemeData(color: Color(0xAAAAAAAA), opacity: 0.5, size: 16.0);
IconThemeData retrieved;
late IconThemeData retrieved;
await tester.pumpWidget(
IconTheme(data: data, child: Builder(builder: (BuildContext context) {
retrieved = IconTheme.of(context);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
......@@ -394,11 +392,11 @@ void main() {
..sort((Element a, Element b) {
final RenderParagraph aParagraph = a.renderObject as RenderParagraph;
final RenderParagraph bParagraph = b.renderObject as RenderParagraph;
return aParagraph.text.style.fontSize.compareTo(bParagraph.text.style.fontSize);
return aParagraph.text.style!.fontSize!.compareTo(bParagraph.text.style!.fontSize!);
});
Iterable<double> opacities = titles.map<double>((Element element) {
final RenderAnimatedOpacity renderOpacity = element.findAncestorRenderObjectOfType<RenderAnimatedOpacity>();
final RenderAnimatedOpacity renderOpacity = element.findAncestorRenderObjectOfType<RenderAnimatedOpacity>()!;
return renderOpacity.opacity.value;
});
......@@ -419,11 +417,11 @@ void main() {
..sort((Element a, Element b) {
final RenderParagraph aParagraph = a.renderObject as RenderParagraph;
final RenderParagraph bParagraph = b.renderObject as RenderParagraph;
return aParagraph.text.style.fontSize.compareTo(bParagraph.text.style.fontSize);
return aParagraph.text.style!.fontSize!.compareTo(bParagraph.text.style!.fontSize!);
});
opacities = titles.map<double>((Element element) {
final RenderAnimatedOpacity renderOpacity = element.findAncestorRenderObjectOfType<RenderAnimatedOpacity>();
final RenderAnimatedOpacity renderOpacity = element.findAncestorRenderObjectOfType<RenderAnimatedOpacity>()!;
return renderOpacity.opacity.value;
});
......@@ -531,7 +529,7 @@ void main() {
expect(find.text('Different title'), findsOneWidget);
RenderAnimatedOpacity largeTitleOpacity =
tester.element(find.text('Title')).findAncestorRenderObjectOfType<RenderAnimatedOpacity>();
tester.element(find.text('Title')).findAncestorRenderObjectOfType<RenderAnimatedOpacity>()!;
// Large title initially visible.
expect(
largeTitleOpacity.opacity.value,
......@@ -550,7 +548,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 300));
largeTitleOpacity =
tester.element(find.text('Title')).findAncestorRenderObjectOfType<RenderAnimatedOpacity>();
tester.element(find.text('Title')).findAncestorRenderObjectOfType<RenderAnimatedOpacity>()!;
// Large title no longer visible.
expect(
largeTitleOpacity.opacity.value,
......@@ -680,7 +678,7 @@ void main() {
final BoxDecoration decoration = decoratedBox.decoration as BoxDecoration;
expect(decoration.border, isNotNull);
final BorderSide side = decoration.border.bottom;
final BorderSide side = decoration.border!.bottom;
expect(side, isNotNull);
});
......@@ -708,7 +706,7 @@ void main() {
final BoxDecoration decoration = decoratedBox.decoration as BoxDecoration;
expect(decoration.border, isNotNull);
final BorderSide side = decoration.border.bottom;
final BorderSide side = decoration.border!.bottom;
expect(side, isNotNull);
expect(side.color, const Color(0xFFAABBCC));
});
......@@ -757,7 +755,7 @@ void main() {
final BoxDecoration decoration = decoratedBox.decoration as BoxDecoration;
expect(decoration.border, isNotNull);
final BorderSide bottom = decoration.border.bottom;
final BorderSide bottom = decoration.border!.bottom;
expect(bottom, isNotNull);
});
......@@ -863,10 +861,10 @@ void main() {
final BoxDecoration decoration = decoratedBox.decoration as BoxDecoration;
expect(decoration.border, isNotNull);
final BorderSide top = decoration.border.top;
final BorderSide top = decoration.border!.top;
expect(top, isNotNull);
expect(top, BorderSide.none);
final BorderSide bottom = decoration.border.bottom;
final BorderSide bottom = decoration.border!.bottom;
expect(bottom, isNotNull);
expect(bottom.color, const Color(0xFFAABBCC));
});
......@@ -1108,7 +1106,7 @@ void main() {
CupertinoApp(
home: Builder(builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 99),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 99),
child: CupertinoPageScaffold(
child: CustomScrollView(
slivers: <Widget>[
......@@ -1156,7 +1154,7 @@ void main() {
title: 'title',
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 99),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: 99),
child: Container(
child: const CupertinoPageScaffold(
child: CustomScrollView(
......@@ -1190,14 +1188,17 @@ void main() {
}
class _ExpectStyles extends StatelessWidget {
const _ExpectStyles({ this.color, this.index });
const _ExpectStyles({
required this.color,
required this.index
});
final Color color;
final int index;
@override
Widget build(BuildContext context) {
final TextStyle style = DefaultTextStyle.of(context).style;
final TextStyle style = DefaultTextStyle.of(context).style!;
expect(style.color, isSameColorAs(color));
expect(style.fontFamily, '.SF Pro Text');
expect(style.fontSize, 17.0);
......
......@@ -2,28 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
Future<void> startTransitionBetween(
WidgetTester tester, {
Widget from,
Widget to,
String fromTitle,
String toTitle,
Widget? from,
Widget? to,
String? fromTitle,
String? toTitle,
TextDirection textDirection = TextDirection.ltr,
CupertinoThemeData theme,
CupertinoThemeData? theme,
}) async {
await tester.pumpWidget(
CupertinoApp(
theme: theme,
builder: (BuildContext context, Widget navigator) {
builder: (BuildContext context, Widget? navigator) {
return Directionality(
textDirection: textDirection,
child: navigator,
child: navigator!,
);
},
home: const Placeholder(),
......@@ -34,7 +32,7 @@ Future<void> startTransitionBetween(
.state<NavigatorState>(find.byType(Navigator))
.push(CupertinoPageRoute<void>(
title: fromTitle,
builder: (BuildContext context) => scaffoldForNavBar(from),
builder: (BuildContext context) => scaffoldForNavBar(from)!,
));
await tester.pump();
......@@ -44,16 +42,16 @@ Future<void> startTransitionBetween(
.state<NavigatorState>(find.byType(Navigator))
.push(CupertinoPageRoute<void>(
title: toTitle,
builder: (BuildContext context) => scaffoldForNavBar(to),
builder: (BuildContext context) => scaffoldForNavBar(to)!,
));
await tester.pump();
}
CupertinoPageScaffold scaffoldForNavBar(Widget navBar) {
CupertinoPageScaffold? scaffoldForNavBar(Widget? navBar) {
if (navBar is CupertinoNavigationBar || navBar == null) {
return CupertinoPageScaffold(
navigationBar: navBar as CupertinoNavigationBar ?? const CupertinoNavigationBar(),
navigationBar: navBar as CupertinoNavigationBar? ?? const CupertinoNavigationBar(),
child: const Placeholder(),
);
} else if (navBar is CupertinoSliverNavigationBar) {
......@@ -175,10 +173,10 @@ void main() {
// The transition's stack is ordered. The bottom middle is inserted first.
final RenderParagraph bottomMiddle =
tester.renderObject(flying(tester, find.text('Page 1')).first);
expect(bottomMiddle.text.style.color, const Color(0xff00050a));
expect(bottomMiddle.text.style.fontWeight, FontWeight.w600);
expect(bottomMiddle.text.style.fontFamily, '.SF Pro Text');
expect(bottomMiddle.text.style.letterSpacing, -0.41);
expect(bottomMiddle.text.style!.color, const Color(0xff00050a));
expect(bottomMiddle.text.style!.fontWeight, FontWeight.w600);
expect(bottomMiddle.text.style!.fontFamily, '.SF Pro Text');
expect(bottomMiddle.text.style!.letterSpacing, -0.41);
checkOpacity(
tester, flying(tester, find.text('Page 1')).first, 0.9004602432250977);
......@@ -187,26 +185,26 @@ void main() {
// are flipped.
final RenderParagraph topBackLabel =
tester.renderObject(flying(tester, find.text('Page 1')).last);
expect(topBackLabel.text.style.color, const Color(0xff00050a));
expect(topBackLabel.text.style.fontWeight, FontWeight.w600);
expect(topBackLabel.text.style.fontFamily, '.SF Pro Text');
expect(topBackLabel.text.style.letterSpacing, -0.41);
expect(topBackLabel.text.style!.color, const Color(0xff00050a));
expect(topBackLabel.text.style!.fontWeight, FontWeight.w600);
expect(topBackLabel.text.style!.fontFamily, '.SF Pro Text');
expect(topBackLabel.text.style!.letterSpacing, -0.41);
checkOpacity(tester, flying(tester, find.text('Page 1')).last, 0.0);
// Move animation further a bit.
await tester.pump(const Duration(milliseconds: 200));
expect(bottomMiddle.text.style.color, const Color(0xff006de4));
expect(bottomMiddle.text.style.fontWeight, FontWeight.w400);
expect(bottomMiddle.text.style.fontFamily, '.SF Pro Text');
expect(bottomMiddle.text.style.letterSpacing, -0.41);
expect(bottomMiddle.text.style!.color, const Color(0xff006de4));
expect(bottomMiddle.text.style!.fontWeight, FontWeight.w400);
expect(bottomMiddle.text.style!.fontFamily, '.SF Pro Text');
expect(bottomMiddle.text.style!.letterSpacing, -0.41);
checkOpacity(tester, flying(tester, find.text('Page 1')).first, 0.0);
expect(topBackLabel.text.style.color, const Color(0xff006de4));
expect(topBackLabel.text.style.fontWeight, FontWeight.w400);
expect(topBackLabel.text.style.fontFamily, '.SF Pro Text');
expect(topBackLabel.text.style.letterSpacing, -0.41);
expect(topBackLabel.text.style!.color, const Color(0xff006de4));
expect(topBackLabel.text.style!.fontWeight, FontWeight.w400);
expect(topBackLabel.text.style!.fontFamily, '.SF Pro Text');
expect(topBackLabel.text.style!.letterSpacing, -0.41);
checkOpacity(
tester, flying(tester, find.text('Page 1')).last, 0.7630139589309692);
......@@ -225,10 +223,10 @@ void main() {
// The transition's stack is ordered. The bottom middle is inserted first.
final RenderParagraph bottomMiddle =
tester.renderObject(flying(tester, find.text('Page 1')).first);
expect(bottomMiddle.text.style.color, const Color(0xFFF4F9FF));
expect(bottomMiddle.text.style.fontWeight, FontWeight.w600);
expect(bottomMiddle.text.style.fontFamily, '.SF Pro Text');
expect(bottomMiddle.text.style.letterSpacing, -0.41);
expect(bottomMiddle.text.style!.color, const Color(0xFFF4F9FF));
expect(bottomMiddle.text.style!.fontWeight, FontWeight.w600);
expect(bottomMiddle.text.style!.fontFamily, '.SF Pro Text');
expect(bottomMiddle.text.style!.letterSpacing, -0.41);
checkOpacity(tester, flying(tester, find.text('Page 1')).first, 0.9004602432250977);
......@@ -236,26 +234,26 @@ void main() {
// are flipped.
final RenderParagraph topBackLabel =
tester.renderObject(flying(tester, find.text('Page 1')).last);
expect(topBackLabel.text.style.color, const Color(0xFFF4F9FF));
expect(topBackLabel.text.style.fontWeight, FontWeight.w600);
expect(topBackLabel.text.style.fontFamily, '.SF Pro Text');
expect(topBackLabel.text.style.letterSpacing, -0.41);
expect(topBackLabel.text.style!.color, const Color(0xFFF4F9FF));
expect(topBackLabel.text.style!.fontWeight, FontWeight.w600);
expect(topBackLabel.text.style!.fontFamily, '.SF Pro Text');
expect(topBackLabel.text.style!.letterSpacing, -0.41);
checkOpacity(tester, flying(tester, find.text('Page 1')).last, 0.0);
// Move animation further a bit.
await tester.pump(const Duration(milliseconds: 200));
expect(bottomMiddle.text.style.color, const Color(0xFF2390FF));
expect(bottomMiddle.text.style.fontWeight, FontWeight.w400);
expect(bottomMiddle.text.style.fontFamily, '.SF Pro Text');
expect(bottomMiddle.text.style.letterSpacing, -0.41);
expect(bottomMiddle.text.style!.color, const Color(0xFF2390FF));
expect(bottomMiddle.text.style!.fontWeight, FontWeight.w400);
expect(bottomMiddle.text.style!.fontFamily, '.SF Pro Text');
expect(bottomMiddle.text.style!.letterSpacing, -0.41);
checkOpacity(tester, flying(tester, find.text('Page 1')).first, 0.0);
expect(topBackLabel.text.style.color, const Color(0xFF2390FF));
expect(topBackLabel.text.style.fontWeight, FontWeight.w400);
expect(topBackLabel.text.style.fontFamily, '.SF Pro Text');
expect(topBackLabel.text.style.letterSpacing, -0.41);
expect(topBackLabel.text.style!.color, const Color(0xFF2390FF));
expect(topBackLabel.text.style!.fontWeight, FontWeight.w400);
expect(topBackLabel.text.style!.fontFamily, '.SF Pro Text');
expect(topBackLabel.text.style!.letterSpacing, -0.41);
checkOpacity(tester, flying(tester, find.text('Page 1')).last, 0.7630139589309692);
});
......@@ -271,7 +269,7 @@ void main() {
.state<NavigatorState>(find.byType(Navigator))
.push(CupertinoPageRoute<void>(
title: 'Page 1',
builder: (BuildContext context) => scaffoldForNavBar(null),
builder: (BuildContext context) => scaffoldForNavBar(null)!,
));
await tester.pump();
......@@ -282,7 +280,7 @@ void main() {
.push(CupertinoPageRoute<void>(
title: 'Page 2',
fullscreenDialog: true,
builder: (BuildContext context) => scaffoldForNavBar(null),
builder: (BuildContext context) => scaffoldForNavBar(null)!,
));
await tester.pump();
......@@ -328,7 +326,7 @@ void main() {
// The transition's stack is ordered. The bottom middle is inserted first.
final RenderParagraph bottomMiddle =
tester.renderObject(flying(tester, find.text('Page 1')).first);
expect(bottomMiddle.text.style.color, const Color(0xff00050a));
expect(bottomMiddle.text.style!.color, const Color(0xff00050a));
expect(
tester.getTopLeft(flying(tester, find.text('Page 1')).first),
const Offset(337.0234375, 13.5),
......@@ -338,7 +336,7 @@ void main() {
// are flipped.
final RenderParagraph topBackLabel =
tester.renderObject(flying(tester, find.text('Page 1')).last);
expect(topBackLabel.text.style.color, const Color(0xff00050a));
expect(topBackLabel.text.style!.color, const Color(0xff00050a));
expect(
tester.getTopLeft(flying(tester, find.text('Page 1')).last),
const Offset(337.0234375, 13.5),
......@@ -373,7 +371,7 @@ void main() {
// The transition's stack is ordered. The bottom middle is inserted first.
final RenderParagraph bottomMiddle =
tester.renderObject(flying(tester, find.text('Page 1')).first);
expect(bottomMiddle.text.style.color, const Color(0xff00050a));
expect(bottomMiddle.text.style!.color, const Color(0xff00050a));
expect(
tester.getTopLeft(flying(tester, find.text('Page 1')).first),
const Offset(362.9765625, 13.5),
......@@ -383,7 +381,7 @@ void main() {
// are flipped.
final RenderParagraph topBackLabel =
tester.renderObject(flying(tester, find.text('Page 1')).last);
expect(topBackLabel.text.style.color, const Color(0xff00050a));
expect(topBackLabel.text.style!.color, const Color(0xff00050a));
expect(
tester.getTopLeft(flying(tester, find.text('Page 1')).last),
const Offset(362.9765625, 13.5),
......@@ -584,7 +582,7 @@ void main() {
.state<NavigatorState>(find.byType(Navigator))
.push(CupertinoPageRoute<void>(
title: 'Page 1',
builder: (BuildContext context) => scaffoldForNavBar(null),
builder: (BuildContext context) => scaffoldForNavBar(null)!,
));
await tester.pump();
......@@ -612,10 +610,10 @@ void main() {
testWidgets('First appearance of back chevron fades in from the left in RTL', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
builder: (BuildContext context, Widget navigator) {
builder: (BuildContext context, Widget? navigator) {
return Directionality(
textDirection: TextDirection.rtl,
child: navigator,
child: navigator!,
);
},
home: scaffoldForNavBar(null),
......@@ -626,7 +624,7 @@ void main() {
.state<NavigatorState>(find.byType(Navigator))
.push(CupertinoPageRoute<void>(
title: 'Page 1',
builder: (BuildContext context) => scaffoldForNavBar(null),
builder: (BuildContext context) => scaffoldForNavBar(null)!,
));
await tester.pump();
......@@ -778,7 +776,7 @@ void main() {
.state<NavigatorState>(find.byType(Navigator))
.push(CupertinoPageRoute<void>(
title: 'Page 3',
builder: (BuildContext context) => scaffoldForNavBar(null),
builder: (BuildContext context) => scaffoldForNavBar(null)!,
));
await tester.pump();
......@@ -815,7 +813,7 @@ void main() {
.state<NavigatorState>(find.byType(Navigator))
.push(CupertinoPageRoute<void>(
title: 'Page 3',
builder: (BuildContext context) => scaffoldForNavBar(null),
builder: (BuildContext context) => scaffoldForNavBar(null)!,
));
await tester.pump();
......@@ -931,30 +929,30 @@ void main() {
// The transition's stack is ordered. The bottom large title is inserted first.
final RenderParagraph bottomLargeTitle =
tester.renderObject(flying(tester, find.text('Page 1')).first);
expect(bottomLargeTitle.text.style.color, const Color(0xff00050a));
expect(bottomLargeTitle.text.style.fontWeight, FontWeight.w700);
expect(bottomLargeTitle.text.style.fontFamily, '.SF Pro Display');
expect(bottomLargeTitle.text.style.letterSpacing, moreOrLessEquals(0.374765625));
expect(bottomLargeTitle.text.style!.color, const Color(0xff00050a));
expect(bottomLargeTitle.text.style!.fontWeight, FontWeight.w700);
expect(bottomLargeTitle.text.style!.fontFamily, '.SF Pro Display');
expect(bottomLargeTitle.text.style!.letterSpacing, moreOrLessEquals(0.374765625));
// The top back label is styled exactly the same way.
final RenderParagraph topBackLabel =
tester.renderObject(flying(tester, find.text('Page 1')).last);
expect(topBackLabel.text.style.color, const Color(0xff00050a));
expect(topBackLabel.text.style.fontWeight, FontWeight.w700);
expect(topBackLabel.text.style.fontFamily, '.SF Pro Display');
expect(topBackLabel.text.style.letterSpacing, moreOrLessEquals(0.374765625));
expect(topBackLabel.text.style!.color, const Color(0xff00050a));
expect(topBackLabel.text.style!.fontWeight, FontWeight.w700);
expect(topBackLabel.text.style!.fontFamily, '.SF Pro Display');
expect(topBackLabel.text.style!.letterSpacing, moreOrLessEquals(0.374765625));
// Move animation further a bit.
await tester.pump(const Duration(milliseconds: 200));
expect(bottomLargeTitle.text.style.color, const Color(0xff006de4));
expect(bottomLargeTitle.text.style.fontWeight, FontWeight.w400);
expect(bottomLargeTitle.text.style.fontFamily, '.SF Pro Text');
expect(bottomLargeTitle.text.style.letterSpacing, moreOrLessEquals(-0.32379547566175454));
expect(topBackLabel.text.style.color, const Color(0xff006de4));
expect(topBackLabel.text.style.fontWeight, FontWeight.w400);
expect(topBackLabel.text.style.fontFamily, '.SF Pro Text');
expect(topBackLabel.text.style.letterSpacing, moreOrLessEquals(-0.32379547566175454));
expect(bottomLargeTitle.text.style!.color, const Color(0xff006de4));
expect(bottomLargeTitle.text.style!.fontWeight, FontWeight.w400);
expect(bottomLargeTitle.text.style!.fontFamily, '.SF Pro Text');
expect(bottomLargeTitle.text.style!.letterSpacing, moreOrLessEquals(-0.32379547566175454));
expect(topBackLabel.text.style!.color, const Color(0xff006de4));
expect(topBackLabel.text.style!.fontWeight, FontWeight.w400);
expect(topBackLabel.text.style!.fontFamily, '.SF Pro Text');
expect(topBackLabel.text.style!.letterSpacing, moreOrLessEquals(-0.32379547566175454));
});
testWidgets('Top middle fades in and slides in from the right', (WidgetTester tester) async {
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -276,10 +274,10 @@ void main() {
testWidgets('test edge swipes work with media query padding (LTR)', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
builder: (BuildContext context, Widget navigator) {
builder: (BuildContext context, Widget? navigator) {
return MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(left: 40)),
child: navigator,
child: navigator!,
);
},
home: const Placeholder(),
......@@ -320,12 +318,12 @@ void main() {
testWidgets('test edge swipes work with media query padding (RLT)', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
builder: (BuildContext context, Widget navigator) {
builder: (BuildContext context, Widget? navigator) {
return Directionality(
textDirection: TextDirection.rtl,
child: MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(right: 40)),
child: navigator,
child: navigator!,
),
);
},
......@@ -471,7 +469,7 @@ void main() {
expect(find.text('subpage'), findsOneWidget);
expect(find.text('home'), findsNothing);
navigator.currentState.pop();
navigator.currentState!.pop();
await tester.pump();
expect(find.text('subpage'), findsOneWidget);
......@@ -498,14 +496,14 @@ class RtlOverrideWidgetsLocalization implements WidgetsLocalizations {
class KeepsStateTestWidget extends StatefulWidget {
const KeepsStateTestWidget({this.navigatorKey});
final Key navigatorKey;
final Key? navigatorKey;
@override
State<KeepsStateTestWidget> createState() => _KeepsStateTestWidgetState();
}
class _KeepsStateTestWidgetState extends State<KeepsStateTestWidget> {
String _subpage = 'subpage';
String? _subpage = 'subpage';
@override
Widget build(BuildContext context) {
......@@ -514,7 +512,7 @@ class _KeepsStateTestWidgetState extends State<KeepsStateTestWidget> {
key: widget.navigatorKey,
pages: <Page<void>>[
const CupertinoPage<void>(child: Text('home')),
if (_subpage != null) CupertinoPage<void>(child: Text(_subpage)),
if (_subpage != null) CupertinoPage<void>(child: Text(_subpage!)),
],
onPopPage: (Route<dynamic> route, dynamic result) {
if (!route.didPop(result)) {
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
......@@ -39,8 +37,8 @@ void main() {
final RenderParagraph paragraph = tester.renderObject(find.text('1'));
expect(paragraph.text.style.color, isSameColorAs(CupertinoColors.black));
expect(paragraph.text.style.copyWith(color: CupertinoColors.black), const TextStyle(
expect(paragraph.text.style!.color, isSameColorAs(CupertinoColors.black));
expect(paragraph.text.style!.copyWith(color: CupertinoColors.black), const TextStyle(
inherit: false,
fontFamily: '.SF Pro Display',
fontSize: 21.0,
......
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