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

[NNBD] More test migration for Cupertino & Painting (#67323)

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