Default child lists to empty lists (#6592)
Fixes #6591
diff --git a/packages/flutter/lib/src/material/about.dart b/packages/flutter/lib/src/material/about.dart
index bf19b3a..3e75cd1 100644
--- a/packages/flutter/lib/src/material/about.dart
+++ b/packages/flutter/lib/src/material/about.dart
@@ -203,7 +203,7 @@
this.applicationVersion,
this.applicationIcon,
this.applicationLegalese,
- this.children
+ this.children,
}) : super(key: key);
/// The name of the application.
diff --git a/packages/flutter/lib/src/material/button_bar.dart b/packages/flutter/lib/src/material/button_bar.dart
index 710c7ed..306d2a3 100644
--- a/packages/flutter/lib/src/material/button_bar.dart
+++ b/packages/flutter/lib/src/material/button_bar.dart
@@ -30,7 +30,7 @@
Key key,
this.alignment: MainAxisAlignment.end,
this.mainAxisSize: MainAxisSize.max,
- this.children
+ this.children: const <Widget>[],
}) : super(key: key);
/// How the children should be placed along the horizontal axis.
diff --git a/packages/flutter/lib/src/material/list.dart b/packages/flutter/lib/src/material/list.dart
index d91d126..ff647e5 100644
--- a/packages/flutter/lib/src/material/list.dart
+++ b/packages/flutter/lib/src/material/list.dart
@@ -68,7 +68,7 @@
this.onScroll,
this.onScrollEnd,
this.type: MaterialListType.twoLine,
- this.children,
+ this.children: const <Widget>[],
this.padding: EdgeInsets.zero,
this.scrollableKey
}) : super(key: key);
diff --git a/packages/flutter/lib/src/material/two_level_list.dart b/packages/flutter/lib/src/material/two_level_list.dart
index c57dae6..568feb3 100644
--- a/packages/flutter/lib/src/material/two_level_list.dart
+++ b/packages/flutter/lib/src/material/two_level_list.dart
@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'package:flutter/widgets.dart';
+import 'package:meta/meta.dart';
import 'colors.dart';
import 'icon.dart';
@@ -32,7 +33,7 @@
TwoLevelListItem({
Key key,
this.leading,
- this.title,
+ @required this.title,
this.trailing,
this.enabled: true,
this.onTap,
@@ -107,10 +108,10 @@
TwoLevelSublist({
Key key,
this.leading,
- this.title,
+ @required this.title,
this.backgroundColor,
this.onOpenChanged,
- this.children
+ this.children: const <Widget>[],
}) : super(key: key);
/// A widget to display before the title.
@@ -263,7 +264,7 @@
TwoLevelList({
Key key,
this.scrollableKey,
- this.children,
+ this.children: const <Widget>[],
this.type: MaterialListType.twoLine,
this.padding
}) : super(key: key) {
diff --git a/packages/flutter/lib/src/rendering/grid.dart b/packages/flutter/lib/src/rendering/grid.dart
index ef0e8d6..a37dab4 100644
--- a/packages/flutter/lib/src/rendering/grid.dart
+++ b/packages/flutter/lib/src/rendering/grid.dart
@@ -532,6 +532,10 @@
/// The delegate that controls the layout of the children.
///
+ /// For example, a [FixedColumnCountGridDelegate] for grids that have a fixed
+ /// number of columns or a [MaxTileWidthGridDelegate] for grids that have a
+ /// maximum tile width.
+ ///
/// If the new delegate is the same as the previous one, this does nothing.
///
/// If the new delegate is the same class as the previous one, then the new
diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart
index 0ca09ed..7a4317e 100644
--- a/packages/flutter/lib/src/widgets/basic.dart
+++ b/packages/flutter/lib/src/widgets/basic.dart
@@ -745,8 +745,6 @@
}
}
-const List<Widget> _emptyWidgetList = const <Widget>[];
-
/// A widget that defers the layout of multiple children to a delegate.
///
/// The delegate can determine the layout constraints for each child and can
@@ -767,7 +765,7 @@
CustomMultiChildLayout({
Key key,
@required this.delegate,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) {
assert(delegate != null);
}
@@ -1414,7 +1412,7 @@
BlockBody({
Key key,
this.mainAxis: Axis.vertical,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) {
assert(mainAxis != null);
}
@@ -1468,7 +1466,7 @@
Key key,
this.alignment: FractionalOffset.topLeft,
this.overflow: Overflow.clip,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(key: key, children: children);
/// How to align the non-positioned children in the stack.
@@ -1514,7 +1512,7 @@
Key key,
FractionalOffset alignment: FractionalOffset.topLeft,
this.index: 0,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(key: key, alignment: alignment, children: children) {
assert(index != null);
}
@@ -1710,8 +1708,8 @@
abstract class GridRenderObjectWidget extends MultiChildRenderObjectWidget {
/// Initializes fields for subclasses.
GridRenderObjectWidget({
- List<Widget> children: _emptyWidgetList,
- Key key
+ Key key,
+ List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) {
_delegate = createDelegate();
}
@@ -1743,12 +1741,16 @@
CustomGrid({
Key key,
@required this.delegate,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) {
assert(delegate != null);
}
/// The delegate that controls the layout of the children.
+ ///
+ /// For example, a [FixedColumnCountGridDelegate] for grids that have a fixed
+ /// number of columns or a [MaxTileWidthGridDelegate] for grids that have a
+ /// maximum tile width.
final GridDelegate delegate;
@override
@@ -1769,7 +1771,7 @@
this.rowSpacing: 0.0,
this.tileAspectRatio: 1.0,
this.padding: EdgeInsets.zero,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) {
assert(columnCount != null && columnCount >= 0);
assert(tileAspectRatio != null && tileAspectRatio > 0.0);
@@ -1816,7 +1818,7 @@
this.rowSpacing: 0.0,
this.tileAspectRatio: 1.0,
this.padding: EdgeInsets.zero,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) {
assert(maxTileWidth != null && maxTileWidth >= 0.0);
assert(tileAspectRatio != null && tileAspectRatio > 0.0);
@@ -1945,7 +1947,7 @@
this.mainAxisSize: MainAxisSize.max,
this.crossAxisAlignment: CrossAxisAlignment.center,
this.textBaseline,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) {
assert(direction != null);
assert(mainAxisAlignment != null);
@@ -2047,7 +2049,7 @@
MainAxisSize mainAxisSize: MainAxisSize.max,
CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center,
TextBaseline textBaseline,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
@@ -2101,7 +2103,7 @@
MainAxisSize mainAxisSize: MainAxisSize.max,
CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center,
TextBaseline textBaseline,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
@@ -2212,7 +2214,7 @@
Flow({
Key key,
@required this.delegate,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(key: key, children: RepaintBoundary.wrapAll(children)) {
assert(delegate != null);
}
@@ -2227,7 +2229,7 @@
Flow.unwrapped({
Key key,
this.delegate,
- List<Widget> children: _emptyWidgetList
+ List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) {
assert(delegate != null);
}
diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart
index 0ae1d08..7eb0400 100644
--- a/packages/flutter/lib/src/widgets/framework.dart
+++ b/packages/flutter/lib/src/widgets/framework.dart
@@ -1215,7 +1215,7 @@
///
/// The [children] argument must not be null and must not contain any null
/// objects.
- MultiChildRenderObjectWidget({ Key key, this.children })
+ MultiChildRenderObjectWidget({ Key key, this.children: const <Widget>[] })
: super(key: key) {
assert(children != null);
assert(!children.any((Widget child) => child == null));
diff --git a/packages/flutter/lib/src/widgets/lazy_block.dart b/packages/flutter/lib/src/widgets/lazy_block.dart
index 36308b9..1ad847b 100644
--- a/packages/flutter/lib/src/widgets/lazy_block.dart
+++ b/packages/flutter/lib/src/widgets/lazy_block.dart
@@ -144,7 +144,7 @@
///
/// The list of children must not be modified after being passed to this
/// constructor.
- LazyBlockChildren({ this.children }) {
+ LazyBlockChildren({ this.children: const <Widget>[] }) {
assert(children != null);
}
diff --git a/packages/flutter/lib/src/widgets/pageable_list.dart b/packages/flutter/lib/src/widgets/pageable_list.dart
index 53c411a..e7911f1 100644
--- a/packages/flutter/lib/src/widgets/pageable_list.dart
+++ b/packages/flutter/lib/src/widgets/pageable_list.dart
@@ -122,7 +122,7 @@
ValueChanged<int> onPageChanged,
Duration duration: const Duration(milliseconds: 200),
Curve curve: Curves.ease,
- this.children
+ this.children: const <Widget>[],
}) : super(
key: key,
initialScrollOffset: initialScrollOffset,
@@ -542,7 +542,7 @@
Axis mainAxis: Axis.vertical,
ViewportAnchor anchor: ViewportAnchor.start,
bool itemsWrap: false,
- this.children
+ this.children: const <Widget>[],
}) : super(
startOffset,
mainAxis,
diff --git a/packages/flutter/lib/src/widgets/scrollable_grid.dart b/packages/flutter/lib/src/widgets/scrollable_grid.dart
index 7ab2243..8e15884 100644
--- a/packages/flutter/lib/src/widgets/scrollable_grid.dart
+++ b/packages/flutter/lib/src/widgets/scrollable_grid.dart
@@ -35,7 +35,7 @@
this.snapOffsetCallback,
this.scrollableKey,
@required this.delegate,
- this.children
+ this.children: const <Widget>[],
}) : super(key: key) {
assert(delegate != null);
}
@@ -75,6 +75,10 @@
final Key scrollableKey;
/// The delegate that controls the layout of the children.
+ ///
+ /// For example, a [FixedColumnCountGridDelegate] for grids that have a fixed
+ /// number of columns or a [MaxTileWidthGridDelegate] for grids that have a
+ /// maximum tile width.
final GridDelegate delegate;
/// The children that will be placed in the grid.
@@ -124,7 +128,7 @@
this.scrollOffset,
this.delegate,
this.onExtentsChanged,
- this.children
+ this.children: const <Widget>[],
}) {
assert(delegate != null);
}
@@ -140,6 +144,10 @@
}
/// The delegate that controls the layout of the children.
+ ///
+ /// For example, a [FixedColumnCountGridDelegate] for grids that have a fixed
+ /// number of columns or a [MaxTileWidthGridDelegate] for grids that have a
+ /// maximum tile width.
final GridDelegate delegate;
/// Called when the interior or exterior dimensions of the viewport change.
diff --git a/packages/flutter/lib/src/widgets/scrollable_list.dart b/packages/flutter/lib/src/widgets/scrollable_list.dart
index 076a32e..30b39fa 100644
--- a/packages/flutter/lib/src/widgets/scrollable_list.dart
+++ b/packages/flutter/lib/src/widgets/scrollable_list.dart
@@ -49,7 +49,7 @@
@required this.itemExtent,
this.itemsWrap: false,
this.padding,
- this.children
+ this.children: const <Widget>[],
}) : super(key: key) {
assert(scrollDirection != null);
assert(scrollAnchor != null);
@@ -389,7 +389,7 @@
@required double itemExtent,
bool itemsWrap: false,
EdgeInsets padding,
- this.children
+ this.children: const <Widget>[],
}) : super(
onExtentsChanged,
scrollOffset,
diff --git a/packages/flutter/test/material/button_bar_test.dart b/packages/flutter/test/material/button_bar_test.dart
new file mode 100644
index 0000000..479ee2d
--- /dev/null
+++ b/packages/flutter/test/material/button_bar_test.dart
@@ -0,0 +1,12 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+void main() {
+ testWidgets('ButtonBar default control', (WidgetTester tester) async {
+ await tester.pumpWidget(new Center(child: new ButtonBar()));
+ });
+}
diff --git a/packages/flutter/test/material/list_test.dart b/packages/flutter/test/material/list_test.dart
new file mode 100644
index 0000000..d86e7c6
--- /dev/null
+++ b/packages/flutter/test/material/list_test.dart
@@ -0,0 +1,12 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+void main() {
+ testWidgets('MaterialList default control', (WidgetTester tester) async {
+ await tester.pumpWidget(new Center(child: new MaterialList()));
+ });
+}
diff --git a/packages/flutter/test/material/two_level_list_test.dart b/packages/flutter/test/material/two_level_list_test.dart
index bb8cd9b..bce5ea4 100644
--- a/packages/flutter/test/material/two_level_list_test.dart
+++ b/packages/flutter/test/material/two_level_list_test.dart
@@ -7,7 +7,25 @@
import 'package:flutter/material.dart';
void main() {
- testWidgets('TwoLeveList basics', (WidgetTester tester) async {
+ testWidgets('TwoLevelList default control', (WidgetTester tester) async {
+ await tester.pumpWidget(new Center(child: new TwoLevelList()));
+
+ await tester.pumpWidget(
+ new Material(
+ child: new Center(
+ child: new TwoLevelList(
+ children: <Widget>[
+ new TwoLevelSublist(
+ title: new Text('Title'),
+ )
+ ]
+ )
+ )
+ )
+ );
+ });
+
+ testWidgets('TwoLevelList basics', (WidgetTester tester) async {
final Key topKey = new UniqueKey();
final Key sublistKey = new UniqueKey();
final Key bottomKey = new UniqueKey();
diff --git a/packages/flutter/test/widget/pageable_list_test.dart b/packages/flutter/test/widget/pageable_list_test.dart
index 89ab688..122af47 100644
--- a/packages/flutter/test/widget/pageable_list_test.dart
+++ b/packages/flutter/test/widget/pageable_list_test.dart
@@ -60,6 +60,10 @@
}
void main() {
+ testWidgets('PageableList default control', (WidgetTester tester) async {
+ await tester.pumpWidget(new Center(child: new PageableList()));
+ });
+
testWidgets('PageableList with itemsWrap: false', (WidgetTester tester) async {
currentPage = null;
await tester.pumpWidget(buildFrame());
diff --git a/packages/flutter/test/widget/scrollable_grid_test.dart b/packages/flutter/test/widget/scrollable_grid_test.dart
index 7f7fd32..7c74638 100644
--- a/packages/flutter/test/widget/scrollable_grid_test.dart
+++ b/packages/flutter/test/widget/scrollable_grid_test.dart
@@ -7,6 +7,12 @@
import 'package:flutter/rendering.dart';
void main() {
+ testWidgets('ScrollableGrid default control', (WidgetTester tester) async {
+ await tester.pumpWidget(new Center(child: new ScrollableGrid(
+ delegate: new FixedColumnCountGridDelegate(columnCount: 1),
+ )));
+ });
+
// Tests https://github.com/flutter/flutter/issues/5522
testWidgets('ScrollableGrid displays correct children with nonzero padding', (WidgetTester tester) async {
GlobalKey<ScrollableState> scrollableKey = new GlobalKey<ScrollableState>();
diff --git a/packages/flutter/test/widget/scrollable_list_test.dart b/packages/flutter/test/widget/scrollable_list_test.dart
new file mode 100644
index 0000000..7bf2028
--- /dev/null
+++ b/packages/flutter/test/widget/scrollable_list_test.dart
@@ -0,0 +1,12 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+void main() {
+ testWidgets('ScrollableList default control', (WidgetTester tester) async {
+ await tester.pumpWidget(new Center(child: new ScrollableList(itemExtent: 100.0)));
+ });
+}