Unverified Commit 4513e96a authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Migrate more material tests (#67591)

parent b79e3462
......@@ -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/gestures.dart';
import 'package:flutter/material.dart';
......@@ -11,11 +9,12 @@ import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/physics.dart';
import '../flutter_test_alternative.dart' show Fake;
import '../rendering/mock_canvas.dart';
import '../rendering/recording_canvas.dart';
import '../widgets/semantics_tester.dart';
Widget boilerplate({ Widget child, TextDirection textDirection = TextDirection.ltr }) {
Widget boilerplate({ Widget? child, TextDirection textDirection = TextDirection.ltr }) {
return Localizations(
locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[
......@@ -32,27 +31,27 @@ Widget boilerplate({ Widget child, TextDirection textDirection = TextDirection.l
}
class StateMarker extends StatefulWidget {
const StateMarker({ Key key, this.child }) : super(key: key);
const StateMarker({ Key? key, this.child }) : super(key: key);
final Widget child;
final Widget? child;
@override
StateMarkerState createState() => StateMarkerState();
}
class StateMarkerState extends State<StateMarker> {
String marker;
String? marker;
@override
Widget build(BuildContext context) {
if (widget.child != null)
return widget.child;
return widget.child!;
return Container();
}
}
class AlwaysKeepAliveWidget extends StatefulWidget {
const AlwaysKeepAliveWidget({ Key key}) : super(key: key);
const AlwaysKeepAliveWidget({ Key? key}) : super(key: key);
static String text = 'AlwaysKeepAlive';
@override
AlwaysKeepAliveState createState() => AlwaysKeepAliveState();
......@@ -75,7 +74,7 @@ class _NestedTabBarContainer extends StatelessWidget {
this.tabController,
});
final TabController tabController;
final TabController? tabController;
@override
Widget build(BuildContext context) {
......@@ -107,11 +106,11 @@ class _NestedTabBarContainer extends StatelessWidget {
}
Widget buildFrame({
Key tabBarKey,
List<String> tabs,
String value,
Key? tabBarKey,
required List<String> tabs,
required String value,
bool isScrollable = false,
Color indicatorColor,
Color? indicatorColor,
}) {
return boilerplate(
child: DefaultTabController(
......@@ -131,10 +130,10 @@ typedef TabControllerFrameBuilder = Widget Function(BuildContext context, TabCon
class TabControllerFrame extends StatefulWidget {
const TabControllerFrame({
Key key,
this.length,
Key? key,
required this.length,
this.initialIndex = 0,
this.builder,
required this.builder,
}) : super(key: key);
final int length;
......@@ -146,7 +145,7 @@ class TabControllerFrame extends StatefulWidget {
}
class TabControllerFrameState extends State<TabControllerFrame> with SingleTickerProviderStateMixin {
TabController _controller;
late TabController _controller;
@override
void initState() {
......@@ -170,7 +169,7 @@ class TabControllerFrameState extends State<TabControllerFrame> with SingleTicke
}
}
Widget buildLeftRightApp({ List<String> tabs, String value }) {
Widget buildLeftRightApp({ required List<String> tabs, required String value }) {
return MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: DefaultTabController(
......@@ -198,7 +197,7 @@ class TabIndicatorRecordingCanvas extends TestRecordingCanvas {
TabIndicatorRecordingCanvas(this.indicatorColor);
final Color indicatorColor;
Rect indicatorRect;
late Rect indicatorRect;
@override
void drawLine(Offset p1, Offset p2, Paint paint) {
......@@ -210,10 +209,10 @@ class TabIndicatorRecordingCanvas extends TestRecordingCanvas {
}
class TestScrollPhysics extends ScrollPhysics {
const TestScrollPhysics({ ScrollPhysics parent }) : super(parent: parent);
const TestScrollPhysics({ ScrollPhysics? parent }) : super(parent: parent);
@override
TestScrollPhysics applyTo(ScrollPhysics ancestor) {
TestScrollPhysics applyTo(ScrollPhysics? ancestor) {
return TestScrollPhysics(parent: buildParent(ancestor));
}
......@@ -255,7 +254,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(theme: ThemeData(fontFamily: 'Ahem'), home: const Center(child: Material(child: Tab(text: 'x')))),
);
expect(tester.renderObject<RenderParagraph>(find.byType(RichText)).text.style.fontFamily, 'Ahem');
expect(tester.renderObject<RenderParagraph>(find.byType(RichText)).text.style!.fontFamily, 'Ahem');
expect(tester.getSize(find.byType(Tab)), const Size(14.0, 46.0));
});
......@@ -263,7 +262,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(theme: ThemeData(fontFamily: 'Ahem'), home: const Center(child: Material(child: Tab(icon: SizedBox(width: 10.0, height: 10.0), text: 'x')))),
);
expect(tester.renderObject<RenderParagraph>(find.byType(RichText)).text.style.fontFamily, 'Ahem');
expect(tester.renderObject<RenderParagraph>(find.byType(RichText)).text.style!.fontFamily, 'Ahem');
expect(tester.getSize(find.byType(Tab)), const Size(14.0, 72.0));
});
......@@ -287,7 +286,7 @@ void main() {
),
),
);
expect(tester.renderObject<RenderParagraph>(find.byType(RichText)).text.style.fontFamily, 'Ahem');
expect(tester.renderObject<RenderParagraph>(find.byType(RichText)).text.style!.fontFamily, 'Ahem');
expect(tester.getSize(find.byType(Tab)), const Size(210.0, 72.0));
});
......@@ -295,7 +294,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(theme: ThemeData(fontFamily: 'Ahem'), home: const Center(child: Material(child: Tab(icon: SizedBox(width: 10.0, height: 10.0), child: Text('x'))))),
);
expect(tester.renderObject<RenderParagraph>(find.byType(RichText)).text.style.fontFamily, 'Ahem');
expect(tester.renderObject<RenderParagraph>(find.byType(RichText)).text.style!.fontFamily, 'Ahem');
expect(tester.getSize(find.byType(Tab)), const Size(14.0, 72.0));
});
......@@ -330,7 +329,7 @@ void main() {
expect(find.text('A'), findsOneWidget);
expect(find.text('B'), findsOneWidget);
expect(find.text('C'), findsOneWidget);
final TabController controller = DefaultTabController.of(tester.element(find.text('A')));
final TabController controller = DefaultTabController.of(tester.element(find.text('A')))!;
expect(controller, isNotNull);
expect(controller.index, 2);
expect(controller.previousIndex, 2);
......@@ -366,7 +365,7 @@ void main() {
expect(find.text('A'), findsOneWidget);
expect(find.text('B'), findsOneWidget);
expect(find.text('C'), findsOneWidget);
final TabController controller = DefaultTabController.of(tester.element(find.text('A')));
final TabController controller = DefaultTabController.of(tester.element(find.text('A')))!;
expect(controller.index, 2);
expect(controller.previousIndex, 2);
......@@ -387,7 +386,7 @@ void main() {
final List<String> tabs = <String>['AAAAAA', 'BBBBBB', 'CCCCCC', 'DDDDDD', 'EEEEEE', 'FFFFFF', 'GGGGGG', 'HHHHHH', 'IIIIII', 'JJJJJJ', 'KKKKKK', 'LLLLLL'];
const Key tabBarKey = Key('TabBar');
await tester.pumpWidget(buildFrame(tabs: tabs, value: 'AAAAAA', isScrollable: true, tabBarKey: tabBarKey));
final TabController controller = DefaultTabController.of(tester.element(find.text('AAAAAA')));
final TabController controller = DefaultTabController.of(tester.element(find.text('AAAAAA')))!;
expect(controller, isNotNull);
expect(controller.index, 0);
......@@ -407,7 +406,7 @@ void main() {
final List<String> tabs = <String>['AAAA', 'BBBB', 'CCCC', 'DDDD', 'EEEE', 'FFFF', 'GGGG', 'HHHH', 'IIII', 'JJJJ', 'KKKK', 'LLLL'];
const Key tabBarKey = Key('TabBar');
await tester.pumpWidget(buildFrame(tabs: tabs, value: 'AAAA', isScrollable: true, tabBarKey: tabBarKey));
final TabController controller = DefaultTabController.of(tester.element(find.text('AAAA')));
final TabController controller = DefaultTabController.of(tester.element(find.text('AAAA')))!;
expect(controller, isNotNull);
expect(controller.index, 0);
......@@ -447,7 +446,7 @@ void main() {
}
await tester.pumpWidget(builder());
final TabController controller = DefaultTabController.of(tester.element(find.text('AAAAAA')));
final TabController controller = DefaultTabController.of(tester.element(find.text('AAAAAA')))!;
TestGesture gesture = await tester.startGesture(tester.getCenter(find.text(tabs[0])));
await gesture.moveBy(const Offset(-600.0, 0.0));
......@@ -504,7 +503,7 @@ void main() {
expect(find.text('LEFT CHILD'), findsOneWidget);
expect(find.text('RIGHT CHILD'), findsNothing);
final TabController controller = DefaultTabController.of(tester.element(find.text('LEFT')));
final TabController controller = DefaultTabController.of(tester.element(find.text('LEFT')))!;
expect(controller.index, 0);
// Fling to the left, switch from the 'LEFT' tab to the 'RIGHT'
......@@ -533,7 +532,7 @@ void main() {
expect(find.text('LEFT CHILD'), findsOneWidget);
expect(find.text('RIGHT CHILD'), findsNothing);
final TabController controller = DefaultTabController.of(tester.element(find.text('LEFT')));
final TabController controller = DefaultTabController.of(tester.element(find.text('LEFT')))!;
expect(controller.index, 0);
final Offset flingStart = tester.getCenter(find.text('LEFT CHILD'));
......@@ -554,7 +553,7 @@ void main() {
expect(find.text('LEFT CHILD'), findsOneWidget);
expect(find.text('RIGHT CHILD'), findsNothing);
final TabController controller = DefaultTabController.of(tester.element(find.text('LEFT')));
final TabController controller = DefaultTabController.of(tester.element(find.text('LEFT')))!;
expect(controller.index, 0);
final Offset flingStart = tester.getCenter(find.text('LEFT CHILD'));
......@@ -577,7 +576,7 @@ void main() {
expect(find.text('LEFT CHILD'), findsOneWidget);
expect(find.text('RIGHT CHILD'), findsNothing);
final TabController controller = DefaultTabController.of(tester.element(find.text('LEFT')));
final TabController controller = DefaultTabController.of(tester.element(find.text('LEFT')))!;
expect(controller.index, 0);
final Offset flingStart = tester.getCenter(find.text('LEFT CHILD'));
......@@ -645,12 +644,12 @@ void main() {
final List<String> tabs = <String>['LEFT', 'RIGHT'];
await tester.pumpWidget(buildLeftRightApp(tabs: tabs, value: 'LEFT'));
final TabController controller = DefaultTabController.of(tester.element(find.text('LEFT')));
final TabController controller = DefaultTabController.of(tester.element(find.text('LEFT')))!;
expect(controller, isNotNull);
expect(controller.index, 0);
String value;
late String value;
controller.addListener(() {
value = tabs[controller.index];
});
......@@ -676,7 +675,7 @@ void main() {
testWidgets('Explicit TabController', (WidgetTester tester) async {
final List<String> tabs = <String>['LEFT', 'RIGHT'];
TabController tabController;
late TabController tabController;
Widget buildTabControllerFrame(BuildContext context, TabController controller) {
tabController = controller;
......@@ -714,8 +713,8 @@ void main() {
expect(tabController.index, 1);
expect(tabController.previousIndex, 1);
expect(tabController.indexIsChanging, false);
expect(tabController.animation.value, 1.0);
expect(tabController.animation.status, AnimationStatus.forward);
expect(tabController.animation!.value, 1.0);
expect(tabController.animation!.status, AnimationStatus.forward);
tabController.index = 0;
await tester.pump(const Duration(milliseconds: 500));
......@@ -735,7 +734,7 @@ void main() {
// https://github.com/flutter/flutter/pull/7387#pullrequestreview-15630946
final List<String> tabs = <String>['A', 'B', 'C'];
TabController tabController;
late TabController tabController;
Widget buildTabControllerFrame(BuildContext context, TabController controller) {
tabController = controller;
......@@ -766,8 +765,8 @@ void main() {
length: tabs.length,
));
tabController.animation.addListener(() {
if (tabController.animation.status == AnimationStatus.forward)
tabController.animation!.addListener(() {
if (tabController.animation!.status == AnimationStatus.forward)
tabController.index = 2;
expect(tabController.indexIsChanging, true);
});
......@@ -803,8 +802,8 @@ void main() {
length: 2,
);
Color firstColor;
Color secondColor;
late Color firstColor;
late Color secondColor;
await tester.pumpWidget(
boilerplate(
......@@ -815,13 +814,13 @@ void main() {
tabs: <Widget>[
Builder(
builder: (BuildContext context) {
firstColor = IconTheme.of(context).color;
firstColor = IconTheme.of(context).color!;
return const Text('First');
}
),
Builder(
builder: (BuildContext context) {
secondColor = IconTheme.of(context).color;
secondColor = IconTheme.of(context).color!;
return const Text('Second');
}
),
......@@ -1175,7 +1174,7 @@ void main() {
);
final TabBar tabBar = tester.widget(find.byType(TabBar));
final double position = tabBar.physics.applyPhysicsToUserOffset(null, 10);
final double position = tabBar.physics!.applyPhysicsToUserOffset(MockScrollMetrics(), 10);
expect(position, equals(20));
});
......@@ -1438,7 +1437,7 @@ void main() {
double tabTop = (tabBarHeight - indicatorWeight - 30.0) / 2.0;
double tabBottom = tabTop + 30.0;
Rect tabRect = Rect.fromLTRB(tabLeft, tabTop, tabRight, tabBottom);
expect(tester.getRect(find.byKey(tabs[0].key)), tabRect);
expect(tester.getRect(find.byKey(tabs[0].key!)), tabRect);
// Tab1 width = 140, height = 40
......@@ -1447,7 +1446,7 @@ void main() {
tabTop = (tabBarHeight - indicatorWeight - 40.0) / 2.0;
tabBottom = tabTop + 40.0;
tabRect = Rect.fromLTRB(tabLeft, tabTop, tabRight, tabBottom);
expect(tester.getRect(find.byKey(tabs[1].key)), tabRect);
expect(tester.getRect(find.byKey(tabs[1].key!)), tabRect);
// Tab2 width = 150, height = 50
......@@ -1456,7 +1455,7 @@ void main() {
tabTop = (tabBarHeight - indicatorWeight - 50.0) / 2.0;
tabBottom = tabTop + 50.0;
tabRect = Rect.fromLTRB(tabLeft, tabTop, tabRight, tabBottom);
expect(tester.getRect(find.byKey(tabs[2].key)), tabRect);
expect(tester.getRect(find.byKey(tabs[2].key!)), tabRect);
// Tab 0 selected, indicator padding resolves to left: 100.0
const double indicatorLeft = 100.0 + indicatorWeight / 2.0;
......@@ -1508,7 +1507,7 @@ void main() {
double tabTop = (tabBarHeight - indicatorWeight - 50.0) / 2.0;
double tabBottom = tabTop + 50.0;
Rect tabRect = Rect.fromLTRB(tabLeft, tabTop, tabRight, tabBottom);
expect(tester.getRect(find.byKey(tabs[2].key)), tabRect);
expect(tester.getRect(find.byKey(tabs[2].key!)), tabRect);
// Tab1 width = 140, height = 40
tabLeft = tabRight + kTabLabelPadding.right + kTabLabelPadding.left;
......@@ -1516,7 +1515,7 @@ void main() {
tabTop = (tabBarHeight - indicatorWeight - 40.0) / 2.0;
tabBottom = tabTop + 40.0;
tabRect = Rect.fromLTRB(tabLeft, tabTop, tabRight, tabBottom);
expect(tester.getRect(find.byKey(tabs[1].key)), tabRect);
expect(tester.getRect(find.byKey(tabs[1].key!)), tabRect);
// Tab0 width = 130, height = 30
tabLeft = tabRight + kTabLabelPadding.right + kTabLabelPadding.left;
......@@ -1524,7 +1523,7 @@ void main() {
tabTop = (tabBarHeight - indicatorWeight - 30.0) / 2.0;
tabBottom = tabTop + 30.0;
tabRect = Rect.fromLTRB(tabLeft, tabTop, tabRight, tabBottom);
expect(tester.getRect(find.byKey(tabs[0].key)), tabRect);
expect(tester.getRect(find.byKey(tabs[0].key!)), tabRect);
// Tab 0 selected, indicator padding resolves to right: 100.0
final double indicatorLeft = tabLeft - kTabLabelPadding.left + indicatorWeight / 2.0;
......@@ -1578,7 +1577,7 @@ void main() {
double tabTop = (tabBarHeight - indicatorWeight - 30.0) / 2.0;
double tabBottom = tabTop + 30.0;
Rect tabRect = Rect.fromLTRB(tabLeft, tabTop, tabRight, tabBottom);
expect(tester.getRect(find.byKey(tabs[0].key)), tabRect);
expect(tester.getRect(find.byKey(tabs[0].key!)), tabRect);
// Tab1 width = 140, height = 40
tabLeft = tabRight + labelPadding.right + labelPadding.left;
......@@ -1586,7 +1585,7 @@ void main() {
tabTop = (tabBarHeight - indicatorWeight - 40.0) / 2.0;
tabBottom = tabTop + 40.0;
tabRect = Rect.fromLTRB(tabLeft, tabTop, tabRight, tabBottom);
expect(tester.getRect(find.byKey(tabs[1].key)), tabRect);
expect(tester.getRect(find.byKey(tabs[1].key!)), tabRect);
// Tab2 width = 150, height = 50
tabLeft = tabRight + labelPadding.right + labelPadding.left;
......@@ -1594,7 +1593,7 @@ void main() {
tabTop = (tabBarHeight - indicatorWeight - 50.0) / 2.0;
tabBottom = tabTop + 50.0;
tabRect = Rect.fromLTRB(tabLeft, tabTop, tabRight, tabBottom);
expect(tester.getRect(find.byKey(tabs[2].key)), tabRect);
expect(tester.getRect(find.byKey(tabs[2].key!)), tabRect);
// Tab 0 selected, indicatorPadding == labelPadding
final double indicatorLeft = indicatorPadding.left + indicatorWeight / 2.0;
......@@ -2018,8 +2017,8 @@ void main() {
int tabIndex = -1;
Widget buildFrame({
TabController controller,
List<String> tabs,
required TabController controller,
required List<String> tabs,
}) {
return boilerplate(
child: Container(
......@@ -2123,7 +2122,7 @@ void main() {
await tester.pump();
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
// Test default cursor
await tester.pumpWidget(MaterialApp(home: DefaultTabController(
......@@ -2138,7 +2137,7 @@ void main() {
),
),
));
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
});
testWidgets('TabController changes', (WidgetTester tester) async {
......@@ -2330,7 +2329,7 @@ void main() {
];
final TabController controller = TabController(vsync: const TestVSync(), length: tabs.length);
Widget buildTestWidget({double width, double height}) {
Widget buildTestWidget({double? width, double? height}) {
return MaterialApp(
home: Center(
child: SizedBox(
......@@ -2398,7 +2397,7 @@ void main() {
),
);
}
TabController getController() => DefaultTabController.of(tester.element(find.text('A')));
TabController getController() => DefaultTabController.of(tester.element(find.text('A')))!;
await tester.pumpWidget(buildTabs(threeTabs));
await tester.tap(find.text('B'));
......@@ -2593,7 +2592,7 @@ void main() {
Tab(text: 'A'), Tab(text: 'B'), Tab(text: 'C')
];
const Color indicatorColor = Color(0xFFFF0000);
TabController tabController;
late TabController tabController;
Widget buildTabControllerFrame(BuildContext context, TabController controller) {
tabController = controller;
......@@ -2609,7 +2608,7 @@ void main() {
body: TabBarView(
controller: controller,
children: tabs.map((Tab tab) {
return Center(child: Text(tab.text));
return Center(child: Text(tab.text!));
}).toList(),
),
),
......@@ -2677,8 +2676,8 @@ void main() {
length: 2,
);
Color firstColor;
Color secondColor;
late Color firstColor;
late Color secondColor;
await tester.pumpWidget(
boilerplate(
......@@ -2688,11 +2687,11 @@ void main() {
unselectedLabelColor: Colors.black,
tabs: <Widget>[
Builder(builder: (BuildContext context) {
firstColor = DefaultTextStyle.of(context).style.color;
firstColor = DefaultTextStyle.of(context).style.color!;
return const Text('First');
}),
Builder(builder: (BuildContext context) {
secondColor = DefaultTextStyle.of(context).style.color;
secondColor = DefaultTextStyle.of(context).style.color!;
return const Text('Second');
}),
],
......@@ -2764,18 +2763,18 @@ void main() {
pageController.jumpTo(300.0);
await tester.pump();
expect(tabController.animation.value, pageController.page);
expect(tabController.animation!.value, pageController.page);
// Touch TabBarView while ballistic scrolling is happening and
// check if tabController's animation value properly follows page value.
await tester.startGesture(tester.getCenter(find.byType(PageView)));
await tester.pump();
expect(tabController.animation.value, pageController.page);
expect(tabController.animation!.value, pageController.page);
});
}
class KeepAliveInk extends StatefulWidget {
const KeepAliveInk(this.title, {Key key}) : super(key: key);
const KeepAliveInk(this.title, {Key? key}) : super(key: key);
final String title;
@override
State<StatefulWidget> createState() {
......@@ -2825,3 +2824,5 @@ class TabBarDemo extends StatelessWidget {
);
}
}
class MockScrollMetrics extends Fake implements ScrollMetrics {}
......@@ -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';
import 'package:flutter/gestures.dart';
......@@ -43,10 +41,10 @@ void main() {
expect(material.elevation, 0.0);
expect(material.shadowColor, const Color(0xff000000));
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)));
expect(material.textStyle.color, colorScheme.primary);
expect(material.textStyle.fontFamily, 'Roboto');
expect(material.textStyle.fontSize, 14);
expect(material.textStyle.fontWeight, FontWeight.w500);
expect(material.textStyle!.color, colorScheme.primary);
expect(material.textStyle!.fontFamily, 'Roboto');
expect(material.textStyle!.fontSize, 14);
expect(material.textStyle!.fontWeight, FontWeight.w500);
expect(material.type, MaterialType.button);
final Offset center = tester.getCenter(find.byType(TextButton));
......@@ -68,10 +66,10 @@ void main() {
expect(material.elevation, 0.0);
expect(material.shadowColor, const Color(0xff000000));
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)));
expect(material.textStyle.color, colorScheme.primary);
expect(material.textStyle.fontFamily, 'Roboto');
expect(material.textStyle.fontSize, 14);
expect(material.textStyle.fontWeight, FontWeight.w500);
expect(material.textStyle!.color, colorScheme.primary);
expect(material.textStyle!.fontFamily, 'Roboto');
expect(material.textStyle!.fontSize, 14);
expect(material.textStyle!.fontWeight, FontWeight.w500);
expect(material.type, MaterialType.button);
// Disabled TextButton
......@@ -96,10 +94,10 @@ void main() {
expect(material.elevation, 0.0);
expect(material.shadowColor, const Color(0xff000000));
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)));
expect(material.textStyle.color, colorScheme.onSurface.withOpacity(0.38));
expect(material.textStyle.fontFamily, 'Roboto');
expect(material.textStyle.fontSize, 14);
expect(material.textStyle.fontWeight, FontWeight.w500);
expect(material.textStyle!.color, colorScheme.onSurface.withOpacity(0.38));
expect(material.textStyle!.fontFamily, 'Roboto');
expect(material.textStyle!.fontSize, 14);
expect(material.textStyle!.fontWeight, FontWeight.w500);
expect(material.type, MaterialType.button);
});
......@@ -161,9 +159,9 @@ void main() {
MaterialState.focused,
};
if (states.any(interactiveStates.contains)) {
return Colors.blue[900];
return Colors.blue[900]!;
}
return Colors.blue[800];
return Colors.blue[800]!;
}
await tester.pumpWidget(
......@@ -258,8 +256,8 @@ void main() {
),
);
Color textColor() {
return tester.renderObject<RenderParagraph>(find.text('TextButton')).text.style.color;
Color? textColor() {
return tester.renderObject<RenderParagraph>(find.text('TextButton')).text.style?.color;
}
// Default, not disabled.
......@@ -329,7 +327,7 @@ void main() {
),
);
Color iconColor() => _iconStyle(tester, Icons.add).color;
Color? iconColor() => _iconStyle(tester, Icons.add)?.color;
// Default, not disabled.
expect(iconColor(), equals(defaultColor));
......@@ -378,7 +376,7 @@ void main() {
testWidgets('Does TextButton work with hover', (WidgetTester tester) async {
const Color hoverColor = Color(0xff001122);
Color getOverlayColor(Set<MaterialState> states) {
Color? getOverlayColor(Set<MaterialState> states) {
return states.contains(MaterialState.hovered) ? hoverColor : null;
}
......@@ -388,7 +386,7 @@ void main() {
child: Material(
child: TextButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.resolveWith<Color>(getOverlayColor),
overlayColor: MaterialStateProperty.resolveWith<Color?>(getOverlayColor),
),
child: Container(),
onPressed: () { /* to make sure the button is enabled */ },
......@@ -411,7 +409,7 @@ void main() {
testWidgets('Does TextButton work with focus', (WidgetTester tester) async {
const Color focusColor = Color(0xff001122);
Color getOverlayColor(Set<MaterialState> states) {
Color? getOverlayColor(Set<MaterialState> states) {
return states.contains(MaterialState.focused) ? focusColor : null;
}
......@@ -421,7 +419,7 @@ void main() {
textDirection: TextDirection.ltr,
child: TextButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.resolveWith<Color>(getOverlayColor),
overlayColor: MaterialStateProperty.resolveWith<Color?>(getOverlayColor),
),
focusNode: focusNode,
onPressed: () { },
......@@ -430,7 +428,7 @@ void main() {
),
);
WidgetsBinding.instance.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
WidgetsBinding.instance!.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
focusNode.requestFocus();
await tester.pumpAndSettle();
......@@ -590,7 +588,7 @@ void main() {
bool wasPressed;
Finder textButton;
Widget buildFrame({ VoidCallback onPressed, VoidCallback onLongPress }) {
Widget buildFrame({ VoidCallback? onPressed, VoidCallback? onLongPress }) {
return Directionality(
textDirection: TextDirection.ltr,
child: TextButton(
......@@ -731,7 +729,7 @@ void main() {
const List<double> textScaleFactorOptions = <double>[0.5, 1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 4.0];
const List<TextDirection> textDirectionOptions = <TextDirection>[TextDirection.ltr, TextDirection.rtl];
const List<Widget> iconOptions = <Widget>[null, Icon(Icons.add, size: 18, key: iconKey)];
const List<Widget?> iconOptions = <Widget?>[null, Icon(Icons.add, size: 18, key: iconKey)];
// Expected values for each textScaleFactor.
final Map<double, double> paddingVertical = <double, double>{
......@@ -781,7 +779,7 @@ void main() {
}
/// Computes the padding between two [Rect]s, one inside the other.
EdgeInsets paddingBetween({ Rect parent, Rect child }) {
EdgeInsets paddingBetween({ required Rect parent, required Rect child }) {
assert (parent.intersect(child) == child);
return EdgeInsets.fromLTRB(
child.left - parent.left,
......@@ -793,7 +791,7 @@ void main() {
for (final double textScaleFactor in textScaleFactorOptions) {
for (final TextDirection textDirection in textDirectionOptions) {
for (final Widget icon in iconOptions) {
for (final Widget? icon in iconOptions) {
final String testName = 'TextButton'
', text scale $textScaleFactor'
'${icon != null ? ", with icon" : ""}'
......@@ -806,7 +804,7 @@ void main() {
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
data: MediaQuery.of(context)!.copyWith(
textScaleFactor: textScaleFactor,
),
child: Directionality(
......@@ -845,12 +843,12 @@ void main() {
// Compute expected padding, and check.
final double expectedPaddingTop = paddingVertical[textScaleFactor];
final double expectedPaddingBottom = paddingVertical[textScaleFactor];
final double expectedPaddingTop = paddingVertical[textScaleFactor]!;
final double expectedPaddingBottom = paddingVertical[textScaleFactor]!;
final double expectedPaddingStart = icon != null
? textPaddingWithIconHorizontal[textScaleFactor]
: textPaddingWithoutIconHorizontal[textScaleFactor];
? textPaddingWithIconHorizontal[textScaleFactor]!
: textPaddingWithoutIconHorizontal[textScaleFactor]!;
final double expectedPaddingEnd = expectedPaddingStart;
final EdgeInsets expectedPadding = EdgeInsetsDirectional.fromSTEB(
......@@ -867,9 +865,9 @@ void main() {
final RenderBox labelRenderBox = tester.renderObject<RenderBox>(find.byKey(labelKey));
final Rect labelBounds = globalBounds(labelRenderBox);
final RenderBox iconRenderBox = icon == null ? null : tester.renderObject<RenderBox>(find.byKey(iconKey));
final Rect iconBounds = icon == null ? null : globalBounds(iconRenderBox);
final Rect childBounds = icon == null ? labelBounds : labelBounds.expandToInclude(iconBounds);
final RenderBox? iconRenderBox = icon == null ? null : tester.renderObject<RenderBox>(find.byKey(iconKey));
final Rect? iconBounds = icon == null ? null : globalBounds(iconRenderBox!);
final Rect childBounds = icon == null ? labelBounds : labelBounds.expandToInclude(iconBounds!);
// We measure the `InkResponse` descendant of the button
// element, because the button has a larger `RenderBox`
......@@ -918,8 +916,8 @@ void main() {
// Check the gap between the icon and the label
if (icon != null) {
final double gapWidth = textDirection == TextDirection.ltr
? labelBounds.left - iconBounds.right
: iconBounds.left - labelBounds.right;
? labelBounds.left - iconBounds!.right
: iconBounds!.left - labelBounds.right;
expect(gapWidth, paddingWithIconGap[textScaleFactor]);
}
......@@ -948,7 +946,7 @@ void main() {
home: Builder(
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
data: MediaQuery.of(context)!.copyWith(
textScaleFactor: 2,
),
child: Scaffold(
......@@ -978,7 +976,7 @@ void main() {
}
TextStyle _iconStyle(WidgetTester tester, IconData icon) {
TextStyle? _iconStyle(WidgetTester tester, IconData icon) {
final RichText iconRichText = tester.widget<RichText>(
find.descendant(of: find.byIcon(icon), matching: find.byType(RichText)),
);
......
......@@ -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';
......@@ -37,10 +35,10 @@ void main() {
expect(material.elevation, 0.0);
expect(material.shadowColor, const Color(0xff000000));
expect(material.shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)));
expect(material.textStyle.color, colorScheme.primary);
expect(material.textStyle.fontFamily, 'Roboto');
expect(material.textStyle.fontSize, 14);
expect(material.textStyle.fontWeight, FontWeight.w500);
expect(material.textStyle!.color, colorScheme.primary);
expect(material.textStyle!.fontFamily, 'Roboto');
expect(material.textStyle!.fontSize, 14);
expect(material.textStyle!.fontWeight, FontWeight.w500);
});
group('[Theme, TextTheme, TextButton style overrides]', () {
......@@ -78,7 +76,7 @@ void main() {
enableFeedback: enableFeedback,
);
Widget buildFrame({ ButtonStyle buttonStyle, ButtonStyle themeStyle, ButtonStyle overallStyle }) {
Widget buildFrame({ ButtonStyle? buttonStyle, ButtonStyle? themeStyle, ButtonStyle? overallStyle }) {
final Widget child = Builder(
builder: (BuildContext context) {
return TextButton(
......@@ -123,15 +121,15 @@ void main() {
void checkButton(WidgetTester tester) {
final Material material = tester.widget<Material>(findMaterial);
final InkWell inkWell = tester.widget<InkWell>(findInkWell);
expect(material.textStyle.color, primaryColor);
expect(material.textStyle.fontSize, 12);
expect(material.textStyle!.color, primaryColor);
expect(material.textStyle!.fontSize, 12);
expect(material.color, backgroundColor);
expect(material.shadowColor, shadowColor);
expect(material.elevation, elevation);
expect(MaterialStateProperty.resolveAs<MouseCursor>(inkWell.mouseCursor, enabled), enabledMouseCursor);
expect(MaterialStateProperty.resolveAs<MouseCursor>(inkWell.mouseCursor, disabled), disabledMouseCursor);
expect(inkWell.overlayColor.resolve(hovered), primaryColor.withOpacity(0.04));
expect(inkWell.overlayColor.resolve(focused), primaryColor.withOpacity(0.12));
expect(MaterialStateProperty.resolveAs<MouseCursor?>(inkWell.mouseCursor, enabled), enabledMouseCursor);
expect(MaterialStateProperty.resolveAs<MouseCursor?>(inkWell.mouseCursor, disabled), disabledMouseCursor);
expect(inkWell.overlayColor!.resolve(hovered), primaryColor.withOpacity(0.04));
expect(inkWell.overlayColor!.resolve(focused), primaryColor.withOpacity(0.12));
expect(inkWell.enableFeedback, enableFeedback);
expect(material.borderRadius, null);
expect(material.shape, shape);
......@@ -183,7 +181,7 @@ void main() {
const Color shadowColor = Color(0xff000001);
const Color overiddenColor = Color(0xff000002);
Widget buildFrame({ Color overallShadowColor, Color themeShadowColor, Color shadowColor }) {
Widget buildFrame({ Color? overallShadowColor, Color? themeShadowColor, Color? shadowColor }) {
return MaterialApp(
theme: ThemeData.from(colorScheme: colorScheme).copyWith(
shadowColor: overallShadowColor,
......
......@@ -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';
......@@ -40,7 +38,7 @@ void main() {
expect(tester.testTextInput.isVisible, isFalse);
Navigator.of(tester.element(find.text('Dialog'))).pop();
Navigator.of(tester.element(find.text('Dialog')))!.pop();
await tester.pump();
expect(focusNode.hasPrimaryFocus, isTrue);
......@@ -177,7 +175,7 @@ void main() {
testWidgets('Focus keep-alive works with GlobalKey reparenting', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
Widget makeTest(String prefix) {
Widget makeTest(String? prefix) {
return MaterialApp(
home: Material(
child: ListView(
......
......@@ -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';
......
......@@ -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';
......@@ -74,7 +72,7 @@ Future<void> restoreAndVerify(WidgetTester tester) async {
}
class TestWidget extends StatefulWidget {
const TestWidget({Key key, this.useExternal = false}) : super(key: key);
const TestWidget({Key? key, this.useExternal = false}) : super(key: key);
final bool useExternal;
......@@ -89,7 +87,7 @@ class TestWidgetState extends State<TestWidget> with RestorationMixin {
String get restorationId => 'widget';
@override
void restoreState(RestorationBucket oldBucket, bool initialRestore) {
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
registerForRestoration(controller, 'controller');
}
......
......@@ -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/gestures.dart' show kPressTimeout;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -14,17 +12,17 @@ bool cancelCalled = false;
class TestInkSplash extends InkSplash {
TestInkSplash({
MaterialInkController controller,
RenderBox referenceBox,
Offset position,
Color color,
required MaterialInkController controller,
required RenderBox referenceBox,
Offset? position,
required Color color,
bool containedInkWell = false,
RectCallback rectCallback,
BorderRadius borderRadius,
ShapeBorder customBorder,
double radius,
VoidCallback onRemoved,
TextDirection textDirection,
RectCallback? rectCallback,
BorderRadius? borderRadius,
ShapeBorder? customBorder,
double? radius,
VoidCallback? onRemoved,
required TextDirection textDirection,
}) : super(
controller: controller,
referenceBox: referenceBox,
......@@ -57,17 +55,17 @@ class TestInkSplashFactory extends InteractiveInkFeatureFactory {
@override
InteractiveInkFeature create({
MaterialInkController controller,
RenderBox referenceBox,
Offset position,
Color color,
required MaterialInkController controller,
required RenderBox referenceBox,
Offset? position,
required Color color,
bool containedInkWell = false,
RectCallback rectCallback,
BorderRadius borderRadius,
ShapeBorder customBorder,
double radius,
VoidCallback onRemoved,
TextDirection textDirection,
RectCallback? rectCallback,
BorderRadius? borderRadius,
ShapeBorder? customBorder,
double? radius,
VoidCallback? onRemoved,
required TextDirection textDirection,
}) {
return TestInkSplash(
controller: controller,
......
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