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: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,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