Unverified Commit c083f02f authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Migrate more material tests to NNBD (#67674)

This migrates more material tests to NNBD.
parent dcb5975d
......@@ -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/foundation.dart';
......@@ -733,7 +731,7 @@ class LicensePageObserver extends NavigatorObserver {
int licensePageCount = 0;
@override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (route is MaterialPageRoute<dynamic>) {
licensePageCount++;
}
......@@ -745,7 +743,7 @@ class AboutDialogObserver extends NavigatorObserver {
int dialogCount = 0;
@override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (route.toString().contains('_DialogRoute')) {
dialogCount++;
}
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math show pi;
import 'package:flutter/material.dart';
......@@ -13,8 +11,8 @@ import '../flutter_test_alternative.dart' show Fake;
import '../widgets/semantics_tester.dart';
class MockCanvas extends Fake implements Canvas {
Path capturedPath;
Paint capturedPaint;
late Path capturedPath;
late Paint capturedPaint;
@override
void drawPath(Path path, Paint paint) {
......@@ -22,13 +20,13 @@ class MockCanvas extends Fake implements Canvas {
capturedPaint = paint;
}
double capturedSx;
double capturedSy;
late double capturedSx;
late double capturedSy;
@override
void scale(double sx, [double sy]) {
void scale(double sx, [double? sy]) {
capturedSx = sx;
capturedSy = sy;
capturedSy = sy!;
}
final List<RecordedCanvasCall> invocations = <RecordedCanvasCall>[];
......@@ -96,7 +94,7 @@ void main() {
);
final CustomPaint customPaint = tester.widget(find.byType(CustomPaint));
final MockCanvas canvas = MockCanvas();
customPaint.painter.paint(canvas, const Size(48.0, 48.0));
customPaint.painter!.paint(canvas, const Size(48.0, 48.0));
expect(canvas.capturedPaint, hasColor(0xFF666666));
});
......@@ -118,7 +116,7 @@ void main() {
);
final CustomPaint customPaint = tester.widget(find.byType(CustomPaint));
final MockCanvas canvas = MockCanvas();
customPaint.painter.paint(canvas, const Size(48.0, 48.0));
customPaint.painter!.paint(canvas, const Size(48.0, 48.0));
expect(canvas.capturedPaint, hasColor(0x80666666));
});
......@@ -140,7 +138,7 @@ void main() {
);
final CustomPaint customPaint = tester.widget(find.byType(CustomPaint));
final MockCanvas canvas = MockCanvas();
customPaint.painter.paint(canvas, const Size(48.0, 48.0));
customPaint.painter!.paint(canvas, const Size(48.0, 48.0));
expect(canvas.capturedPaint, hasColor(0xFF0000FF));
});
......@@ -162,7 +160,7 @@ void main() {
);
final CustomPaint customPaint = tester.widget(find.byType(CustomPaint));
final MockCanvas canvas = MockCanvas();
customPaint.painter.paint(canvas, const Size(12.0, 12.0));
customPaint.painter!.paint(canvas, const Size(12.0, 12.0));
// arrow_menu default size is 48x48 so we expect it to be scaled by 0.25.
expect(canvas.capturedSx, 0.25);
expect(canvas.capturedSy, 0.25);
......@@ -187,7 +185,7 @@ void main() {
);
final CustomPaint customPaint = tester.widget(find.byType(CustomPaint));
final MockCanvas canvas = MockCanvas();
customPaint.painter.paint(canvas, const Size(12.0, 12.0));
customPaint.painter!.paint(canvas, const Size(12.0, 12.0));
// arrow_menu default size is 48x48 so we expect it to be scaled by 2.
expect(canvas.capturedSx, 2);
expect(canvas.capturedSy, 2);
......@@ -230,7 +228,7 @@ void main() {
);
final CustomPaint customPaint = tester.widget(find.byType(CustomPaint));
final MockCanvas canvas = MockCanvas();
customPaint.painter.paint(canvas, const Size(48.0, 48.0));
customPaint.painter!.paint(canvas, const Size(48.0, 48.0));
expect(canvas.invocations, const <RecordedCanvasCall>[
RecordedRotate(math.pi),
RecordedTranslate(-48, -48),
......@@ -254,7 +252,7 @@ void main() {
);
final CustomPaint customPaint = tester.widget(find.byType(CustomPaint));
final MockCanvas canvas = MockCanvas();
customPaint.painter.paint(canvas, const Size(48.0, 48.0));
customPaint.painter!.paint(canvas, const Size(48.0, 48.0));
expect(canvas.invocations, isEmpty);
});
......@@ -276,7 +274,7 @@ void main() {
);
final CustomPaint customPaint = tester.widget(find.byType(CustomPaint));
final MockCanvas canvas = MockCanvas();
customPaint.painter.paint(canvas, const Size(48.0, 48.0));
customPaint.painter!.paint(canvas, const Size(48.0, 48.0));
expect(canvas.invocations, const <RecordedCanvasCall>[
RecordedRotate(math.pi),
RecordedTranslate(-48, -48),
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
......@@ -14,10 +12,10 @@ import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart';
Widget buildSliverAppBarApp({
bool floating,
bool pinned,
double collapsedHeight,
double expandedHeight,
bool floating = false,
bool pinned = false,
double? collapsedHeight,
double? expandedHeight,
bool snap = false,
double toolbarHeight = kToolbarHeight,
}) {
......@@ -65,7 +63,7 @@ Widget buildSliverAppBarApp({
}
ScrollController primaryScrollController(WidgetTester tester) {
return PrimaryScrollController.of(tester.element(find.byType(CustomScrollView)));
return PrimaryScrollController.of(tester.element(find.byType(CustomScrollView)))!;
}
double appBarHeight(WidgetTester tester) => tester.getSize(find.byType(AppBar, skipOffstage: false)).height;
......@@ -303,7 +301,7 @@ void main() {
final Key titleKey = UniqueKey();
Widget leading = Container();
List<Widget> actions;
List<Widget> actions = <Widget>[];
Widget buildApp() {
return MaterialApp(
......@@ -360,8 +358,8 @@ void main() {
final Key titleKey = UniqueKey();
double titleWidth = 700.0;
Widget leading = Container();
List<Widget> actions;
Widget? leading = Container();
List<Widget> actions = <Widget>[];
Widget buildApp() {
return MaterialApp(
......@@ -412,8 +410,8 @@ void main() {
final Key titleKey = UniqueKey();
double titleWidth = 700.0;
Widget leading = Container();
List<Widget> actions;
Widget? leading = Container();
List<Widget> actions = <Widget>[];
Widget buildApp() {
return MaterialApp(
......@@ -1952,14 +1950,14 @@ void main() {
});
testWidgets('AppBars title has upper limit on text scaling, textScaleFactor = 1, 1.34, 2', (WidgetTester tester) async {
double textScaleFactor;
late double textScaleFactor;
Widget buildFrame() {
return MaterialApp(
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor),
child: Scaffold(
appBar: AppBar(
centerTitle: false,
......@@ -1988,9 +1986,9 @@ void main() {
});
testWidgets('AppBars with jumbo titles, textScaleFactor = 3, 3.5, 4', (WidgetTester tester) async {
double textScaleFactor;
TextDirection textDirection;
bool centerTitle;
double textScaleFactor = 1.0;
TextDirection textDirection = TextDirection.ltr;
bool centerTitle = false;
Widget buildFrame() {
return MaterialApp(
......@@ -2004,7 +2002,7 @@ void main() {
appBar: AppBar(
centerTitle: centerTitle,
title: MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: textScaleFactor),
data: MediaQuery.of(context)!.copyWith(textScaleFactor: textScaleFactor),
child: const Text('Jumbo'),
),
),
......@@ -2023,10 +2021,8 @@ void main() {
// Overall screen size is 800x600
// Left or right justified title is padded by 16 on the "start" side.
// Toolbar height is 56.
// "Jumbo" title is 100x20.
textScaleFactor = 1; // "Jumbo" title is 100x20.
textDirection = TextDirection.ltr;
centerTitle = false;
await tester.pumpWidget(buildFrame());
expect(tester.getRect(appBarTitle), const Rect.fromLTRB(16, 18, 116, 38));
expect(tester.getCenter(appBarTitle).dy, tester.getCenter(toolbar).dy);
......@@ -2058,7 +2054,7 @@ void main() {
});
testWidgets('SliverAppBar configures the delegate properly', (WidgetTester tester) async {
Future<void> buildAndVerifyDelegate({ bool pinned, bool floating, bool snap }) async {
Future<void> buildAndVerifyDelegate({ required bool pinned, required bool floating, required bool snap }) async {
await tester.pumpWidget(
MaterialApp(
home: CustomScrollView(
......@@ -2150,17 +2146,6 @@ void main() {
expect(appBarHeight(tester), collapsedHeight + initialTabBarHeight);
});
test('SliverApp toolbarHeight cannot be null', () {
try{
SliverAppBar(
toolbarHeight: null,
);
} on AssertionError catch (error) {
expect(error.toString(), contains('toolbarHeight != null'));
expect(error.toString(), contains('is not true'));
}
});
testWidgets('AppBar respects leadingWidth', (WidgetTester tester) async {
const Key key = Key('leading');
await tester.pumpWidget(MaterialApp(
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
......@@ -31,14 +29,14 @@ void main() {
final RichText actionIconText = _getAppBarIconRichText(tester);
final DefaultTextStyle text = _getAppBarText(tester);
expect(SystemChrome.latestStyle.statusBarBrightness, Brightness.dark);
expect(SystemChrome.latestStyle!.statusBarBrightness, Brightness.dark);
expect(widget.color, Colors.blue);
expect(widget.elevation, 4.0);
expect(widget.shadowColor, Colors.black);
expect(iconTheme.data, const IconThemeData(color: Colors.white));
expect(actionsIconTheme.data, const IconThemeData(color: Colors.white));
expect(actionIconText.text.style.color, Colors.white);
expect(text.style, Typography.material2014().englishLike.bodyText2.merge(Typography.material2014().white.bodyText2));
expect(actionIconText.text.style!.color, Colors.white);
expect(text.style, Typography.material2014().englishLike.bodyText2!.merge(Typography.material2014().white.bodyText2));
});
testWidgets('AppBar uses values from AppBarTheme', (WidgetTester tester) async {
......@@ -60,14 +58,14 @@ void main() {
final RichText actionIconText = _getAppBarIconRichText(tester);
final DefaultTextStyle text = _getAppBarText(tester);
expect(SystemChrome.latestStyle.statusBarBrightness, appBarTheme.brightness);
expect(SystemChrome.latestStyle!.statusBarBrightness, appBarTheme.brightness);
expect(widget.color, appBarTheme.color);
expect(widget.elevation, appBarTheme.elevation);
expect(widget.shadowColor, appBarTheme.shadowColor);
expect(iconTheme.data, appBarTheme.iconTheme);
expect(actionsIconTheme.data, appBarTheme.actionsIconTheme);
expect(actionIconText.text.style.color, appBarTheme.actionsIconTheme.color);
expect(text.style, appBarTheme.textTheme.bodyText2);
expect(actionIconText.text.style!.color, appBarTheme.actionsIconTheme!.color);
expect(text.style, appBarTheme.textTheme!.bodyText2);
});
testWidgets('AppBar widget properties take priority over theme', (WidgetTester tester) async {
......@@ -103,13 +101,13 @@ void main() {
final RichText actionIconText = _getAppBarIconRichText(tester);
final DefaultTextStyle text = _getAppBarText(tester);
expect(SystemChrome.latestStyle.statusBarBrightness, brightness);
expect(SystemChrome.latestStyle!.statusBarBrightness, brightness);
expect(widget.color, color);
expect(widget.elevation, elevation);
expect(widget.shadowColor, shadowColor);
expect(iconTheme.data, iconThemeData);
expect(actionsIconTheme.data, actionsIconThemeData);
expect(actionIconText.text.style.color, actionsIconThemeData.color);
expect(actionIconText.text.style!.color, actionsIconThemeData.color);
expect(text.style, textTheme.bodyText2);
});
......@@ -132,7 +130,7 @@ void main() {
));
final RichText actionIconText = _getAppBarIconRichText(tester);
expect(actionIconText.text.style.color, color);
expect(actionIconText.text.style!.color, color);
});
testWidgets('AppBarTheme properties take priority over ThemeData properties', (WidgetTester tester) async {
......@@ -154,14 +152,14 @@ void main() {
final RichText actionIconText = _getAppBarIconRichText(tester);
final DefaultTextStyle text = _getAppBarText(tester);
expect(SystemChrome.latestStyle.statusBarBrightness, appBarTheme.brightness);
expect(SystemChrome.latestStyle!.statusBarBrightness, appBarTheme.brightness);
expect(widget.color, appBarTheme.color);
expect(widget.elevation, appBarTheme.elevation);
expect(widget.shadowColor, appBarTheme.shadowColor);
expect(iconTheme.data, appBarTheme.iconTheme);
expect(actionsIconTheme.data, appBarTheme.actionsIconTheme);
expect(actionIconText.text.style.color, appBarTheme.actionsIconTheme.color);
expect(text.style, appBarTheme.textTheme.bodyText2);
expect(actionIconText.text.style!.color, appBarTheme.actionsIconTheme!.color);
expect(text.style, appBarTheme.textTheme!.bodyText2);
});
testWidgets('ThemeData properties are used when no AppBarTheme is set', (WidgetTester tester) async {
......@@ -182,15 +180,15 @@ void main() {
final RichText actionIconText = _getAppBarIconRichText(tester);
final DefaultTextStyle text = _getAppBarText(tester);
expect(SystemChrome.latestStyle.statusBarBrightness, themeData.brightness);
expect(SystemChrome.latestStyle!.statusBarBrightness, themeData.brightness);
expect(widget.color, themeData.primaryColor);
expect(widget.elevation, 4.0);
expect(widget.shadowColor, Colors.black);
expect(iconTheme.data, themeData.primaryIconTheme);
expect(actionsIconTheme.data, themeData.primaryIconTheme);
expect(actionIconText.text.style.color, themeData.primaryIconTheme.color);
expect(actionIconText.text.style!.color, themeData.primaryIconTheme.color);
// Default value for ThemeData.typography is Typography.material2014()
expect(text.style, Typography.material2014().englishLike.bodyText2.merge(Typography.material2014().white.bodyText2).merge(themeData.primaryTextTheme.bodyText2));
expect(text.style, Typography.material2014().englishLike.bodyText2!.merge(Typography.material2014().white.bodyText2).merge(themeData.primaryTextTheme.bodyText2));
});
testWidgets('AppBar uses AppBarTheme.centerTitle when centerTitle is null', (WidgetTester tester) async {
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
......@@ -15,9 +13,9 @@ void main() {
primarySwatch: Colors.green,
),
home: const Placeholder(),
builder: (BuildContext context, Widget child) {
builder: (BuildContext context, Widget? child) {
log.add('build');
expect(Theme.of(context).primaryColor, Colors.green);
expect(Theme.of(context)!.primaryColor, Colors.green);
expect(Directionality.of(context), TextDirection.ltr);
expect(child, isA<Navigator>());
return const Placeholder();
......@@ -49,15 +47,15 @@ void main() {
home: Builder(
builder: (BuildContext context) {
log.add('build');
expect(Theme.of(context).primaryColor, Colors.yellow);
expect(Theme.of(context)!.primaryColor, Colors.yellow);
expect(Directionality.of(context), TextDirection.rtl);
return const Placeholder();
},
),
builder: (BuildContext context, Widget child) {
builder: (BuildContext context, Widget? child) {
return Directionality(
textDirection: TextDirection.rtl,
child: child,
child: child!,
);
},
),
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.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/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -132,7 +130,7 @@ void main() {
of: find.byType(BackButton),
matching: find.byType(RichText)
));
expect(iconText.text.style.color, Colors.blue);
expect(iconText.text.style!.color, Colors.blue);
});
testWidgets('BackButton semantics', (WidgetTester tester) async {
......@@ -182,7 +180,7 @@ void main() {
of: find.byType(CloseButton),
matching: find.byType(RichText)
));
expect(iconText.text.style.color, Colors.red);
expect(iconText.text.style!.color, Colors.red);
});
testWidgets('CloseButton onPressed overrides default pop behavior', (WidgetTester tester) async {
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -260,5 +258,5 @@ Container _getContainerFromBanner(WidgetTester tester) {
}
RenderParagraph _getTextRenderObjectFromDialog(WidgetTester tester, String text) {
return tester.element<StatelessElement>(find.descendant(of: find.byType(MaterialBanner), matching: find.text(text))).renderObject as RenderParagraph;
return tester.element<StatelessElement>(find.descendant(of: find.byType(MaterialBanner), matching: find.text(text))).renderObject! as RenderParagraph;
}
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -70,7 +68,7 @@ void main() {
final RenderParagraph content = _getTextRenderObjectFromDialog(tester, contentText);
expect(container.color, const Color(0xffffffff));
// Default value for ThemeData.typography is Typography.material2014()
expect(content.text.style, Typography.material2014().englishLike.bodyText2.merge(Typography.material2014().black.bodyText2));
expect(content.text.style, Typography.material2014().englishLike.bodyText2!.merge(Typography.material2014().black.bodyText2));
});
testWidgets('MaterialBanner uses values from MaterialBannerThemeData', (WidgetTester tester) async {
......@@ -185,7 +183,7 @@ Finder _containerFinder() {
}
RenderParagraph _getTextRenderObjectFromDialog(WidgetTester tester, String text) {
return tester.element<StatelessElement>(_textFinder(text)).renderObject as RenderParagraph;
return tester.element<StatelessElement>(_textFinder(text)).renderObject! as RenderParagraph;
}
Finder _textFinder(String text) {
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
......@@ -90,7 +88,7 @@ void main() {
home: Builder(
builder: (BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(bottomAppBarColor: const Color(0xffffff00)),
data: Theme.of(context)!.copyWith(bottomAppBarColor: const Color(0xffffff00)),
child: const Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: null,
......@@ -115,7 +113,7 @@ void main() {
home: Builder(
builder: (BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(bottomAppBarColor: const Color(0xffffff00)),
data: Theme.of(context)!.copyWith(bottomAppBarColor: const Color(0xffffff00)),
child: const Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: null,
......@@ -392,19 +390,19 @@ void main() {
class ClipCachePainter extends CustomPainter {
ClipCachePainter(this.context);
Path value;
late Path value;
BuildContext context;
@override
void paint(Canvas canvas, Size size) {
final RenderPhysicalShape physicalShape = findPhysicalShapeChild(context);
value = physicalShape.clipper.getClip(size);
final RenderPhysicalShape physicalShape = findPhysicalShapeChild(context)!;
value = physicalShape.clipper!.getClip(size);
}
RenderPhysicalShape findPhysicalShapeChild(BuildContext context) {
RenderPhysicalShape result;
RenderPhysicalShape? findPhysicalShapeChild(BuildContext context) {
RenderPhysicalShape? result;
context.visitChildElements((Element e) {
final RenderObject renderObject = e.findRenderObject();
final RenderObject renderObject = e.findRenderObject()!;
if (renderObject.runtimeType == RenderPhysicalShape) {
assert(result == null);
result = renderObject as RenderPhysicalShape;
......@@ -422,7 +420,7 @@ class ClipCachePainter extends CustomPainter {
}
class ShapeListener extends StatefulWidget {
const ShapeListener(this.child, { Key key }) : super(key: key);
const ShapeListener(this.child, { Key? key }) : super(key: key);
final Widget child;
......@@ -440,7 +438,7 @@ class ShapeListenerState extends State<ShapeListener> {
);
}
ClipCachePainter cache;
late ClipCachePainter cache;
@override
void didChangeDependencies() {
......@@ -454,7 +452,7 @@ class RectangularNotch extends NotchedShape {
const RectangularNotch();
@override
Path getOuterPath(Rect host, Rect guest) {
Path getOuterPath(Rect host, Rect? guest) {
if (guest == null)
return Path()..addRect(host);
return Path()
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -139,14 +137,14 @@ void main() {
),
);
final TextStyle selectedFontStyle = tester.renderObject<RenderParagraph>(find.text('AC')).text.style;
final TextStyle selectedFontStyle = tester.renderObject<RenderParagraph>(find.text('AC')).text.style!;
final TextStyle selectedIcon = _iconStyle(tester, Icons.ac_unit);
final TextStyle unselectedIcon = _iconStyle(tester, Icons.access_alarm);
expect(selectedFontStyle.fontSize, selectedFontStyle.fontSize);
// Unselected label has a font size of 22 but is scaled down to be font size 21.
expect(
tester.firstWidget<Transform>(find.ancestor(of: find.text('Alarm'), matching: find.byType(Transform))).transform,
equals(Matrix4.diagonal3(Vector3.all(unselectedTextStyle.fontSize / selectedTextStyle.fontSize))),
equals(Matrix4.diagonal3(Vector3.all(unselectedTextStyle.fontSize! / selectedTextStyle.fontSize!))),
);
expect(selectedIcon.color, equals(selectedItemColor));
expect(selectedIcon.fontSize, equals(selectedIconTheme.size));
......@@ -232,14 +230,14 @@ void main() {
),
);
final TextStyle selectedFontStyle = tester.renderObject<RenderParagraph>(find.text('AC')).text.style;
final TextStyle selectedFontStyle = tester.renderObject<RenderParagraph>(find.text('AC')).text.style!;
final TextStyle selectedIcon = _iconStyle(tester, Icons.ac_unit);
final TextStyle unselectedIcon = _iconStyle(tester, Icons.access_alarm);
expect(selectedFontStyle.fontSize, selectedFontStyle.fontSize);
// Unselected label has a font size of 22 but is scaled down to be font size 21.
expect(
tester.firstWidget<Transform>(find.ancestor(of: find.text('Alarm'), matching: find.byType(Transform))).transform,
equals(Matrix4.diagonal3(Vector3.all(unselectedTextStyle.fontSize / selectedTextStyle.fontSize))),
equals(Matrix4.diagonal3(Vector3.all(unselectedTextStyle.fontSize! / selectedTextStyle.fontSize!))),
);
expect(selectedIcon.color, equals(selectedItemColor));
expect(selectedIcon.fontSize, equals(selectedIconTheme.size));
......@@ -266,7 +264,7 @@ TextStyle _iconStyle(WidgetTester tester, IconData icon) {
final RichText iconRichText = tester.widget<RichText>(
find.descendant(of: find.byIcon(icon), matching: find.byType(RichText)),
);
return iconRichText.text.style;
return iconRichText.text.style!;
}
Material _material(WidgetTester tester) {
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
......@@ -28,7 +26,7 @@ void main() {
}
testWidgets('Tapping on a modal BottomSheet should not dismiss it', (WidgetTester tester) async {
BuildContext savedContext;
late BuildContext savedContext;
await tester.pumpWidget(
MaterialApp(
......@@ -64,7 +62,7 @@ void main() {
});
testWidgets('Tapping outside a modal BottomSheet should dismiss it by default', (WidgetTester tester) async {
BuildContext savedContext;
late BuildContext savedContext;
await tester.pumpWidget(MaterialApp(
home: Builder(
......@@ -98,7 +96,7 @@ void main() {
});
testWidgets('Tapping outside a modal BottomSheet should dismiss it when isDismissible=true', (WidgetTester tester) async {
BuildContext savedContext;
late BuildContext savedContext;
await tester.pumpWidget(MaterialApp(
home: Builder(
......@@ -133,7 +131,7 @@ void main() {
});
testWidgets('Verify that the BottomSheet animates non-linearly', (WidgetTester tester) async {
BuildContext savedContext;
late BuildContext savedContext;
await tester.pumpWidget(MaterialApp(
home: Builder(
......@@ -165,7 +163,7 @@ void main() {
});
testWidgets('Tapping outside a modal BottomSheet should not dismiss it when isDismissible=false', (WidgetTester tester) async {
BuildContext savedContext;
late BuildContext savedContext;
await tester.pumpWidget(
MaterialApp(
......@@ -202,7 +200,7 @@ void main() {
});
testWidgets('Swiping down a modal BottomSheet should dismiss it by default', (WidgetTester tester) async {
BuildContext savedContext;
late BuildContext savedContext;
await tester.pumpWidget(MaterialApp(
home: Builder(
......@@ -237,7 +235,7 @@ void main() {
});
testWidgets('Swiping down a modal BottomSheet should not dismiss it when enableDrag is false', (WidgetTester tester) async {
BuildContext savedContext;
late BuildContext savedContext;
await tester.pumpWidget(MaterialApp(
home: Builder(
......@@ -273,7 +271,7 @@ void main() {
});
testWidgets('Swiping down a modal BottomSheet should dismiss it when enableDrag is true', (WidgetTester tester) async {
BuildContext savedContext;
late BuildContext savedContext;
await tester.pumpWidget(MaterialApp(
home: Builder(
......@@ -309,7 +307,7 @@ void main() {
});
testWidgets('Modal BottomSheet builder should only be called once', (WidgetTester tester) async {
BuildContext savedContext;
late BuildContext savedContext;
await tester.pumpWidget(MaterialApp(
home: Builder(
......@@ -354,7 +352,7 @@ void main() {
expect(showBottomSheetThenCalled, isFalse);
expect(find.text('BottomSheet'), findsNothing);
scaffoldKey.currentState.showBottomSheet<void>((BuildContext context) {
scaffoldKey.currentState!.showBottomSheet<void>((BuildContext context) {
return Container(
margin: const EdgeInsets.all(40.0),
child: const Text('BottomSheet'),
......@@ -408,7 +406,7 @@ void main() {
),
));
scaffoldKey.currentState.showBottomSheet<void>((BuildContext context) {
scaffoldKey.currentState!.showBottomSheet<void>((BuildContext context) {
return Container(
margin: const EdgeInsets.all(40.0),
child: const Text('BottomSheet'),
......@@ -428,8 +426,8 @@ void main() {
});
testWidgets('modal BottomSheet has no top MediaQuery', (WidgetTester tester) async {
BuildContext outerContext;
BuildContext innerContext;
late BuildContext outerContext;
late BuildContext innerContext;
await tester.pumpWidget(Localizations(
locale: const Locale('en', 'US'),
......@@ -469,11 +467,11 @@ void main() {
await tester.pump(const Duration(seconds: 1));
expect(
MediaQuery.of(outerContext).padding,
MediaQuery.of(outerContext)!.padding,
const EdgeInsets.all(50.0),
);
expect(
MediaQuery.of(innerContext).padding,
MediaQuery.of(innerContext)!.padding,
const EdgeInsets.only(left: 50.0, right: 50.0, bottom: 50.0),
);
});
......@@ -490,7 +488,7 @@ void main() {
));
showModalBottomSheet<void>(context: scaffoldKey.currentContext, builder: (BuildContext context) {
showModalBottomSheet<void>(context: scaffoldKey.currentContext!, builder: (BuildContext context) {
return Container(
child: const Text('BottomSheet'),
);
......@@ -545,7 +543,7 @@ void main() {
));
showModalBottomSheet<void>(
context: scaffoldKey.currentContext,
context: scaffoldKey.currentContext!,
backgroundColor: color,
barrierColor: barrierColor,
elevation: elevation,
......@@ -584,7 +582,7 @@ void main() {
showModalBottomSheet<void>(
context: scaffoldKey.currentContext,
context: scaffoldKey.currentContext!,
builder: (BuildContext context) {
return DraggableScrollableSheet(
expand: false,
......@@ -710,13 +708,13 @@ void main() {
),
));
RouteSettings retrievedRouteSettings;
late RouteSettings retrievedRouteSettings;
showModalBottomSheet<void>(
context: scaffoldKey.currentContext,
context: scaffoldKey.currentContext!,
routeSettings: routeSettings,
builder: (BuildContext context) {
retrievedRouteSettings = ModalRoute.of(context).settings;
retrievedRouteSettings = ModalRoute.of(context)!.settings;
return Container(
child: const Text('BottomSheet'),
);
......@@ -731,9 +729,9 @@ void main() {
}
class _TestPage extends StatelessWidget {
const _TestPage({Key key, this.useRootNavigator}) : super(key: key);
const _TestPage({Key? key, this.useRootNavigator}) : super(key: key);
final bool useRootNavigator;
final bool? useRootNavigator;
@override
Widget build(BuildContext context) {
......@@ -743,7 +741,7 @@ class _TestPage extends StatelessWidget {
onPressed: () {
if (useRootNavigator != null) {
showModalBottomSheet<void>(
useRootNavigator: useRootNavigator,
useRootNavigator: useRootNavigator!,
context: context,
builder: (_) => const Text('Modal bottom sheet'),
);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.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/material.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -243,7 +241,7 @@ void main() {
group('button properties override ButtonTheme', () {
testWidgets('default button properties override ButtonTheme properties', (WidgetTester tester) async {
BuildContext capturedContext;
late BuildContext capturedContext;
await tester.pumpWidget(
MaterialApp(
home: ButtonBar(
......@@ -266,7 +264,7 @@ void main() {
});
testWidgets('ButtonBarTheme button properties override defaults and ButtonTheme properties', (WidgetTester tester) async {
BuildContext capturedContext;
late BuildContext capturedContext;
await tester.pumpWidget(
MaterialApp(
home: ButtonBarTheme(
......@@ -299,7 +297,7 @@ void main() {
});
testWidgets('ButtonBar button properties override ButtonBarTheme, defaults and ButtonTheme properties', (WidgetTester tester) async {
BuildContext capturedContext;
late BuildContext capturedContext;
await tester.pumpWidget(
MaterialApp(
home: ButtonBarTheme(
......
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