Unverified Commit 1fc43d93 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

add key to constructors of public widgets (#47884)

* add key to constructors of public widgets

* fix a test

* fix a test
parent 2ae58321
...@@ -265,12 +265,14 @@ class CupertinoActionSheetAction extends StatelessWidget { ...@@ -265,12 +265,14 @@ class CupertinoActionSheetAction extends StatelessWidget {
/// ///
/// The [child] and [onPressed] arguments must not be null. /// The [child] and [onPressed] arguments must not be null.
const CupertinoActionSheetAction({ const CupertinoActionSheetAction({
Key key,
@required this.onPressed, @required this.onPressed,
this.isDefaultAction = false, this.isDefaultAction = false,
this.isDestructiveAction = false, this.isDestructiveAction = false,
@required this.child, @required this.child,
}) : assert(child != null), }) : assert(child != null),
assert(onPressed != null); assert(onPressed != null),
super(key: key);
/// The callback that is called when the button is tapped. /// The callback that is called when the button is tapped.
/// ///
......
...@@ -230,6 +230,7 @@ class CupertinoDatePicker extends StatefulWidget { ...@@ -230,6 +230,7 @@ class CupertinoDatePicker extends StatefulWidget {
/// ///
/// [use24hFormat] decides whether 24 hour format is used. Defaults to false. /// [use24hFormat] decides whether 24 hour format is used. Defaults to false.
CupertinoDatePicker({ CupertinoDatePicker({
Key key,
this.mode = CupertinoDatePickerMode.dateAndTime, this.mode = CupertinoDatePickerMode.dateAndTime,
@required this.onDateTimeChanged, @required this.onDateTimeChanged,
DateTime initialDateTime, DateTime initialDateTime,
...@@ -247,7 +248,8 @@ class CupertinoDatePicker extends StatefulWidget { ...@@ -247,7 +248,8 @@ class CupertinoDatePicker extends StatefulWidget {
assert( assert(
minuteInterval > 0 && 60 % minuteInterval == 0, minuteInterval > 0 && 60 % minuteInterval == 0,
'minute interval is not a positive integer factor of 60', 'minute interval is not a positive integer factor of 60',
) { ),
super(key: key) {
assert(this.initialDateTime != null); assert(this.initialDateTime != null);
assert( assert(
mode != CupertinoDatePickerMode.dateAndTime || minimumDate == null || !this.initialDateTime.isBefore(minimumDate), mode != CupertinoDatePickerMode.dateAndTime || minimumDate == null || !this.initialDateTime.isBefore(minimumDate),
......
...@@ -1270,11 +1270,13 @@ class CupertinoNavigationBarBackButton extends StatelessWidget { ...@@ -1270,11 +1270,13 @@ class CupertinoNavigationBarBackButton extends StatelessWidget {
/// ///
/// The [color] parameter must not be null. /// The [color] parameter must not be null.
const CupertinoNavigationBarBackButton({ const CupertinoNavigationBarBackButton({
Key key,
this.color, this.color,
this.previousPageTitle, this.previousPageTitle,
this.onPressed, this.onPressed,
}) : _backChevron = null, }) : _backChevron = null,
_backLabel = null; _backLabel = null,
super(key: key);
// Allow the back chevron and label to be separately created (and keyed) // Allow the back chevron and label to be separately created (and keyed)
// because they animate separately during page transitions. // because they animate separately during page transitions.
......
...@@ -200,7 +200,7 @@ class _CupertinoPageScaffoldState extends State<CupertinoPageScaffold> { ...@@ -200,7 +200,7 @@ class _CupertinoPageScaffoldState extends State<CupertinoPageScaffold> {
/// ///
/// Used by [CupertinoPageScaffold] to either shift away fully obstructed content /// Used by [CupertinoPageScaffold] to either shift away fully obstructed content
/// or provide a padding guide to partially obstructed content. /// or provide a padding guide to partially obstructed content.
abstract class ObstructingPreferredSizeWidget extends PreferredSizeWidget { abstract class ObstructingPreferredSizeWidget implements PreferredSizeWidget {
/// If true, this widget fully obstructs widgets behind it by the specified /// If true, this widget fully obstructs widgets behind it by the specified
/// size. /// size.
/// ///
......
...@@ -58,6 +58,7 @@ class ReorderableListView extends StatefulWidget { ...@@ -58,6 +58,7 @@ class ReorderableListView extends StatefulWidget {
/// Creates a reorderable list. /// Creates a reorderable list.
ReorderableListView({ ReorderableListView({
Key key,
this.header, this.header,
@required this.children, @required this.children,
@required this.onReorder, @required this.onReorder,
...@@ -70,7 +71,8 @@ class ReorderableListView extends StatefulWidget { ...@@ -70,7 +71,8 @@ class ReorderableListView extends StatefulWidget {
assert( assert(
children.every((Widget w) => w.key != null), children.every((Widget w) => w.key != null),
'All children of this widget must have a key.', 'All children of this widget must have a key.',
); ),
super(key: key);
/// A non-reorderable header widget to show before the list. /// A non-reorderable header widget to show before the list.
/// ///
......
...@@ -922,12 +922,14 @@ class PlatformViewSurface extends LeafRenderObjectWidget { ...@@ -922,12 +922,14 @@ class PlatformViewSurface extends LeafRenderObjectWidget {
/// ///
/// The [controller] must not be null. /// The [controller] must not be null.
const PlatformViewSurface({ const PlatformViewSurface({
Key key,
@required this.controller, @required this.controller,
@required this.hitTestBehavior, @required this.hitTestBehavior,
@required this.gestureRecognizers, @required this.gestureRecognizers,
}) : assert(controller != null), }) : assert(controller != null),
assert(hitTestBehavior != null), assert(hitTestBehavior != null),
assert(gestureRecognizers != null); assert(gestureRecognizers != null),
super(key: key);
/// The controller for the platform view integrated by this [PlatformViewSurface]. /// The controller for the platform view integrated by this [PlatformViewSurface].
/// ///
......
...@@ -58,13 +58,14 @@ class DefaultTextStyle extends InheritedTheme { ...@@ -58,13 +58,14 @@ class DefaultTextStyle extends InheritedTheme {
/// ///
/// This constructor creates a [DefaultTextStyle] that lacks a [child], which /// This constructor creates a [DefaultTextStyle] that lacks a [child], which
/// means the constructed value cannot be incorporated into the tree. /// means the constructed value cannot be incorporated into the tree.
const DefaultTextStyle.fallback() const DefaultTextStyle.fallback({ Key key })
: style = const TextStyle(), : style = const TextStyle(),
textAlign = null, textAlign = null,
softWrap = true, softWrap = true,
maxLines = null, maxLines = null,
overflow = TextOverflow.clip, overflow = TextOverflow.clip,
textWidthBasis = TextWidthBasis.parent; textWidthBasis = TextWidthBasis.parent,
super(key: key, child: null);
/// Creates a default text style that overrides the text styles in scope at /// Creates a default text style that overrides the text styles in scope at
/// this point in the widget tree. /// this point in the widget tree.
......
...@@ -115,11 +115,13 @@ class ValueListenableBuilder<T> extends StatefulWidget { ...@@ -115,11 +115,13 @@ class ValueListenableBuilder<T> extends StatefulWidget {
/// The [child] is optional but is good practice to use if part of the widget /// The [child] is optional but is good practice to use if part of the widget
/// subtree does not depend on the value of the [valueListenable]. /// subtree does not depend on the value of the [valueListenable].
const ValueListenableBuilder({ const ValueListenableBuilder({
Key key,
@required this.valueListenable, @required this.valueListenable,
@required this.builder, @required this.builder,
this.child, this.child,
}) : assert(valueListenable != null), }) : assert(valueListenable != null),
assert(builder != null); assert(builder != null),
super(key: key);
/// The [ValueListenable] whose value you depend on in order to build. /// The [ValueListenable] whose value you depend on in order to build.
/// ///
......
...@@ -419,7 +419,7 @@ class ClipCachePainter extends CustomPainter { ...@@ -419,7 +419,7 @@ class ClipCachePainter extends CustomPainter {
} }
class ShapeListener extends StatefulWidget { class ShapeListener extends StatefulWidget {
const ShapeListener(this.child); const ShapeListener(this.child, { Key key }) : super(key: key);
final Widget child; final Widget child;
......
...@@ -107,10 +107,17 @@ class _TestAppState extends State<TestApp> { ...@@ -107,10 +107,17 @@ class _TestAppState extends State<TestApp> {
} }
class TestApp extends StatefulWidget { class TestApp extends StatefulWidget {
const TestApp({ this.textDirection, this.child, this.mediaSize }); const TestApp({
Key key,
this.textDirection,
this.child,
this.mediaSize,
}) : super(key: key);
final TextDirection textDirection; final TextDirection textDirection;
final Widget child; final Widget child;
final Size mediaSize; final Size mediaSize;
@override @override
_TestAppState createState() => _TestAppState(); _TestAppState createState() => _TestAppState();
} }
......
...@@ -93,10 +93,17 @@ Widget buildFrame({ ...@@ -93,10 +93,17 @@ Widget buildFrame({
} }
class TestApp extends StatefulWidget { class TestApp extends StatefulWidget {
const TestApp({ this.textDirection, this.child, this.mediaSize }); const TestApp({
Key key,
this.textDirection,
this.child,
this.mediaSize,
}) : super(key: key);
final TextDirection textDirection; final TextDirection textDirection;
final Widget child; final Widget child;
final Size mediaSize; final Size mediaSize;
@override @override
_TestAppState createState() => _TestAppState(); _TestAppState createState() => _TestAppState();
} }
......
...@@ -55,7 +55,7 @@ class _SimpleExpansionPanelListTestWidgetState extends State<SimpleExpansionPane ...@@ -55,7 +55,7 @@ class _SimpleExpansionPanelListTestWidgetState extends State<SimpleExpansionPane
} }
class ExpansionPanelListSemanticsTest extends StatefulWidget { class ExpansionPanelListSemanticsTest extends StatefulWidget {
const ExpansionPanelListSemanticsTest({this.headerKey}); const ExpansionPanelListSemanticsTest({ Key key, this.headerKey }) : super(key: key);
final Key headerKey; final Key headerKey;
......
...@@ -201,11 +201,11 @@ void main () { ...@@ -201,11 +201,11 @@ void main () {
} }
class TestWidget extends StatelessWidget { class TestWidget extends StatelessWidget {
const TestWidget({ const TestWidget({
Key key,
this.tapHandler = nullHandler, this.tapHandler = nullHandler,
this.longPressHandler = nullHandler, this.longPressHandler = nullHandler,
}); }) : super(key: key);
final HandlerCreator tapHandler; final HandlerCreator tapHandler;
final HandlerCreator longPressHandler; final HandlerCreator longPressHandler;
......
...@@ -11,6 +11,7 @@ import '../rendering/mock_canvas.dart'; ...@@ -11,6 +11,7 @@ import '../rendering/mock_canvas.dart';
import '../widgets/test_border.dart' show TestBorder; import '../widgets/test_border.dart' show TestBorder;
class NotifyMaterial extends StatelessWidget { class NotifyMaterial extends StatelessWidget {
const NotifyMaterial({ Key key }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
LayoutChangedNotification().dispatch(context); LayoutChangedNotification().dispatch(context);
...@@ -101,7 +102,7 @@ void main() { ...@@ -101,7 +102,7 @@ void main() {
testWidgets('LayoutChangedNotification test', (WidgetTester tester) async { testWidgets('LayoutChangedNotification test', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
Material( const Material(
child: NotifyMaterial(), child: NotifyMaterial(),
), ),
); );
......
...@@ -1194,9 +1194,15 @@ void main() { ...@@ -1194,9 +1194,15 @@ void main() {
} }
class TestApp extends StatefulWidget { class TestApp extends StatefulWidget {
const TestApp({ this.textDirection, this.child }); const TestApp({
Key key,
this.textDirection,
this.child,
}) : super(key: key);
final TextDirection textDirection; final TextDirection textDirection;
final Widget child; final Widget child;
@override @override
_TestAppState createState() => _TestAppState(); _TestAppState createState() => _TestAppState();
} }
......
...@@ -644,11 +644,12 @@ void main() { ...@@ -644,11 +644,12 @@ void main() {
class TestHomePage extends StatelessWidget { class TestHomePage extends StatelessWidget {
const TestHomePage({ const TestHomePage({
Key key,
this.results, this.results,
this.delegate, this.delegate,
this.passInInitialQuery = false, this.passInInitialQuery = false,
this.initialQuery, this.initialQuery,
}); }) : super(key: key);
final List<String> results; final List<String> results;
final SearchDelegate<String> delegate; final SearchDelegate<String> delegate;
......
...@@ -24,6 +24,8 @@ class MySliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate { ...@@ -24,6 +24,8 @@ class MySliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate {
} }
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
const MyHomePage({ Key key }) : super(key: key);
@override @override
_MyHomePageState createState() => _MyHomePageState(); _MyHomePageState createState() => _MyHomePageState();
} }
...@@ -73,7 +75,7 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin { ...@@ -73,7 +75,7 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
void main() { void main() {
testWidgets('Tabbed CustomScrollViews, warp from tab 1 to 3', (WidgetTester tester) async { testWidgets('Tabbed CustomScrollViews, warp from tab 1 to 3', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: MyHomePage())); await tester.pumpWidget(const MaterialApp(home: MyHomePage()));
// should not crash. // should not crash.
await tester.tap(find.text('Tab 2')); await tester.tap(find.text('Tab 2'));
......
...@@ -127,7 +127,12 @@ Widget buildFrame({ ...@@ -127,7 +127,12 @@ Widget buildFrame({
typedef TabControllerFrameBuilder = Widget Function(BuildContext context, TabController controller); typedef TabControllerFrameBuilder = Widget Function(BuildContext context, TabController controller);
class TabControllerFrame extends StatefulWidget { class TabControllerFrame extends StatefulWidget {
const TabControllerFrame({ this.length, this.initialIndex = 0, this.builder }); const TabControllerFrame({
Key key,
this.length,
this.initialIndex = 0,
this.builder,
}) : super(key: key);
final int length; final int length;
final int initialIndex; final int initialIndex;
......
...@@ -650,7 +650,7 @@ void main() { ...@@ -650,7 +650,7 @@ void main() {
int testBuildCalled; int testBuildCalled;
class Test extends StatefulWidget { class Test extends StatefulWidget {
const Test(); const Test({ Key key }) : super(key: key);
@override @override
_TestState createState() => _TestState(); _TestState createState() => _TestState();
......
...@@ -8,6 +8,7 @@ import 'package:flutter/material.dart'; ...@@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
bool willPopValue = false; bool willPopValue = false;
class SamplePage extends StatefulWidget { class SamplePage extends StatefulWidget {
const SamplePage({ Key key }) : super(key: key);
@override @override
SamplePageState createState() => SamplePageState(); SamplePageState createState() => SamplePageState();
} }
...@@ -86,7 +87,7 @@ void main() { ...@@ -86,7 +87,7 @@ void main() {
onPressed: () { onPressed: () {
showDialog<void>( showDialog<void>(
context: context, context: context,
builder: (BuildContext context) => SamplePage(), builder: (BuildContext context) => const SamplePage(),
); );
}, },
), ),
......
...@@ -94,7 +94,7 @@ void main() { ...@@ -94,7 +94,7 @@ void main() {
} }
class BaselineDetector extends LeafRenderObjectWidget { class BaselineDetector extends LeafRenderObjectWidget {
const BaselineDetector(this.callback); const BaselineDetector(this.callback, { Key key }) : super(key: key);
final VoidCallback callback; final VoidCallback callback;
......
...@@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart'; ...@@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart';
import 'test_widgets.dart'; import 'test_widgets.dart';
class ProbeWidget extends StatefulWidget { class ProbeWidget extends StatefulWidget {
const ProbeWidget({ Key key }) : super(key: key);
@override @override
ProbeWidgetState createState() => ProbeWidgetState(); ProbeWidgetState createState() => ProbeWidgetState();
} }
...@@ -36,7 +37,7 @@ class ProbeWidgetState extends State<ProbeWidget> { ...@@ -36,7 +37,7 @@ class ProbeWidgetState extends State<ProbeWidget> {
} }
class BadWidget extends StatelessWidget { class BadWidget extends StatelessWidget {
const BadWidget(this.parentState); const BadWidget(this.parentState, { Key key }) : super(key: key);
final BadWidgetParentState parentState; final BadWidgetParentState parentState;
...@@ -48,6 +49,7 @@ class BadWidget extends StatelessWidget { ...@@ -48,6 +49,7 @@ class BadWidget extends StatelessWidget {
} }
class BadWidgetParent extends StatefulWidget { class BadWidgetParent extends StatefulWidget {
const BadWidgetParent({ Key key }) : super(key: key);
@override @override
BadWidgetParentState createState() => BadWidgetParentState(); BadWidgetParentState createState() => BadWidgetParentState();
} }
...@@ -67,6 +69,7 @@ class BadWidgetParentState extends State<BadWidgetParent> { ...@@ -67,6 +69,7 @@ class BadWidgetParentState extends State<BadWidgetParent> {
} }
class BadDisposeWidget extends StatefulWidget { class BadDisposeWidget extends StatefulWidget {
const BadDisposeWidget({ Key key }) : super(key: key);
@override @override
BadDisposeWidgetState createState() => BadDisposeWidgetState(); BadDisposeWidgetState createState() => BadDisposeWidgetState();
} }
...@@ -133,14 +136,14 @@ void main() { ...@@ -133,14 +136,14 @@ void main() {
testWidgets('Legal times for setState', (WidgetTester tester) async { testWidgets('Legal times for setState', (WidgetTester tester) async {
final GlobalKey flipKey = GlobalKey(); final GlobalKey flipKey = GlobalKey();
expect(ProbeWidgetState.buildCount, equals(0)); expect(ProbeWidgetState.buildCount, equals(0));
await tester.pumpWidget(ProbeWidget()); await tester.pumpWidget(const ProbeWidget(key: Key('a')));
expect(ProbeWidgetState.buildCount, equals(1)); expect(ProbeWidgetState.buildCount, equals(1));
await tester.pumpWidget(ProbeWidget()); await tester.pumpWidget(const ProbeWidget(key: Key('b')));
expect(ProbeWidgetState.buildCount, equals(2)); expect(ProbeWidgetState.buildCount, equals(2));
await tester.pumpWidget(FlipWidget( await tester.pumpWidget(FlipWidget(
key: flipKey, key: flipKey,
left: Container(), left: Container(),
right: ProbeWidget(), right: const ProbeWidget(key: Key('c')),
)); ));
expect(ProbeWidgetState.buildCount, equals(2)); expect(ProbeWidgetState.buildCount, equals(2));
final FlipWidgetState flipState1 = flipKey.currentState as FlipWidgetState; final FlipWidgetState flipState1 = flipKey.currentState as FlipWidgetState;
...@@ -156,13 +159,13 @@ void main() { ...@@ -156,13 +159,13 @@ void main() {
}); });
testWidgets('Setting parent state during build is forbidden', (WidgetTester tester) async { testWidgets('Setting parent state during build is forbidden', (WidgetTester tester) async {
await tester.pumpWidget(BadWidgetParent()); await tester.pumpWidget(const BadWidgetParent());
expect(tester.takeException(), isFlutterError); expect(tester.takeException(), isFlutterError);
await tester.pumpWidget(Container()); await tester.pumpWidget(Container());
}); });
testWidgets('Setting state during dispose is forbidden', (WidgetTester tester) async { testWidgets('Setting state during dispose is forbidden', (WidgetTester tester) async {
await tester.pumpWidget(BadDisposeWidget()); await tester.pumpWidget(const BadDisposeWidget());
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
await tester.pumpWidget(Container()); await tester.pumpWidget(Container());
expect(tester.takeException(), isNotNull); expect(tester.takeException(), isNotNull);
......
...@@ -208,7 +208,7 @@ Future<void> rollbackElement(WidgetTester tester, Finder finder, { @required Axi ...@@ -208,7 +208,7 @@ Future<void> rollbackElement(WidgetTester tester, Finder finder, { @required Axi
} }
class Test1215DismissibleWidget extends StatelessWidget { class Test1215DismissibleWidget extends StatelessWidget {
const Test1215DismissibleWidget(this.text); const Test1215DismissibleWidget(this.text, { Key key }) : super(key: key);
final String text; final String text;
......
...@@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart';
typedef TestCallback = void Function(BuildContext context); typedef TestCallback = void Function(BuildContext context);
class TestWidget extends StatefulWidget { class TestWidget extends StatefulWidget {
const TestWidget(this.callback); const TestWidget(this.callback, { Key key }) : super(key: key);
final TestCallback callback; final TestCallback callback;
......
...@@ -4153,11 +4153,13 @@ class MockTextSelectionControls extends Mock implements TextSelectionControls { ...@@ -4153,11 +4153,13 @@ class MockTextSelectionControls extends Mock implements TextSelectionControls {
class CustomStyleEditableText extends EditableText { class CustomStyleEditableText extends EditableText {
CustomStyleEditableText({ CustomStyleEditableText({
Key key,
TextEditingController controller, TextEditingController controller,
Color cursorColor, Color cursorColor,
FocusNode focusNode, FocusNode focusNode,
TextStyle style, TextStyle style,
}) : super( }) : super(
key: key,
controller: controller, controller: controller,
cursorColor: cursorColor, cursorColor: cursorColor,
backgroundCursorColor: Colors.grey, backgroundCursorColor: Colors.grey,
...@@ -4180,7 +4182,11 @@ class CustomStyleEditableTextState extends EditableTextState { ...@@ -4180,7 +4182,11 @@ class CustomStyleEditableTextState extends EditableTextState {
} }
class TransformedEditableText extends StatefulWidget { class TransformedEditableText extends StatefulWidget {
const TransformedEditableText({ this.offset, this.transformButtonKey }); const TransformedEditableText({
Key key,
this.offset,
this.transformButtonKey,
}) : super(key: key);
final Offset offset; final Offset offset;
final Key transformButtonKey; final Key transformButtonKey;
......
...@@ -644,7 +644,7 @@ void main() { ...@@ -644,7 +644,7 @@ void main() {
}); });
testWidgets('Element diagnostics with null child', (WidgetTester tester) async { testWidgets('Element diagnostics with null child', (WidgetTester tester) async {
await tester.pumpWidget(NullChildTest()); await tester.pumpWidget(const NullChildTest());
final NullChildElement test = tester.element<NullChildElement>(find.byType(NullChildTest)); final NullChildElement test = tester.element<NullChildElement>(find.byType(NullChildTest));
test.includeChild = true; test.includeChild = true;
expect( expect(
...@@ -713,6 +713,7 @@ void main() { ...@@ -713,6 +713,7 @@ void main() {
} }
class NullChildTest extends Widget { class NullChildTest extends Widget {
const NullChildTest({ Key key }) : super(key: key);
@override @override
Element createElement() => NullChildElement(this); Element createElement() => NullChildElement(this);
} }
......
...@@ -29,7 +29,7 @@ class StatefulLeafState extends State<StatefulLeaf> { ...@@ -29,7 +29,7 @@ class StatefulLeafState extends State<StatefulLeaf> {
} }
class KeyedWrapper extends StatelessWidget { class KeyedWrapper extends StatelessWidget {
const KeyedWrapper(this.key1, this.key2); const KeyedWrapper(this.key1, this.key2, { Key key }) : super(key: key);
final Key key1; final Key key1;
final GlobalKey key2; final GlobalKey key2;
......
...@@ -248,7 +248,12 @@ Widget wrap({Widget child}) { ...@@ -248,7 +248,12 @@ Widget wrap({Widget child}) {
} }
class TestAnimatedWidget extends StatefulWidget { class TestAnimatedWidget extends StatefulWidget {
const TestAnimatedWidget({this.callback, this.switchKey, this.state}); const TestAnimatedWidget({
Key key,
this.callback,
this.switchKey,
this.state,
}) : super(key: key);
@required @required
final VoidCallback callback; final VoidCallback callback;
@required @required
......
...@@ -66,9 +66,15 @@ class Trigger { ...@@ -66,9 +66,15 @@ class Trigger {
} }
class TriggerableWidget extends StatefulWidget { class TriggerableWidget extends StatefulWidget {
const TriggerableWidget({ this.trigger, this.counter }); const TriggerableWidget({
Key key,
this.trigger,
this.counter,
}) : super(key: key);
final Trigger trigger; final Trigger trigger;
final Counter counter; final Counter counter;
@override @override
TriggerableState createState() => TriggerableState(); TriggerableState createState() => TriggerableState();
} }
......
...@@ -30,7 +30,7 @@ class ValueInherited extends InheritedWidget { ...@@ -30,7 +30,7 @@ class ValueInherited extends InheritedWidget {
} }
class ExpectFail extends StatefulWidget { class ExpectFail extends StatefulWidget {
const ExpectFail(this.onError); const ExpectFail(this.onError, { Key key }) : super(key: key);
final VoidCallback onError; final VoidCallback onError;
@override @override
......
...@@ -12,7 +12,7 @@ class TestRoute extends PageRouteBuilder<void> { ...@@ -12,7 +12,7 @@ class TestRoute extends PageRouteBuilder<void> {
} }
class IconTextBox extends StatelessWidget { class IconTextBox extends StatelessWidget {
const IconTextBox(this.text); const IconTextBox(this.text, { Key key }) : super(key: key);
final String text; final String text;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart'; ...@@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart';
List<String> ancestors = <String>[]; List<String> ancestors = <String>[];
class TestWidget extends StatefulWidget { class TestWidget extends StatefulWidget {
const TestWidget({ Key key }) : super(key: key);
@override @override
TestWidgetState createState() => TestWidgetState(); TestWidgetState createState() => TestWidgetState();
} }
...@@ -28,7 +29,7 @@ class TestWidgetState extends State<TestWidget> { ...@@ -28,7 +29,7 @@ class TestWidgetState extends State<TestWidget> {
void main() { void main() {
testWidgets('initState() is called when we are in the tree', (WidgetTester tester) async { testWidgets('initState() is called when we are in the tree', (WidgetTester tester) async {
await tester.pumpWidget(Container(child: TestWidget())); await tester.pumpWidget(Container(child: const TestWidget()));
expect(ancestors, equals(<String>['Container', 'RenderObjectToWidgetAdapter<RenderBox>'])); expect(ancestors, equals(<String>['Container', 'RenderObjectToWidgetAdapter<RenderBox>']));
}); });
} }
...@@ -257,6 +257,7 @@ class LinkedScrollActivity extends ScrollActivity { ...@@ -257,6 +257,7 @@ class LinkedScrollActivity extends ScrollActivity {
} }
class Test extends StatefulWidget { class Test extends StatefulWidget {
const Test({ Key key }) : super(key: key);
@override @override
_TestState createState() => _TestState(); _TestState createState() => _TestState();
} }
...@@ -372,7 +373,7 @@ class _TestState extends State<Test> { ...@@ -372,7 +373,7 @@ class _TestState extends State<Test> {
void main() { void main() {
testWidgets('LinkedScrollController - 1', (WidgetTester tester) async { testWidgets('LinkedScrollController - 1', (WidgetTester tester) async {
await tester.pumpWidget(Test()); await tester.pumpWidget(const Test());
expect(find.text('Hello A'), findsOneWidget); expect(find.text('Hello A'), findsOneWidget);
expect(find.text('Hello 1'), findsOneWidget); expect(find.text('Hello 1'), findsOneWidget);
expect(find.text('Hello D'), findsNothing); expect(find.text('Hello D'), findsNothing);
...@@ -450,7 +451,7 @@ void main() { ...@@ -450,7 +451,7 @@ void main() {
expect(find.text('Hello 4'), findsOneWidget); expect(find.text('Hello 4'), findsOneWidget);
}); });
testWidgets('LinkedScrollController - 2', (WidgetTester tester) async { testWidgets('LinkedScrollController - 2', (WidgetTester tester) async {
await tester.pumpWidget(Test()); await tester.pumpWidget(const Test());
expect(find.text('Hello A'), findsOneWidget); expect(find.text('Hello A'), findsOneWidget);
expect(find.text('Hello B'), findsOneWidget); expect(find.text('Hello B'), findsOneWidget);
expect(find.text('Hello C'), findsNothing); expect(find.text('Hello C'), findsNothing);
......
...@@ -19,7 +19,7 @@ class TestSliverChildListDelegate extends SliverChildListDelegate { ...@@ -19,7 +19,7 @@ class TestSliverChildListDelegate extends SliverChildListDelegate {
} }
class Alive extends StatefulWidget { class Alive extends StatefulWidget {
const Alive(this.alive, this.index); const Alive(this.alive, this.index, { Key key }) : super(key: key);
final bool alive; final bool alive;
final int index; final int index;
......
...@@ -165,8 +165,8 @@ void main() { ...@@ -165,8 +165,8 @@ void main() {
testWidgets('ModalBarrier pops the Navigator when dismissed by primay tap', (WidgetTester tester) async { testWidgets('ModalBarrier pops the Navigator when dismissed by primay tap', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => FirstWidget(), '/': (BuildContext context) => const FirstWidget(),
'/modal': (BuildContext context) => SecondWidget(), '/modal': (BuildContext context) => const SecondWidget(),
}; };
await tester.pumpWidget(MaterialApp(routes: routes)); await tester.pumpWidget(MaterialApp(routes: routes));
...@@ -195,8 +195,8 @@ void main() { ...@@ -195,8 +195,8 @@ void main() {
testWidgets('ModalBarrier pops the Navigator when dismissed by non-primary tap', (WidgetTester tester) async { testWidgets('ModalBarrier pops the Navigator when dismissed by non-primary tap', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => FirstWidget(), '/': (BuildContext context) => const FirstWidget(),
'/modal': (BuildContext context) => SecondWidget(), '/modal': (BuildContext context) => const SecondWidget(),
}; };
await tester.pumpWidget(MaterialApp(routes: routes)); await tester.pumpWidget(MaterialApp(routes: routes));
...@@ -226,8 +226,8 @@ void main() { ...@@ -226,8 +226,8 @@ void main() {
testWidgets('ModalBarrier may pop the Navigator when competing with other gestures', (WidgetTester tester) async { testWidgets('ModalBarrier may pop the Navigator when competing with other gestures', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => FirstWidget(), '/': (BuildContext context) => const FirstWidget(),
'/modal': (BuildContext context) => SecondWidgetWithCompetence (), '/modal': (BuildContext context) => const SecondWidgetWithCompetence(),
}; };
await tester.pumpWidget(MaterialApp(routes: routes)); await tester.pumpWidget(MaterialApp(routes: routes));
...@@ -252,10 +252,10 @@ void main() { ...@@ -252,10 +252,10 @@ void main() {
testWidgets('ModalBarrier does not pop the Navigator with a WillPopScope that returns false', (WidgetTester tester) async { testWidgets('ModalBarrier does not pop the Navigator with a WillPopScope that returns false', (WidgetTester tester) async {
bool willPopCalled = false; bool willPopCalled = false;
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => FirstWidget(), '/': (BuildContext context) => const FirstWidget(),
'/modal': (BuildContext context) => Stack( '/modal': (BuildContext context) => Stack(
children: <Widget>[ children: <Widget>[
SecondWidget(), const SecondWidget(),
WillPopScope( WillPopScope(
child: const SizedBox(), child: const SizedBox(),
onWillPop: () async { onWillPop: () async {
...@@ -292,10 +292,10 @@ void main() { ...@@ -292,10 +292,10 @@ void main() {
testWidgets('ModalBarrier pops the Navigator with a WillPopScope that returns true', (WidgetTester tester) async { testWidgets('ModalBarrier pops the Navigator with a WillPopScope that returns true', (WidgetTester tester) async {
bool willPopCalled = false; bool willPopCalled = false;
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => FirstWidget(), '/': (BuildContext context) => const FirstWidget(),
'/modal': (BuildContext context) => Stack( '/modal': (BuildContext context) => Stack(
children: <Widget>[ children: <Widget>[
SecondWidget(), const SecondWidget(),
WillPopScope( WillPopScope(
child: const SizedBox(), child: const SizedBox(),
onWillPop: () async { onWillPop: () async {
...@@ -379,6 +379,7 @@ void main() { ...@@ -379,6 +379,7 @@ void main() {
} }
class FirstWidget extends StatelessWidget { class FirstWidget extends StatelessWidget {
const FirstWidget({ Key key }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return GestureDetector(
...@@ -393,6 +394,7 @@ class FirstWidget extends StatelessWidget { ...@@ -393,6 +394,7 @@ class FirstWidget extends StatelessWidget {
} }
class SecondWidget extends StatelessWidget { class SecondWidget extends StatelessWidget {
const SecondWidget({ Key key }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const ModalBarrier( return const ModalBarrier(
...@@ -403,6 +405,7 @@ class SecondWidget extends StatelessWidget { ...@@ -403,6 +405,7 @@ class SecondWidget extends StatelessWidget {
} }
class SecondWidgetWithCompetence extends StatelessWidget { class SecondWidgetWithCompetence extends StatelessWidget {
const SecondWidgetWithCompetence({ Key key }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Stack( return Stack(
......
...@@ -12,6 +12,7 @@ import 'observer_tester.dart'; ...@@ -12,6 +12,7 @@ import 'observer_tester.dart';
import 'semantics_tester.dart'; import 'semantics_tester.dart';
class FirstWidget extends StatelessWidget { class FirstWidget extends StatelessWidget {
const FirstWidget({ Key key }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return GestureDetector(
...@@ -27,6 +28,7 @@ class FirstWidget extends StatelessWidget { ...@@ -27,6 +28,7 @@ class FirstWidget extends StatelessWidget {
} }
class SecondWidget extends StatefulWidget { class SecondWidget extends StatefulWidget {
const SecondWidget({ Key key }) : super(key: key);
@override @override
SecondWidgetState createState() => SecondWidgetState(); SecondWidgetState createState() => SecondWidgetState();
} }
...@@ -47,7 +49,7 @@ class SecondWidgetState extends State<SecondWidget> { ...@@ -47,7 +49,7 @@ class SecondWidgetState extends State<SecondWidget> {
typedef ExceptionCallback = void Function(dynamic exception); typedef ExceptionCallback = void Function(dynamic exception);
class ThirdWidget extends StatelessWidget { class ThirdWidget extends StatelessWidget {
const ThirdWidget({ this.targetKey, this.onException }); const ThirdWidget({ Key key, this.targetKey, this.onException }) : super(key: key);
final Key targetKey; final Key targetKey;
final ExceptionCallback onException; final ExceptionCallback onException;
...@@ -94,8 +96,8 @@ class OnTapPage extends StatelessWidget { ...@@ -94,8 +96,8 @@ class OnTapPage extends StatelessWidget {
void main() { void main() {
testWidgets('Can navigator navigate to and from a stateful widget', (WidgetTester tester) async { testWidgets('Can navigator navigate to and from a stateful widget', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => FirstWidget(), // X '/': (BuildContext context) => const FirstWidget(), // X
'/second': (BuildContext context) => SecondWidget(), // Y '/second': (BuildContext context) => const SecondWidget(), // Y
}; };
await tester.pumpWidget(MaterialApp(routes: routes)); await tester.pumpWidget(MaterialApp(routes: routes));
......
...@@ -11,7 +11,10 @@ final BoxDecoration kBoxDecorationB = BoxDecoration(border: nonconst(null)); ...@@ -11,7 +11,10 @@ final BoxDecoration kBoxDecorationB = BoxDecoration(border: nonconst(null));
final BoxDecoration kBoxDecorationC = BoxDecoration(border: nonconst(null)); final BoxDecoration kBoxDecorationC = BoxDecoration(border: nonconst(null));
class TestWidget extends StatelessWidget { class TestWidget extends StatelessWidget {
const TestWidget({ this.child }); const TestWidget({
Key key,
this.child,
}) : super(key: key);
final Widget child; final Widget child;
......
...@@ -57,7 +57,11 @@ class DummyStatefulWidgetState extends State<DummyStatefulWidget> { ...@@ -57,7 +57,11 @@ class DummyStatefulWidgetState extends State<DummyStatefulWidget> {
} }
class RekeyableDummyStatefulWidgetWrapper extends StatefulWidget { class RekeyableDummyStatefulWidgetWrapper extends StatefulWidget {
const RekeyableDummyStatefulWidgetWrapper({ this.child, this.initialKey }); const RekeyableDummyStatefulWidgetWrapper({
Key key,
this.child,
this.initialKey,
}) : super(key: key);
final Widget child; final Widget child;
final GlobalKey initialKey; final GlobalKey initialKey;
@override @override
......
...@@ -10,6 +10,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -10,6 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
// This is a regression test for https://github.com/flutter/flutter/issues/5840. // This is a regression test for https://github.com/flutter/flutter/issues/5840.
class Bar extends StatefulWidget { class Bar extends StatefulWidget {
const Bar({ Key key }) : super(key: key);
@override @override
BarState createState() => BarState(); BarState createState() => BarState();
} }
...@@ -68,7 +69,7 @@ class StatefulCreationCounterState extends State<StatefulCreationCounter> { ...@@ -68,7 +69,7 @@ class StatefulCreationCounterState extends State<StatefulCreationCounter> {
void main() { void main() {
testWidgets('reparent state with layout builder', (WidgetTester tester) async { testWidgets('reparent state with layout builder', (WidgetTester tester) async {
expect(StatefulCreationCounterState.creationCount, 0); expect(StatefulCreationCounterState.creationCount, 0);
await tester.pumpWidget(Bar()); await tester.pumpWidget(const Bar());
expect(StatefulCreationCounterState.creationCount, 1); expect(StatefulCreationCounterState.creationCount, 1);
final BarState s = tester.state<BarState>(find.byType(Bar)); final BarState s = tester.state<BarState>(find.byType(Bar));
s.trigger(); s.trigger();
......
...@@ -14,7 +14,10 @@ ScrollController _controller = ScrollController( ...@@ -14,7 +14,10 @@ ScrollController _controller = ScrollController(
); );
class ThePositiveNumbers extends StatelessWidget { class ThePositiveNumbers extends StatelessWidget {
const ThePositiveNumbers({@required this.from}); const ThePositiveNumbers({
Key key,
@required this.from,
}) : super(key: key);
final int from; final int from;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
class Inside extends StatefulWidget { class Inside extends StatefulWidget {
const Inside({ Key key }) : super(key: key);
@override @override
InsideState createState() => InsideState(); InsideState createState() => InsideState();
} }
...@@ -25,7 +26,10 @@ class InsideState extends State<Inside> { ...@@ -25,7 +26,10 @@ class InsideState extends State<Inside> {
} }
class Middle extends StatefulWidget { class Middle extends StatefulWidget {
const Middle({ this.child }); const Middle({
Key key,
this.child,
}) : super(key: key);
final Inside child; final Inside child;
...@@ -48,6 +52,7 @@ class MiddleState extends State<Middle> { ...@@ -48,6 +52,7 @@ class MiddleState extends State<Middle> {
} }
class Outside extends StatefulWidget { class Outside extends StatefulWidget {
const Outside({ Key key }) : super(key: key);
@override @override
OutsideState createState() => OutsideState(); OutsideState createState() => OutsideState();
} }
...@@ -55,13 +60,13 @@ class Outside extends StatefulWidget { ...@@ -55,13 +60,13 @@ class Outside extends StatefulWidget {
class OutsideState extends State<Outside> { class OutsideState extends State<Outside> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Middle(child: Inside()); return const Middle(child: Inside());
} }
} }
void main() { void main() {
testWidgets('setState() smoke test', (WidgetTester tester) async { testWidgets('setState() smoke test', (WidgetTester tester) async {
await tester.pumpWidget(Outside()); await tester.pumpWidget(const Outside());
final Offset location = tester.getCenter(find.text('INSIDE')); final Offset location = tester.getCenter(find.text('INSIDE'));
final TestGesture gesture = await tester.startGesture(location); final TestGesture gesture = await tester.startGesture(location);
await tester.pump(); await tester.pump();
......
...@@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart';
ChangerState changer; ChangerState changer;
class Changer extends StatefulWidget { class Changer extends StatefulWidget {
const Changer(this.child); const Changer(this.child, { Key key }) : super(key: key);
final Widget child; final Widget child;
...@@ -32,7 +32,7 @@ class ChangerState extends State<Changer> { ...@@ -32,7 +32,7 @@ class ChangerState extends State<Changer> {
} }
class Wrapper extends StatelessWidget { class Wrapper extends StatelessWidget {
const Wrapper(this.child); const Wrapper(this.child, { Key key }) : super(key: key);
final Widget child; final Widget child;
...@@ -41,6 +41,7 @@ class Wrapper extends StatelessWidget { ...@@ -41,6 +41,7 @@ class Wrapper extends StatelessWidget {
} }
class Leaf extends StatefulWidget { class Leaf extends StatefulWidget {
const Leaf({ Key key }) : super(key: key);
@override @override
LeafState createState() => LeafState(); LeafState createState() => LeafState();
} }
...@@ -52,8 +53,8 @@ class LeafState extends State<Leaf> { ...@@ -52,8 +53,8 @@ class LeafState extends State<Leaf> {
void main() { void main() {
testWidgets('three-way setState() smoke test', (WidgetTester tester) async { testWidgets('three-way setState() smoke test', (WidgetTester tester) async {
await tester.pumpWidget(Changer(Wrapper(Leaf()))); await tester.pumpWidget(const Changer(Wrapper(Leaf())));
await tester.pumpWidget(Changer(Wrapper(Leaf()))); await tester.pumpWidget(const Changer(Wrapper(Leaf())));
changer.test(); changer.test();
await tester.pump(); await tester.pump();
}); });
......
...@@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
class Changer extends StatefulWidget { class Changer extends StatefulWidget {
const Changer({ Key key }) : super(key: key);
@override @override
ChangerState createState() => ChangerState(); ChangerState createState() => ChangerState();
} }
...@@ -21,7 +22,7 @@ class ChangerState extends State<Changer> { ...@@ -21,7 +22,7 @@ class ChangerState extends State<Changer> {
void main() { void main() {
testWidgets('setState() catches being used with an async callback', (WidgetTester tester) async { testWidgets('setState() catches being used with an async callback', (WidgetTester tester) async {
await tester.pumpWidget(Changer()); await tester.pumpWidget(const Changer());
final ChangerState s = tester.state(find.byType(Changer)); final ChangerState s = tester.state(find.byType(Changer));
expect(s.test0, isNot(throwsFlutterError)); expect(s.test0, isNot(throwsFlutterError));
expect(s.test1, isNot(throwsFlutterError)); expect(s.test1, isNot(throwsFlutterError));
......
...@@ -6,9 +6,9 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -6,9 +6,9 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
class BadWidget extends StatefulWidget { class BadWidget extends StatefulWidget {
const BadWidget({ Key key }) : super(key: key);
@override @override
State<StatefulWidget> createState() => BadWidgetState(); State<StatefulWidget> createState() => BadWidgetState();
} }
class BadWidgetState extends State<BadWidget> { class BadWidgetState extends State<BadWidget> {
...@@ -28,7 +28,7 @@ class BadWidgetState extends State<BadWidget> { ...@@ -28,7 +28,7 @@ class BadWidgetState extends State<BadWidget> {
void main() { void main() {
testWidgets('setState() catches being used inside a constructor', (WidgetTester tester) async { testWidgets('setState() catches being used inside a constructor', (WidgetTester tester) async {
await tester.pumpWidget(BadWidget()); await tester.pumpWidget(const BadWidget());
expect(tester.takeException(), isInstanceOf<FlutterError>()); expect(tester.takeException(), isInstanceOf<FlutterError>());
}); });
} }
...@@ -5,14 +5,6 @@ ...@@ -5,14 +5,6 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
class NotifyMaterial extends StatelessWidget {
@override
Widget build(BuildContext context) {
LayoutChangedNotification().dispatch(context);
return Container();
}
}
void main() { void main() {
testWidgets('SizeChangedLayoutNotification test', (WidgetTester tester) async { testWidgets('SizeChangedLayoutNotification test', (WidgetTester tester) async {
bool notified = false; bool notified = false;
......
...@@ -9,7 +9,7 @@ import 'package:flutter/widgets.dart'; ...@@ -9,7 +9,7 @@ import 'package:flutter/widgets.dart';
int globalGeneration = 0; int globalGeneration = 0;
class GenerationText extends StatefulWidget { class GenerationText extends StatefulWidget {
const GenerationText(this.value); const GenerationText(this.value, { Key key }) : super(key: key);
final int value; final int value;
@override @override
_GenerationTextState createState() => _GenerationTextState(); _GenerationTextState createState() => _GenerationTextState();
......
...@@ -701,7 +701,7 @@ bool sameHorizontal(Offset a, Offset b) => b.dy == a.dy; ...@@ -701,7 +701,7 @@ bool sameHorizontal(Offset a, Offset b) => b.dy == a.dy;
bool sameVertical(Offset a, Offset b) => b.dx == a.dx; bool sameVertical(Offset a, Offset b) => b.dx == a.dx;
class TestSliverGrid extends StatelessWidget { class TestSliverGrid extends StatelessWidget {
const TestSliverGrid(this.children); const TestSliverGrid(this.children, { Key key }) : super(key: key);
final List<Widget> children; final List<Widget> children;
...@@ -726,7 +726,7 @@ class TestSliverGrid extends StatelessWidget { ...@@ -726,7 +726,7 @@ class TestSliverGrid extends StatelessWidget {
} }
class TestSliverFixedExtentList extends StatelessWidget { class TestSliverFixedExtentList extends StatelessWidget {
const TestSliverFixedExtentList(this.children); const TestSliverFixedExtentList(this.children, { Key key }) : super(key: key);
final List<Widget> children; final List<Widget> children;
...@@ -749,7 +749,7 @@ class TestSliverFixedExtentList extends StatelessWidget { ...@@ -749,7 +749,7 @@ class TestSliverFixedExtentList extends StatelessWidget {
} }
class KeepAlive extends StatefulWidget { class KeepAlive extends StatefulWidget {
const KeepAlive(this.data); const KeepAlive(this.data, { Key key }) : super(key: key);
final String data; final String data;
......
...@@ -6,6 +6,7 @@ import 'package:flutter/widgets.dart'; ...@@ -6,6 +6,7 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
class Foo extends StatefulWidget { class Foo extends StatefulWidget {
const Foo({ Key key }) : super(key: key);
@override @override
FooState createState() => FooState(); FooState createState() => FooState();
} }
...@@ -80,7 +81,7 @@ class FooScrollBehavior extends ScrollBehavior { ...@@ -80,7 +81,7 @@ class FooScrollBehavior extends ScrollBehavior {
void main() { void main() {
testWidgets('Can animate scroll after setState', (WidgetTester tester) async { testWidgets('Can animate scroll after setState', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
Directionality( const Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Foo(), child: Foo(),
), ),
......
...@@ -57,10 +57,10 @@ void main() { ...@@ -57,10 +57,10 @@ void main() {
testWidgets('Don\'t rebuild subwidgets', (WidgetTester tester) async { testWidgets('Don\'t rebuild subwidgets', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
FlipWidget( const FlipWidget(
key: const Key('rebuild test'), key: Key('rebuild test'),
left: TestBuildCounter(), left: TestBuildCounter(),
right: const DecoratedBox(decoration: kBoxDecorationB), right: DecoratedBox(decoration: kBoxDecorationB),
), ),
); );
......
...@@ -6,7 +6,12 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -6,7 +6,12 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
class TestWidget extends StatefulWidget { class TestWidget extends StatefulWidget {
const TestWidget({ this.child, this.persistentState, this.syncedState }); const TestWidget({
Key key,
this.child,
this.persistentState,
this.syncedState,
}) : super(key: key);
final Widget child; final Widget child;
final int persistentState; final int persistentState;
......
...@@ -19,6 +19,8 @@ const BoxDecoration kBoxDecorationC = BoxDecoration( ...@@ -19,6 +19,8 @@ const BoxDecoration kBoxDecorationC = BoxDecoration(
); );
class TestBuildCounter extends StatelessWidget { class TestBuildCounter extends StatelessWidget {
const TestBuildCounter({ Key key }) : super(key: key);
static int buildCount = 0; static int buildCount = 0;
@override @override
......
...@@ -57,7 +57,7 @@ void main() { ...@@ -57,7 +57,7 @@ void main() {
}); });
testWidgets('SingleTickerProviderStateMixin can handle not being used', (WidgetTester tester) async { testWidgets('SingleTickerProviderStateMixin can handle not being used', (WidgetTester tester) async {
final Widget widget = BoringTickerTest(); const Widget widget = BoringTickerTest();
expect(widget.toString, isNot(throwsException)); expect(widget.toString, isNot(throwsException));
await tester.pumpWidget(widget); await tester.pumpWidget(widget);
...@@ -228,6 +228,7 @@ void main() { ...@@ -228,6 +228,7 @@ void main() {
} }
class BoringTickerTest extends StatefulWidget { class BoringTickerTest extends StatefulWidget {
const BoringTickerTest({ Key key }) : super(key: key);
@override @override
_BoringTickerTestState createState() => _BoringTickerTestState(); _BoringTickerTestState createState() => _BoringTickerTestState();
} }
......
...@@ -18,6 +18,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -18,6 +18,7 @@ import 'package:flutter_test/flutter_test.dart';
// columns will impact whether tests pass. // columns will impact whether tests pass.
class ClockDemo extends StatefulWidget { class ClockDemo extends StatefulWidget {
const ClockDemo({ Key key }) : super(key: key);
@override @override
_ClockDemoState createState() => _ClockDemoState(); _ClockDemoState createState() => _ClockDemoState();
} }
...@@ -1634,7 +1635,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService { ...@@ -1634,7 +1635,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService {
testWidgets('ext.flutter.inspector.trackRebuildDirtyWidgets', (WidgetTester tester) async { testWidgets('ext.flutter.inspector.trackRebuildDirtyWidgets', (WidgetTester tester) async {
service.rebuildCount = 0; service.rebuildCount = 0;
await tester.pumpWidget(ClockDemo()); await tester.pumpWidget(const ClockDemo());
final Element clockDemoElement = find.byType(ClockDemo).evaluate().first; final Element clockDemoElement = find.byType(ClockDemo).evaluate().first;
...@@ -1724,7 +1725,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService { ...@@ -1724,7 +1725,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService {
_CreationLocation location = knownLocations[id]; _CreationLocation location = knownLocations[id];
expect(location.file, equals(file)); expect(location.file, equals(file));
// ClockText widget. // ClockText widget.
expect(location.line, equals(50)); expect(location.line, equals(51));
expect(location.column, equals(9)); expect(location.column, equals(9));
expect(count, equals(1)); expect(count, equals(1));
...@@ -1733,7 +1734,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService { ...@@ -1733,7 +1734,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService {
location = knownLocations[id]; location = knownLocations[id];
expect(location.file, equals(file)); expect(location.file, equals(file));
// Text widget in _ClockTextState build method. // Text widget in _ClockTextState build method.
expect(location.line, equals(88)); expect(location.line, equals(89));
expect(location.column, equals(12)); expect(location.column, equals(12));
expect(count, equals(1)); expect(count, equals(1));
...@@ -1758,7 +1759,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService { ...@@ -1758,7 +1759,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService {
location = knownLocations[id]; location = knownLocations[id];
expect(location.file, equals(file)); expect(location.file, equals(file));
// ClockText widget. // ClockText widget.
expect(location.line, equals(50)); expect(location.line, equals(51));
expect(location.column, equals(9)); expect(location.column, equals(9));
expect(count, equals(3)); // 3 clock widget instances rebuilt. expect(count, equals(3)); // 3 clock widget instances rebuilt.
...@@ -1767,7 +1768,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService { ...@@ -1767,7 +1768,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService {
location = knownLocations[id]; location = knownLocations[id];
expect(location.file, equals(file)); expect(location.file, equals(file));
// Text widget in _ClockTextState build method. // Text widget in _ClockTextState build method.
expect(location.line, equals(88)); expect(location.line, equals(89));
expect(location.column, equals(12)); expect(location.column, equals(12));
expect(count, equals(3)); // 3 clock widget instances rebuilt. expect(count, equals(3)); // 3 clock widget instances rebuilt.
...@@ -1833,7 +1834,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService { ...@@ -1833,7 +1834,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService {
testWidgets('ext.flutter.inspector.trackRepaintWidgets', (WidgetTester tester) async { testWidgets('ext.flutter.inspector.trackRepaintWidgets', (WidgetTester tester) async {
service.rebuildCount = 0; service.rebuildCount = 0;
await tester.pumpWidget(ClockDemo()); await tester.pumpWidget(const ClockDemo());
final Element clockDemoElement = find.byType(ClockDemo).evaluate().first; final Element clockDemoElement = find.byType(ClockDemo).evaluate().first;
......
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