diff --git a/packages/flutter/test/cupertino/refresh_test.dart b/packages/flutter/test/cupertino/refresh_test.dart index cb2b79dc07..1c6573bcd3 100644 --- a/packages/flutter/test/cupertino/refresh_test.dart +++ b/packages/flutter/test/cupertino/refresh_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 'dart:async'; import 'package:flutter/cupertino.dart'; @@ -13,7 +11,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { - FakeBuilder mockHelper; + late FakeBuilder mockHelper; setUp(() { mockHelper = FakeBuilder(); @@ -1407,10 +1405,10 @@ class RefreshTaskInvocation extends MockHelperInvocation { @immutable class BuilderInvocation extends MockHelperInvocation { const BuilderInvocation({ - @required this.refreshState, - @required this.pulledExtent, - @required this.refreshIndicatorExtent, - @required this.refreshTriggerPullDistance, + required this.refreshState, + required this.pulledExtent, + required this.refreshIndicatorExtent, + required this.refreshTriggerPullDistance, }); final RefreshIndicatorMode refreshState; @@ -1423,10 +1421,10 @@ class BuilderInvocation extends MockHelperInvocation { } Matcher matchesBuilder({ - @required RefreshIndicatorMode refreshState, - @required dynamic pulledExtent, - @required dynamic refreshTriggerPullDistance, - @required dynamic refreshIndicatorExtent, + required RefreshIndicatorMode refreshState, + required dynamic pulledExtent, + required dynamic refreshTriggerPullDistance, + required dynamic refreshIndicatorExtent, }) { return isA() .having((BuilderInvocation invocation) => invocation.refreshState, 'refreshState', refreshState) diff --git a/packages/flutter/test/cupertino/route_test.dart b/packages/flutter/test/cupertino/route_test.dart index a86346d3d7..4613bbb378 100644 --- a/packages/flutter/test/cupertino/route_test.dart +++ b/packages/flutter/test/cupertino/route_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/foundation.dart'; import 'package:flutter/material.dart'; @@ -13,40 +11,12 @@ import 'package:flutter_test/flutter_test.dart'; import '../widgets/semantics_tester.dart'; void main() { - MockNavigatorObserver navigatorObserver; + late MockNavigatorObserver navigatorObserver; setUp(() { navigatorObserver = MockNavigatorObserver(); }); - testWidgets( - 'Throws FlutterError with correct message when route builder returns null', - (WidgetTester tester) async { - await tester.pumpWidget( - const CupertinoApp( - home: Placeholder(), - ), - ); - - tester.state(find.byType(Navigator)).push( - CupertinoPageRoute( - title: 'Route 1', - builder: (_) => null, - ), - ); - - await tester.pump(); - await tester.pump(const Duration(milliseconds: 500)); - - final dynamic error = tester.takeException(); - expect(error, isFlutterError); - expect(error.toStringDeep(), equalsIgnoringHashCodes( - 'FlutterError\n' - ' The builder for route "null" returned null.\n' - ' Route builders must never return null.\n' - )); - }); - testWidgets('Middle auto-populates with title', (WidgetTester tester) async { await tester.pumpWidget( const CupertinoApp( @@ -115,14 +85,14 @@ 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! ); }); final Iterable opacities = titles.map((Element element) { final RenderAnimatedOpacity renderOpacity = - element.findAncestorRenderObjectOfType(); + element.findAncestorRenderObjectOfType()!; return renderOpacity.opacity.value; }); @@ -305,7 +275,7 @@ void main() { child: Center( child: CupertinoButton( onPressed: () { - Navigator.push(scaffoldKey.currentContext, CupertinoPageRoute( + Navigator.push(scaffoldKey.currentContext!, CupertinoPageRoute( builder: (BuildContext context) { return const CupertinoPageScaffold( child: Center(child: Text('route')), @@ -383,7 +353,7 @@ void main() { // Use the navigator to push a route instead of tapping the 'push' button. // The topmost route (the one that's animating away), ignores input while // the pop is underway because route.navigator.userGestureInProgress. - Navigator.push(scaffoldKey.currentContext, CupertinoPageRoute( + Navigator.push(scaffoldKey.currentContext!, CupertinoPageRoute( builder: (BuildContext context) { return const CupertinoPageScaffold( child: Center(child: Text('route')), @@ -503,7 +473,7 @@ void main() { expect(tester.getTopLeft(find.byType(Placeholder)).dy, moreOrLessEquals(600.0, epsilon: 0.1)); }); - Future testParallax(WidgetTester tester, {@required bool fromFullscreenDialog}) async { + Future testParallax(WidgetTester tester, {required bool fromFullscreenDialog}) async { await tester.pumpWidget( CupertinoApp( onGenerateRoute: (RouteSettings settings) => CupertinoPageRoute( @@ -592,7 +562,7 @@ void main() { await testParallax(tester, fromFullscreenDialog: true); }); - Future testNoParallax(WidgetTester tester, {@required bool fromFullscreenDialog}) async{ + Future testNoParallax(WidgetTester tester, {required bool fromFullscreenDialog}) async{ await tester.pumpWidget( CupertinoApp( onGenerateRoute: (RouteSettings settings) => CupertinoPageRoute( @@ -844,7 +814,7 @@ void main() { } ); - navigatorKey.currentState.push(route2); + navigatorKey.currentState!.push(route2); await tester.pumpAndSettle(); expect(navigatorObserver.invocations.removeLast(), NavigatorInvocation.didPush); @@ -852,14 +822,14 @@ void main() { expect(navigatorObserver.invocations.removeLast(), NavigatorInvocation.didStartUserGesture); await tester.pump(); expect(tester.getTopLeft(find.text('2')).dx, moreOrLessEquals(100)); - expect(navigatorKey.currentState.userGestureInProgress, true); + expect(navigatorKey.currentState!.userGestureInProgress, true); // Didn't drag far enough to snap into dismissing this route. // Each 100px distance takes 100ms to snap back. await tester.pump(const Duration(milliseconds: 101)); // Back to the page covering the whole screen. expect(tester.getTopLeft(find.text('2')).dx, moreOrLessEquals(0)); - expect(navigatorKey.currentState.userGestureInProgress, false); + expect(navigatorKey.currentState!.userGestureInProgress, false); expect(navigatorObserver.invocations.removeLast(), NavigatorInvocation.didStopUserGesture); expect(navigatorObserver.invocations.removeLast(), isNot(NavigatorInvocation.didPop)); @@ -867,7 +837,7 @@ void main() { await tester.dragFrom(const Offset(5, 100), const Offset(500, 0)); await tester.pump(); expect(tester.getTopLeft(find.text('2')).dx, moreOrLessEquals(500)); - expect(navigatorKey.currentState.userGestureInProgress, true); + expect(navigatorKey.currentState!.userGestureInProgress, true); expect(navigatorObserver.invocations.removeLast(), NavigatorInvocation.didPop); // Did go far enough to snap out of this route. @@ -876,7 +846,7 @@ void main() { expect(find.text('2'), findsNothing); // First route covers the whole screen. expect(tester.getTopLeft(find.text('1')).dx, moreOrLessEquals(0)); - expect(navigatorKey.currentState.userGestureInProgress, false); + expect(navigatorKey.currentState!.userGestureInProgress, false); }); /// Regression test for https://github.com/flutter/flutter/issues/29596. @@ -967,7 +937,7 @@ void main() { }); testWidgets('ModalPopup overlay dark mode', (WidgetTester tester) async { - StateSetter stateSetter; + late StateSetter stateSetter; Brightness brightness = Brightness.light; await tester.pumpWidget( @@ -998,7 +968,7 @@ void main() { await tester.pumpAndSettle(); expect( - tester.widget(find.byType(ModalBarrier).last).color.value, + tester.widget(find.byType(ModalBarrier).last).color!.value, 0x33000000, ); @@ -1007,7 +977,7 @@ void main() { // TODO(LongCatIsLooong): The background overlay SHOULD switch to dark color. expect( - tester.widget(find.byType(ModalBarrier).last).color.value, + tester.widget(find.byType(ModalBarrier).last).color!.value, 0x33000000, ); @@ -1034,7 +1004,7 @@ void main() { await tester.pumpAndSettle(); expect( - tester.widget(find.byType(ModalBarrier).last).color.value, + tester.widget(find.byType(ModalBarrier).last).color!.value, 0x7A000000, ); }); @@ -1064,7 +1034,7 @@ void main() { expect(homeTapCount, 1); expect(pageTapCount, 0); - Navigator.push(homeScaffoldKey.currentContext, CupertinoPageRoute( + Navigator.push(homeScaffoldKey.currentContext!, CupertinoPageRoute( builder: (BuildContext context) { return CupertinoPageScaffold( key: pageScaffoldKey, @@ -1172,7 +1142,7 @@ void main() { RenderBox box = tester.renderObject(find.byKey(container)) as RenderBox; final double initialPosition = box.localToGlobal(Offset.zero).dx; - navigator.currentState.pushNamed('/page2'); + navigator.currentState!.pushNamed('/page2'); await tester.pumpAndSettle(); box = tester.renderObject(find.byKey(container)) as RenderBox; final double finalPosition = box.localToGlobal(Offset.zero).dx; @@ -1522,7 +1492,10 @@ void main() { await tester.pumpWidget( buildNavigator( pages: myPages, - onPopPage: (Route route, dynamic result) => null, + onPopPage: (Route route, dynamic result) { + assert(false); // The test shouldn't call this. + return true; + }, transitionDelegate: detector, ) ); @@ -1545,7 +1518,10 @@ void main() { await tester.pumpWidget( buildNavigator( pages: myPages, - onPopPage: (Route route, dynamic result) => null, + onPopPage: (Route route, dynamic result) { + assert(false); // The test shouldn't call this. + return true; + }, transitionDelegate: detector, ) ); @@ -1570,7 +1546,10 @@ void main() { await tester.pumpWidget( buildNavigator( pages: myPages, - onPopPage: (Route route, dynamic result) => null, + onPopPage: (Route route, dynamic result) { + assert(false); // The test shouldn't call this. + return true; + }, transitionDelegate: detector, ) ); @@ -1588,7 +1567,10 @@ void main() { await tester.pumpWidget( buildNavigator( pages: myPages, - onPopPage: (Route route, dynamic result) => null, + onPopPage: (Route route, dynamic result) { + assert(false); // The test shouldn't call this. + return true; + }, transitionDelegate: detector, ) ); @@ -1624,17 +1606,17 @@ class MockNavigatorObserver extends NavigatorObserver { final List invocations = []; @override - void didStartUserGesture(Route route, Route previousRoute) { + void didStartUserGesture(Route route, Route? previousRoute) { invocations.add(NavigatorInvocation.didStartUserGesture); } @override - void didPop(Route route, Route previousRoute) { + void didPop(Route route, Route? previousRoute) { invocations.add(NavigatorInvocation.didPop); } @override - void didPush(Route route, Route previousRoute) { + void didPush(Route route, Route? previousRoute) { invocations.add(NavigatorInvocation.didPush); } @@ -1655,7 +1637,7 @@ class PopupObserver extends NavigatorObserver { int popupCount = 0; @override - void didPush(Route route, Route previousRoute) { + void didPush(Route route, Route? previousRoute) { if (route.toString().contains('_CupertinoModalPopupRoute')) { popupCount++; } @@ -1667,7 +1649,7 @@ class DialogObserver extends NavigatorObserver { int dialogCount = 0; @override - void didPush(Route route, Route previousRoute) { + void didPush(Route route, Route? previousRoute) { if (route.toString().contains('_DialogRoute')) { dialogCount++; } @@ -1679,9 +1661,9 @@ class TransitionDetector extends DefaultTransitionDelegate { bool hasTransition = false; @override Iterable resolve({ - List newPageRouteHistory, - Map locationToExitingPageRoute, - Map> pageRouteToPagelessRoutes + required List newPageRouteHistory, + required Map locationToExitingPageRoute, + required Map> pageRouteToPagelessRoutes, }) { hasTransition = true; return super.resolve( @@ -1693,13 +1675,13 @@ class TransitionDetector extends DefaultTransitionDelegate { } Widget buildNavigator({ - List> pages, - PopPageCallback onPopPage, - GlobalKey key, - TransitionDelegate transitionDelegate + required List> pages, + PopPageCallback? onPopPage, + GlobalKey? key, + TransitionDelegate? transitionDelegate }) { return MediaQuery( - data: MediaQueryData.fromWindow(WidgetsBinding.instance.window), + data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window), child: Localizations( locale: const Locale('en', 'US'), delegates: const >[ diff --git a/packages/flutter/test/cupertino/scaffold_test.dart b/packages/flutter/test/cupertino/scaffold_test.dart index b100332fc4..1116ae17a9 100644 --- a/packages/flutter/test/cupertino/scaffold_test.dart +++ b/packages/flutter/test/cupertino/scaffold_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 'dart:typed_data'; import 'package:flutter/cupertino.dart'; @@ -31,7 +29,7 @@ void main() { }); testWidgets('Opaque bar pushes contents down', (WidgetTester tester) async { - BuildContext childContext; + late BuildContext childContext; await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, child: MediaQuery( @@ -51,7 +49,7 @@ void main() { ), )); - expect(MediaQuery.of(childContext).padding.top, 0); + expect(MediaQuery.of(childContext)!.padding.top, 0); // The top of the [Container] is 44 px from the top of the screen because // it's pushed down by the opaque navigation bar whose height is 44 px, // and the 20 px [MediaQuery] top padding is fully absorbed by the navigation bar. @@ -69,7 +67,7 @@ void main() { darkColor: Color(0xFF000000), ); - BuildContext childContext; + late BuildContext childContext; Widget scaffoldWithBrightness(Brightness brightness) { return Directionality( textDirection: TextDirection.ltr, @@ -96,12 +94,12 @@ void main() { } await tester.pumpWidget(scaffoldWithBrightness(Brightness.light)); - expect(MediaQuery.of(childContext).padding.top, 0); + expect(MediaQuery.of(childContext)!.padding.top, 0); expect(find.byType(CupertinoPageScaffold), paints..rect(color: backgroundColor.color)); await tester.pumpWidget(scaffoldWithBrightness(Brightness.dark)); - expect(MediaQuery.of(childContext).padding.top, greaterThan(0)); + expect(MediaQuery.of(childContext)!.padding.top, greaterThan(0)); expect(find.byType(CupertinoPageScaffold), paints..rect(color: backgroundColor.darkColor)); }); @@ -122,7 +120,7 @@ void main() { expect(tester.getSize(find.byType(Container)).height, 600.0 - 44.0 - 100.0); - BuildContext childContext; + late BuildContext childContext; await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, child: MediaQuery( @@ -144,7 +142,7 @@ void main() { expect(tester.getSize(find.byType(Container)).height, 600.0 - 100.0); // The shouldn't see a media query view inset because it was consumed by // the scaffold. - expect(MediaQuery.of(childContext).viewInsets.bottom, 0); + expect(MediaQuery.of(childContext)!.viewInsets.bottom, 0); await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, @@ -324,7 +322,7 @@ void main() { child: CupertinoButton( child: const Text('Next'), onPressed: () { - Navigator.of(context).push( + Navigator.of(context)!.push( CupertinoPageRoute( builder: (BuildContext context) { return CupertinoPageScaffold( @@ -335,7 +333,7 @@ void main() { child: CupertinoButton( child: const Text('Back'), onPressed: () { - Navigator.of(context).pop(); + Navigator.of(context)!.pop(); }, ), ), @@ -438,11 +436,11 @@ void main() { testWidgets('Lists in CupertinoPageScaffold scroll to the top when status bar tapped', (WidgetTester tester) async { await tester.pumpWidget( CupertinoApp( - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { // Acts as a 20px status bar at the root of the app. return MediaQuery( - data: MediaQuery.of(context).copyWith(padding: const EdgeInsets.only(top: 20)), - child: child, + data: MediaQuery.of(context)!.copyWith(padding: const EdgeInsets.only(top: 20)), + child: child!, ); }, home: CupertinoPageScaffold( @@ -539,7 +537,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: const CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( middle: Text('middle'), diff --git a/packages/flutter/test/cupertino/scrollbar_paint_test.dart b/packages/flutter/test/cupertino/scrollbar_paint_test.dart index bd2c4a120b..e1b1c4298e 100644 --- a/packages/flutter/test/cupertino/scrollbar_paint_test.dart +++ b/packages/flutter/test/cupertino/scrollbar_paint_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_test/flutter_test.dart'; diff --git a/packages/flutter/test/cupertino/scrollbar_test.dart b/packages/flutter/test/cupertino/scrollbar_test.dart index 2c6a0483cf..6fe3e4041a 100644 --- a/packages/flutter/test/cupertino/scrollbar_test.dart +++ b/packages/flutter/test/cupertino/scrollbar_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'; @@ -62,7 +60,7 @@ void main() { testWidgets('Scrollbar dark mode', (WidgetTester tester) async { Brightness brightness = Brightness.light; - StateSetter setState; + late StateSetter setState; await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, diff --git a/packages/flutter/test/cupertino/segmented_control_test.dart b/packages/flutter/test/cupertino/segmented_control_test.dart index d9b8ced94f..4607b7efb9 100644 --- a/packages/flutter/test/cupertino/segmented_control_test.dart +++ b/packages/flutter/test/cupertino/segmented_control_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/widgets.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -41,7 +39,7 @@ StatefulBuilder setupSimpleSegmentedControl() { ); } -Widget boilerplate({ Widget child }) { +Widget boilerplate({ required Widget child }) { return Directionality( textDirection: TextDirection.ltr, child: Center(child: child), @@ -132,18 +130,18 @@ void main() { child: Text('Child 2'), ) ; - Future verifyPadding({ EdgeInsets padding }) async { + Future verifyPadding({ EdgeInsets? padding }) async { final EdgeInsets effectivePadding = padding ?? const EdgeInsets.symmetric(horizontal: 16); final Rect segmentedControlRect = tester.getRect(find.byKey(key)); expect( - tester.getTopLeft(find.byWidget(children[0])), + tester.getTopLeft(find.byWidget(children[0]!)), segmentedControlRect.topLeft.translate( effectivePadding.topLeft.dx, effectivePadding.topLeft.dy, ), ); expect( - tester.getBottomLeft(find.byWidget(children[0])), + tester.getBottomLeft(find.byWidget(children[0]!)), segmentedControlRect.bottomLeft.translate( effectivePadding.bottomLeft.dx, effectivePadding.bottomLeft.dy, @@ -151,14 +149,14 @@ void main() { ); expect( - tester.getTopRight(find.byWidget(children[1])), + tester.getTopRight(find.byWidget(children[1]!)), segmentedControlRect.topRight.translate( effectivePadding.topRight.dx, effectivePadding.topRight.dy, ), ); expect( - tester.getBottomRight(find.byWidget(children[1])), + tester.getBottomRight(find.byWidget(children[1]!)), segmentedControlRect.bottomRight.translate( effectivePadding.bottomRight.dx, effectivePadding.bottomRight.dy, @@ -228,40 +226,6 @@ void main() { } }); - testWidgets('Children and onValueChanged arguments can not be null', (WidgetTester tester) async { - try { - await tester.pumpWidget( - boilerplate( - child: CupertinoSegmentedControl( - children: null, - onValueChanged: (int newValue) { }, - ), - ), - ); - fail('Should not be possible to create segmented control with null children'); - } on AssertionError catch (e) { - expect(e.toString(), contains('children')); - } - - final Map children = {}; - children[0] = const Text('Child 1'); - children[1] = const Text('Child 2'); - - try { - await tester.pumpWidget( - boilerplate( - child: CupertinoSegmentedControl( - children: children, - onValueChanged: null, - ), - ), - ); - fail('Should not be possible to create segmented control with null onValueChanged'); - } on AssertionError catch (e) { - expect(e.toString(), contains('onValueChanged')); - } - }); - testWidgets('Widgets have correct default text/icon styles, change correctly on selection', (WidgetTester tester) async { final Map children = {}; children[0] = const Text('Child 1'); @@ -292,7 +256,7 @@ void main() { DefaultTextStyle textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1')); IconTheme iconTheme = tester.widget(find.widgetWithIcon(IconTheme, const IconData(1))); - expect(textStyle.style.color, isSameColorAs(CupertinoColors.white)); + expect(textStyle.style!.color, isSameColorAs(CupertinoColors.white)); expect(iconTheme.data.color, CupertinoColors.activeBlue); await tester.tap(find.widgetWithIcon(IconTheme, const IconData(1))); @@ -301,7 +265,7 @@ void main() { textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1')); iconTheme = tester.widget(find.widgetWithIcon(IconTheme, const IconData(1))); - expect(textStyle.style.color, CupertinoColors.activeBlue); + expect(textStyle.style!.color, CupertinoColors.activeBlue); expect(iconTheme.data.color, isSameColorAs(CupertinoColors.white)); }); @@ -336,7 +300,7 @@ void main() { DefaultTextStyle textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1').first); IconThemeData iconTheme = IconTheme.of(tester.element(find.byIcon(const IconData(1)))); - expect(textStyle.style.color, isSameColorAs(CupertinoColors.black)); + expect(textStyle.style!.color, isSameColorAs(CupertinoColors.black)); expect(iconTheme.color, isSameColorAs(CupertinoColors.systemBlue.darkColor)); await tester.tap(find.byIcon(const IconData(1))); @@ -346,7 +310,7 @@ void main() { textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1').first); iconTheme = IconTheme.of(tester.element(find.byIcon(const IconData(1)))); - expect(textStyle.style.color, isSameColorAs(CupertinoColors.systemBlue.darkColor)); + expect(textStyle.style!.color, isSameColorAs(CupertinoColors.systemBlue.darkColor)); expect(iconTheme.color, isSameColorAs(CupertinoColors.black)); }, ); @@ -384,7 +348,7 @@ void main() { IconTheme iconTheme = tester.widget(find.widgetWithIcon(IconTheme, const IconData(1))); expect(getRenderSegmentedControl(tester).borderColor, CupertinoColors.black); - expect(textStyle.style.color, CupertinoColors.lightBackgroundGray); + expect(textStyle.style!.color, CupertinoColors.lightBackgroundGray); expect(iconTheme.data.color, CupertinoColors.activeGreen.color); expect(getBackgroundColor(tester, 0), CupertinoColors.activeGreen.color); expect(getBackgroundColor(tester, 1), CupertinoColors.lightBackgroundGray); @@ -395,7 +359,7 @@ void main() { textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1')); iconTheme = tester.widget(find.widgetWithIcon(IconTheme, const IconData(1))); - expect(textStyle.style.color, CupertinoColors.activeGreen.color); + expect(textStyle.style!.color, CupertinoColors.activeGreen.color); expect(iconTheme.data.color, CupertinoColors.lightBackgroundGray); expect(getBackgroundColor(tester, 0), CupertinoColors.lightBackgroundGray); expect(getBackgroundColor(tester, 1), CupertinoColors.activeGreen.color); @@ -562,7 +526,7 @@ void main() { children[0] = const Text('Child 1'); children[1] = const Text('Child 2'); - int sharedValue; + int? sharedValue; await tester.pumpWidget( StatefulBuilder( @@ -930,7 +894,7 @@ void main() { testWidgets('Hit-tests report accurate local position in segments', (WidgetTester tester) async { final Map children = {}; - TapDownDetails tapDownDetails; + late TapDownDetails tapDownDetails; children[0] = GestureDetector( behavior: HitTestBehavior.opaque, onTapDown: (TapDownDetails details) { tapDownDetails = details; }, @@ -961,7 +925,7 @@ void main() { expect(sharedValue, 1); - final Offset segment0GlobalOffset = tester.getTopLeft(find.byWidget(children[0])); + final Offset segment0GlobalOffset = tester.getTopLeft(find.byWidget(children[0]!)); await tester.tapAt(segment0GlobalOffset + const Offset(7, 11)); expect(tapDownDetails.localPosition, const Offset(7, 11)); @@ -998,7 +962,7 @@ void main() { expect(sharedValue, 0); - final Offset centerOfTwo = tester.getCenter(find.byWidget(children[1])); + final Offset centerOfTwo = tester.getCenter(find.byWidget(children[1]!)); // Tap within the bounds of children[1], but not at the center. // children[1] is a SizedBox thus not hittable by itself. await tester.tapAt(centerOfTwo + const Offset(10, 0)); @@ -1418,7 +1382,7 @@ void main() { children[0] = const Text('A'); children[1] = const Text('B'); children[2] = const Text('C'); - int sharedValue = 0; + int? sharedValue = 0; await tester.pumpWidget( StatefulBuilder( diff --git a/packages/flutter/test/cupertino/slider_test.dart b/packages/flutter/test/cupertino/slider_test.dart index 5f224ee54b..15a9623da3 100644 --- a/packages/flutter/test/cupertino/slider_test.dart +++ b/packages/flutter/test/cupertino/slider_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/material.dart'; import 'package:flutter/rendering.dart'; @@ -66,7 +64,7 @@ void main() { await tester.pump(); // No animation should start. // Check the transientCallbackCount before tearing down the widget to ensure // that no animation is running. - expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(0)); }); testWidgets('Slider does not move when tapped (RTL)', (WidgetTester tester) async { @@ -102,7 +100,7 @@ void main() { await tester.pump(); // No animation should start. // Check the transientCallbackCount before tearing down the widget to ensure // that no animation is running. - expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(0)); }); testWidgets('Slider calls onChangeStart once when interaction begins', (WidgetTester tester) async { @@ -143,7 +141,7 @@ void main() { await tester.pump(); // No animation should start. // Check the transientCallbackCount before tearing down the widget to ensure // that no animation is running. - expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(0)); }); testWidgets('Slider calls onChangeEnd once after interaction has ended', (WidgetTester tester) async { @@ -184,14 +182,14 @@ void main() { await tester.pump(); // No animation should start. // Check the transientCallbackCount before tearing down the widget to ensure // that no animation is running. - expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(0)); }); testWidgets('Slider moves when dragged (LTR)', (WidgetTester tester) async { final Key sliderKey = UniqueKey(); double value = 0.0; - double startValue; - double endValue; + late double startValue; + late double endValue; await tester.pumpWidget( CupertinoApp( @@ -238,14 +236,14 @@ void main() { await tester.pump(); // No animation should start. // Check the transientCallbackCount before tearing down the widget to ensure // that no animation is running. - expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(0)); }); testWidgets('Slider moves when dragged (RTL)', (WidgetTester tester) async { final Key sliderKey = UniqueKey(); double value = 0.0; - double startValue; - double endValue; + late double startValue; + late double endValue; await tester.pumpWidget( CupertinoApp( @@ -292,7 +290,7 @@ void main() { await tester.pump(); // No animation should start. // Check the transientCallbackCount before tearing down the widget to ensure // that no animation is running. - expect(SchedulerBinding.instance.transientCallbackCount, equals(0)); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(0)); }); testWidgets('Slider Semantics', (WidgetTester tester) async { diff --git a/packages/flutter/test/cupertino/sliding_segmented_control_test.dart b/packages/flutter/test/cupertino/sliding_segmented_control_test.dart index 72663d9f6a..0f80e8e06f 100644 --- a/packages/flutter/test/cupertino/sliding_segmented_control_test.dart +++ b/packages/flutter/test/cupertino/sliding_segmented_control_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 'dart:collection'; import 'package:flutter/gestures.dart'; @@ -28,7 +26,7 @@ Rect currentUnscaledThumbRect(WidgetTester tester, { bool useGlobalCoordinate = return local; final RenderBox segmentedControl = renderSegmentedControl as RenderBox; - return local?.shift(segmentedControl.localToGlobal(Offset.zero)); + return local.shift(segmentedControl.localToGlobal(Offset.zero)); } double currentThumbScale(WidgetTester tester) => getRenderSegmentedControl(tester).currentThumbScale as double; @@ -50,13 +48,13 @@ Widget setupSimpleSegmentedControl() { ); } -StateSetter setState; -int groupValue = 0; -void defaultCallback(int newValue) { - setState(() { groupValue = newValue; }); +StateSetter? setState; +int? groupValue = 0; +void defaultCallback(int? newValue) { + setState!(() { groupValue = newValue; }); } -Widget boilerplate({ WidgetBuilder builder }) { +Widget boilerplate({ required WidgetBuilder builder }) { return Directionality( textDirection: TextDirection.ltr, child: Center( @@ -75,54 +73,6 @@ void main() { groupValue = 0; }); - testWidgets('Children and onValueChanged and padding arguments can not be null', (WidgetTester tester) async { - groupValue = null; - try { - await tester.pumpWidget( - CupertinoSlidingSegmentedControl( - children: null, - groupValue: groupValue, - onValueChanged: defaultCallback, - ), - ); - fail('Should not be possible to create segmented control with null children'); - } on AssertionError catch (e) { - expect(e.toString(), contains('children')); - } - - const Map children = { - 0: Text('Child 1'), - 1: Text('Child 2'), - }; - - try { - await tester.pumpWidget( - CupertinoSlidingSegmentedControl( - children: children, - groupValue: groupValue, - onValueChanged: null, - ), - ); - fail('Should not be possible to create segmented control without an onValueChanged'); - } on AssertionError catch (e) { - expect(e.toString(), contains('onValueChanged')); - } - - try { - await tester.pumpWidget( - CupertinoSlidingSegmentedControl( - children: children, - groupValue: groupValue, - onValueChanged: defaultCallback, - padding: null, - ), - ); - fail('Should not be possible to create segmented control with null padding'); - } on AssertionError catch (e) { - expect(e.toString(), contains('padding')); - } - }); - testWidgets('Need at least 2 children', (WidgetTester tester) async { final Map children = {}; groupValue = null; @@ -178,25 +128,25 @@ void main() { 1: Text('Child 2'), }; - Future verifyPadding({ EdgeInsets padding }) async { + Future verifyPadding({ EdgeInsets? padding }) async { final EdgeInsets effectivePadding = padding ?? const EdgeInsets.symmetric(vertical: 2, horizontal: 3); final Rect segmentedControlRect = tester.getRect(find.byKey(key)); expect( - tester.getTopLeft(find.ancestor(of: find.byWidget(children[0]), matching: find.byType(Opacity))), + tester.getTopLeft(find.ancestor(of: find.byWidget(children[0]!), matching: find.byType(Opacity))), segmentedControlRect.topLeft + effectivePadding.topLeft, ); expect( - tester.getBottomLeft(find.ancestor(of: find.byWidget(children[0]), matching: find.byType(Opacity))), + tester.getBottomLeft(find.ancestor(of: find.byWidget(children[0]!), matching: find.byType(Opacity))), segmentedControlRect.bottomLeft + effectivePadding.bottomLeft, ); expect( - tester.getTopRight(find.ancestor(of: find.byWidget(children[1]), matching: find.byType(Opacity))), + tester.getTopRight(find.ancestor(of: find.byWidget(children[1]!), matching: find.byType(Opacity))), segmentedControlRect.topRight + effectivePadding.topRight, ); expect( - tester.getBottomRight(find.ancestor(of: find.byWidget(children[1]), matching: find.byType(Opacity))), + tester.getBottomRight(find.ancestor(of: find.byWidget(children[1]!), matching: find.byType(Opacity))), segmentedControlRect.bottomRight + effectivePadding.bottomRight, ); } @@ -304,7 +254,7 @@ void main() { DefaultTextStyle textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1').first); - expect(textStyle.style.fontWeight, FontWeight.w500); + expect(textStyle.style!.fontWeight, FontWeight.w500); await tester.tap(find.byIcon(const IconData(1))); await tester.pump(); @@ -313,7 +263,7 @@ void main() { textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1').first); expect(groupValue, 1); - expect(textStyle.style.fontWeight, FontWeight.normal); + expect(textStyle.style!.fontWeight, FontWeight.normal); }, ); @@ -324,7 +274,7 @@ void main() { }; Brightness brightness = Brightness.light; - StateSetter setState; + late StateSetter setState; await tester.pumpWidget( StatefulBuilder( @@ -354,7 +304,7 @@ void main() { )).decoration as BoxDecoration; expect(getRenderSegmentedControl(tester).thumbColor.value, CupertinoColors.systemGreen.color.value); - expect(decoration.color.value, CupertinoColors.systemRed.color.value); + expect(decoration.color!.value, CupertinoColors.systemRed.color.value); setState(() { brightness = Brightness.dark; }); await tester.pump(); @@ -366,7 +316,7 @@ void main() { expect(getRenderSegmentedControl(tester).thumbColor.value, CupertinoColors.systemGreen.darkColor.value); - expect(decorationDark.color.value, CupertinoColors.systemRed.darkColor.value); + expect(decorationDark.color!.value, CupertinoColors.systemRed.darkColor.value); }); testWidgets( @@ -777,7 +727,7 @@ void main() { expect(groupValue, 0); - final Offset centerOfTwo = tester.getCenter(find.byWidget(children[1])); + final Offset centerOfTwo = tester.getCenter(find.byWidget(children[1]!)); // Tap within the bounds of children[1], but not at the center. // children[1] is a SizedBox thus not hittable by itself. await tester.tapAt(centerOfTwo + const Offset(10, 0)); @@ -787,7 +737,7 @@ void main() { testWidgets('Hit-tests report accurate local position in segments', (WidgetTester tester) async { final Map children = {}; - TapDownDetails tapDownDetails; + late TapDownDetails tapDownDetails; children[0] = GestureDetector( behavior: HitTestBehavior.opaque, onTapDown: (TapDownDetails details) { tapDownDetails = details; }, @@ -810,7 +760,7 @@ void main() { expect(groupValue, 0); - final Offset segment0GlobalOffset = tester.getTopLeft(find.byWidget(children[0])); + final Offset segment0GlobalOffset = tester.getTopLeft(find.byWidget(children[0]!)); await tester.tapAt(segment0GlobalOffset + const Offset(7, 11)); expect(tapDownDetails.localPosition, const Offset(7, 11)); diff --git a/packages/flutter/test/cupertino/switch_test.dart b/packages/flutter/test/cupertino/switch_test.dart index a186670331..3dc549548d 100644 --- a/packages/flutter/test/cupertino/switch_test.dart +++ b/packages/flutter/test/cupertino/switch_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_test/flutter_test.dart'; import 'package:flutter/gestures.dart'; diff --git a/packages/flutter/test/cupertino/tab_scaffold_test.dart b/packages/flutter/test/cupertino/tab_scaffold_test.dart index 7e717be5be..896969229e 100644 --- a/packages/flutter/test/cupertino/tab_scaffold_test.dart +++ b/packages/flutter/test/cupertino/tab_scaffold_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 'dart:typed_data'; import 'package:flutter/cupertino.dart'; @@ -12,10 +10,10 @@ import 'package:flutter_test/flutter_test.dart'; import '../image_data.dart'; import '../rendering/rendering_tester.dart'; -List selectedTabs; +late List selectedTabs; class MockCupertinoTabController extends CupertinoTabController { - MockCupertinoTabController({ int initialIndex }): super(initialIndex: initialIndex); + MockCupertinoTabController({ required int initialIndex }): super(initialIndex: initialIndex); bool isDisposed = false; int numOfListeners = 0; @@ -75,12 +73,12 @@ void main() { of: find.text('Tab 1'), matching: find.byType(RichText), )); - expect(tab1.text.style.color, CupertinoColors.activeBlue); + expect(tab1.text.style!.color, CupertinoColors.activeBlue); RichText tab2 = tester.widget(find.descendant( of: find.text('Tab 2'), matching: find.byType(RichText), )); - expect(tab2.text.style.color.value, 0xFF999999); + expect(tab2.text.style!.color!.value, 0xFF999999); await tester.tap(find.text('Tab 2')); await tester.pump(); @@ -90,12 +88,12 @@ void main() { of: find.text('Tab 1'), matching: find.byType(RichText), )); - expect(tab1.text.style.color.value, 0xFF999999); + expect(tab1.text.style!.color!.value, 0xFF999999); tab2 = tester.widget(find.descendant( of: find.text('Tab 2'), matching: find.byType(RichText), )); - expect(tab2.text.style.color, CupertinoColors.activeBlue); + expect(tab2.text.style!.color, CupertinoColors.activeBlue); await tester.tap(find.text('Tab 1')); await tester.pump(); @@ -377,16 +375,16 @@ void main() { matching: find.byType(RichText), )); // Tab 2 should still be selected after changing theme. - expect(tab1.text.style.color.value, 0xFF757575); + expect(tab1.text.style!.color!.value, 0xFF757575); final RichText tab2 = tester.widget(find.descendant( of: find.text('Tab 2'), matching: find.byType(RichText), )); - expect(tab2.text.style.color, isSameColorAs(CupertinoColors.systemRed.darkColor)); + expect(tab2.text.style!.color, isSameColorAs(CupertinoColors.systemRed.darkColor)); }); testWidgets('Tab contents are padded when there are view insets', (WidgetTester tester) async { - BuildContext innerContext; + late BuildContext innerContext; await tester.pumpWidget( CupertinoApp( @@ -408,11 +406,11 @@ void main() { expect(tester.getRect(find.byType(Placeholder)), const Rect.fromLTWH(0, 0, 800, 400)); // Don't generate more media query padding from the translucent bottom // tab since the tab is behind the keyboard now. - expect(MediaQuery.of(innerContext).padding.bottom, 0); + expect(MediaQuery.of(innerContext)!.padding.bottom, 0); }); testWidgets('Tab contents are not inset when resizeToAvoidBottomInset overridden', (WidgetTester tester) async { - BuildContext innerContext; + late BuildContext innerContext; await tester.pumpWidget( CupertinoApp( @@ -435,7 +433,7 @@ void main() { expect(tester.getRect(find.byType(Placeholder)), const Rect.fromLTWH(0, 0, 800, 600)); // Media query padding shows up in the inner content because it wasn't masked // by the view inset. - expect(MediaQuery.of(innerContext).padding.bottom, 50); + expect(MediaQuery.of(innerContext)!.padding.bottom, 50); }); testWidgets('Tab contents bottom padding are not consumed by viewInsets when resizeToAvoidBottomInset overridden', (WidgetTester tester) async { @@ -492,7 +490,7 @@ void main() { (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/43581. Future getContentPaddingWithTabBarColor(Color color) async { - EdgeInsets contentPadding; + late EdgeInsets contentPadding; await tester.pumpWidget( CupertinoApp( @@ -504,7 +502,7 @@ void main() { items: List.generate(2, tabGenerator), ), tabBuilder: (BuildContext context, int index) { - contentPadding = MediaQuery.of(context).padding; + contentPadding = MediaQuery.of(context)!.padding; return const Placeholder(); } ), @@ -519,7 +517,7 @@ void main() { }); testWidgets('Tab and page scaffolds do not double stack view insets', (WidgetTester tester) async { - BuildContext innerContext; + late BuildContext innerContext; await tester.pumpWidget( CupertinoApp( @@ -545,7 +543,7 @@ void main() { ); expect(tester.getRect(find.byType(Placeholder)), const Rect.fromLTWH(0, 0, 800, 400)); - expect(MediaQuery.of(innerContext).padding.bottom, 0); + expect(MediaQuery.of(innerContext)!.padding.bottom, 0); }); testWidgets('Deleting tabs after selecting them should switch to the last available tab', (WidgetTester tester) async { @@ -965,7 +963,7 @@ void main() { testWidgets("Don't replace focus nodes for existing tabs when changing tab count", (WidgetTester tester) async { final CupertinoTabController controller = CupertinoTabController(initialIndex: 2); - final List scopes = List(5); + final List scopes = List.filled(5, FocusScopeNode()); await tester.pumpWidget( CupertinoApp( home: CupertinoTabScaffold( @@ -987,7 +985,7 @@ void main() { } await tester.pump(); - final List newScopes = List(5); + final List newScopes = []; await tester.pumpWidget( CupertinoApp( home: CupertinoTabScaffold( @@ -996,7 +994,7 @@ void main() { ), controller: controller, tabBuilder: (BuildContext context, int index) { - newScopes[index] = FocusScope.of(context); + newScopes.add(FocusScope.of(context)); return Container(); }, ), @@ -1021,12 +1019,10 @@ void main() { } expectAssertionError(() => CupertinoTabController(initialIndex: -1), '>= 0'); - expectAssertionError(() => CupertinoTabController(initialIndex: null), '!= null'); final CupertinoTabController controller = CupertinoTabController(); expectAssertionError(() => controller.index = -1, '>= 0'); - expectAssertionError(() => controller.index = null, '!= null'); }); testWidgets('Does not lose state when focusing on text input', (WidgetTester tester) async { @@ -1078,7 +1074,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: CupertinoTabScaffold( tabBar: CupertinoTabBar( items: List.generate( diff --git a/packages/flutter/test/cupertino/tab_test.dart b/packages/flutter/test/cupertino/tab_test.dart index 1686890346..3de11516f2 100644 --- a/packages/flutter/test/cupertino/tab_test.dart +++ b/packages/flutter/test/cupertino/tab_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_test/flutter_test.dart'; @@ -42,7 +40,7 @@ void main() { return CupertinoButton( child: const Text('go to second page'), onPressed: () { - Navigator.of(context).pushNamed('/2'); + Navigator.of(context)!.pushNamed('/2'); }, ); }, @@ -83,12 +81,12 @@ void main() { }); testWidgets('Use onUnknownRoute', (WidgetTester tester) async { - String unknownForRouteCalled; + late String unknownForRouteCalled; await tester.pumpWidget( CupertinoApp( home: CupertinoTabView( onUnknownRoute: (RouteSettings settings) { - unknownForRouteCalled = settings.name; + unknownForRouteCalled = settings.name!; return null; }, ), @@ -117,7 +115,7 @@ void main() { ), ); - key.currentState.pushNamed('/2'); + key.currentState!.pushNamed('/2'); await tester.pump(); await tester.pump(const Duration(milliseconds: 300)); @@ -133,7 +131,7 @@ void main() { return CupertinoButton( child: const Text('go to second page'), onPressed: () { - Navigator.of(context).pushNamed('/2'); + Navigator.of(context)!.pushNamed('/2'); }, ); }, @@ -158,7 +156,7 @@ void main() { return CupertinoButton( child: const Text('go to second page'), onPressed: () { - Navigator.of(context).pushNamed('/2'); + Navigator.of(context)!.pushNamed('/2'); }, ); }, @@ -186,9 +184,9 @@ void main() { ), ), ); - FlutterError error; + late FlutterError error; try { - key.currentState.pushNamed('/2'); + key.currentState!.pushNamed('/2'); } on FlutterError catch (e) { error = e; } @@ -222,9 +220,9 @@ void main() { ), ), ); - FlutterError error; + late FlutterError error; try { - key.currentState.pushNamed('/2'); + key.currentState!.pushNamed('/2'); } on FlutterError catch (e) { error = e; }