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