Commit 018ab3f6 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Default child lists to empty lists (#6592)

Fixes #6591
parent 07f99987
...@@ -203,7 +203,7 @@ class AboutDialog extends StatelessWidget { ...@@ -203,7 +203,7 @@ class AboutDialog extends StatelessWidget {
this.applicationVersion, this.applicationVersion,
this.applicationIcon, this.applicationIcon,
this.applicationLegalese, this.applicationLegalese,
this.children this.children,
}) : super(key: key); }) : super(key: key);
/// The name of the application. /// The name of the application.
......
...@@ -30,7 +30,7 @@ class ButtonBar extends StatelessWidget { ...@@ -30,7 +30,7 @@ class ButtonBar extends StatelessWidget {
Key key, Key key,
this.alignment: MainAxisAlignment.end, this.alignment: MainAxisAlignment.end,
this.mainAxisSize: MainAxisSize.max, this.mainAxisSize: MainAxisSize.max,
this.children this.children: const <Widget>[],
}) : super(key: key); }) : super(key: key);
/// How the children should be placed along the horizontal axis. /// How the children should be placed along the horizontal axis.
......
...@@ -68,7 +68,7 @@ class MaterialList extends StatelessWidget { ...@@ -68,7 +68,7 @@ class MaterialList extends StatelessWidget {
this.onScroll, this.onScroll,
this.onScrollEnd, this.onScrollEnd,
this.type: MaterialListType.twoLine, this.type: MaterialListType.twoLine,
this.children, this.children: const <Widget>[],
this.padding: EdgeInsets.zero, this.padding: EdgeInsets.zero,
this.scrollableKey this.scrollableKey
}) : super(key: key); }) : super(key: key);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';
import 'colors.dart'; import 'colors.dart';
import 'icon.dart'; import 'icon.dart';
...@@ -32,7 +33,7 @@ class TwoLevelListItem extends StatelessWidget { ...@@ -32,7 +33,7 @@ class TwoLevelListItem extends StatelessWidget {
TwoLevelListItem({ TwoLevelListItem({
Key key, Key key,
this.leading, this.leading,
this.title, @required this.title,
this.trailing, this.trailing,
this.enabled: true, this.enabled: true,
this.onTap, this.onTap,
...@@ -107,10 +108,10 @@ class TwoLevelSublist extends StatefulWidget { ...@@ -107,10 +108,10 @@ class TwoLevelSublist extends StatefulWidget {
TwoLevelSublist({ TwoLevelSublist({
Key key, Key key,
this.leading, this.leading,
this.title, @required this.title,
this.backgroundColor, this.backgroundColor,
this.onOpenChanged, this.onOpenChanged,
this.children this.children: const <Widget>[],
}) : super(key: key); }) : super(key: key);
/// A widget to display before the title. /// A widget to display before the title.
...@@ -263,7 +264,7 @@ class TwoLevelList extends StatelessWidget { ...@@ -263,7 +264,7 @@ class TwoLevelList extends StatelessWidget {
TwoLevelList({ TwoLevelList({
Key key, Key key,
this.scrollableKey, this.scrollableKey,
this.children, this.children: const <Widget>[],
this.type: MaterialListType.twoLine, this.type: MaterialListType.twoLine,
this.padding this.padding
}) : super(key: key) { }) : super(key: key) {
......
...@@ -532,6 +532,10 @@ class RenderGrid extends RenderVirtualViewport<GridParentData> { ...@@ -532,6 +532,10 @@ class RenderGrid extends RenderVirtualViewport<GridParentData> {
/// The delegate that controls the layout of the children. /// 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 as the previous one, this does nothing.
/// ///
/// If the new delegate is the same class as the previous one, then the new /// If the new delegate is the same class as the previous one, then the new
......
...@@ -745,8 +745,6 @@ class LayoutId extends ParentDataWidget<CustomMultiChildLayout> { ...@@ -745,8 +745,6 @@ class LayoutId extends ParentDataWidget<CustomMultiChildLayout> {
} }
} }
const List<Widget> _emptyWidgetList = const <Widget>[];
/// A widget that defers the layout of multiple children to a delegate. /// A widget that defers the layout of multiple children to a delegate.
/// ///
/// The delegate can determine the layout constraints for each child and can /// The delegate can determine the layout constraints for each child and can
...@@ -767,7 +765,7 @@ class CustomMultiChildLayout extends MultiChildRenderObjectWidget { ...@@ -767,7 +765,7 @@ class CustomMultiChildLayout extends MultiChildRenderObjectWidget {
CustomMultiChildLayout({ CustomMultiChildLayout({
Key key, Key key,
@required this.delegate, @required this.delegate,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) { }) : super(key: key, children: children) {
assert(delegate != null); assert(delegate != null);
} }
...@@ -1414,7 +1412,7 @@ class BlockBody extends MultiChildRenderObjectWidget { ...@@ -1414,7 +1412,7 @@ class BlockBody extends MultiChildRenderObjectWidget {
BlockBody({ BlockBody({
Key key, Key key,
this.mainAxis: Axis.vertical, this.mainAxis: Axis.vertical,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) { }) : super(key: key, children: children) {
assert(mainAxis != null); assert(mainAxis != null);
} }
...@@ -1468,7 +1466,7 @@ class Stack extends MultiChildRenderObjectWidget { ...@@ -1468,7 +1466,7 @@ class Stack extends MultiChildRenderObjectWidget {
Key key, Key key,
this.alignment: FractionalOffset.topLeft, this.alignment: FractionalOffset.topLeft,
this.overflow: Overflow.clip, this.overflow: Overflow.clip,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super(key: key, children: children); }) : super(key: key, children: children);
/// How to align the non-positioned children in the stack. /// How to align the non-positioned children in the stack.
...@@ -1514,7 +1512,7 @@ class IndexedStack extends Stack { ...@@ -1514,7 +1512,7 @@ class IndexedStack extends Stack {
Key key, Key key,
FractionalOffset alignment: FractionalOffset.topLeft, FractionalOffset alignment: FractionalOffset.topLeft,
this.index: 0, this.index: 0,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super(key: key, alignment: alignment, children: children) { }) : super(key: key, alignment: alignment, children: children) {
assert(index != null); assert(index != null);
} }
...@@ -1710,8 +1708,8 @@ class Positioned extends ParentDataWidget<Stack> { ...@@ -1710,8 +1708,8 @@ class Positioned extends ParentDataWidget<Stack> {
abstract class GridRenderObjectWidget extends MultiChildRenderObjectWidget { abstract class GridRenderObjectWidget extends MultiChildRenderObjectWidget {
/// Initializes fields for subclasses. /// Initializes fields for subclasses.
GridRenderObjectWidget({ GridRenderObjectWidget({
List<Widget> children: _emptyWidgetList, Key key,
Key key List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) { }) : super(key: key, children: children) {
_delegate = createDelegate(); _delegate = createDelegate();
} }
...@@ -1743,12 +1741,16 @@ class CustomGrid extends GridRenderObjectWidget { ...@@ -1743,12 +1741,16 @@ class CustomGrid extends GridRenderObjectWidget {
CustomGrid({ CustomGrid({
Key key, Key key,
@required this.delegate, @required this.delegate,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) { }) : super(key: key, children: children) {
assert(delegate != null); assert(delegate != null);
} }
/// The delegate that controls the layout of the children. /// 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; final GridDelegate delegate;
@override @override
...@@ -1769,7 +1771,7 @@ class FixedColumnCountGrid extends GridRenderObjectWidget { ...@@ -1769,7 +1771,7 @@ class FixedColumnCountGrid extends GridRenderObjectWidget {
this.rowSpacing: 0.0, this.rowSpacing: 0.0,
this.tileAspectRatio: 1.0, this.tileAspectRatio: 1.0,
this.padding: EdgeInsets.zero, this.padding: EdgeInsets.zero,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) { }) : super(key: key, children: children) {
assert(columnCount != null && columnCount >= 0); assert(columnCount != null && columnCount >= 0);
assert(tileAspectRatio != null && tileAspectRatio > 0.0); assert(tileAspectRatio != null && tileAspectRatio > 0.0);
...@@ -1816,7 +1818,7 @@ class MaxTileWidthGrid extends GridRenderObjectWidget { ...@@ -1816,7 +1818,7 @@ class MaxTileWidthGrid extends GridRenderObjectWidget {
this.rowSpacing: 0.0, this.rowSpacing: 0.0,
this.tileAspectRatio: 1.0, this.tileAspectRatio: 1.0,
this.padding: EdgeInsets.zero, this.padding: EdgeInsets.zero,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) { }) : super(key: key, children: children) {
assert(maxTileWidth != null && maxTileWidth >= 0.0); assert(maxTileWidth != null && maxTileWidth >= 0.0);
assert(tileAspectRatio != null && tileAspectRatio > 0.0); assert(tileAspectRatio != null && tileAspectRatio > 0.0);
...@@ -1945,7 +1947,7 @@ class Flex extends MultiChildRenderObjectWidget { ...@@ -1945,7 +1947,7 @@ class Flex extends MultiChildRenderObjectWidget {
this.mainAxisSize: MainAxisSize.max, this.mainAxisSize: MainAxisSize.max,
this.crossAxisAlignment: CrossAxisAlignment.center, this.crossAxisAlignment: CrossAxisAlignment.center,
this.textBaseline, this.textBaseline,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) { }) : super(key: key, children: children) {
assert(direction != null); assert(direction != null);
assert(mainAxisAlignment != null); assert(mainAxisAlignment != null);
...@@ -2047,7 +2049,7 @@ class Row extends Flex { ...@@ -2047,7 +2049,7 @@ class Row extends Flex {
MainAxisSize mainAxisSize: MainAxisSize.max, MainAxisSize mainAxisSize: MainAxisSize.max,
CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center, CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center,
TextBaseline textBaseline, TextBaseline textBaseline,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,
...@@ -2101,7 +2103,7 @@ class Column extends Flex { ...@@ -2101,7 +2103,7 @@ class Column extends Flex {
MainAxisSize mainAxisSize: MainAxisSize.max, MainAxisSize mainAxisSize: MainAxisSize.max,
CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center, CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center,
TextBaseline textBaseline, TextBaseline textBaseline,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,
...@@ -2212,7 +2214,7 @@ class Flow extends MultiChildRenderObjectWidget { ...@@ -2212,7 +2214,7 @@ class Flow extends MultiChildRenderObjectWidget {
Flow({ Flow({
Key key, Key key,
@required this.delegate, @required this.delegate,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super(key: key, children: RepaintBoundary.wrapAll(children)) { }) : super(key: key, children: RepaintBoundary.wrapAll(children)) {
assert(delegate != null); assert(delegate != null);
} }
...@@ -2227,7 +2229,7 @@ class Flow extends MultiChildRenderObjectWidget { ...@@ -2227,7 +2229,7 @@ class Flow extends MultiChildRenderObjectWidget {
Flow.unwrapped({ Flow.unwrapped({
Key key, Key key,
this.delegate, this.delegate,
List<Widget> children: _emptyWidgetList List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) { }) : super(key: key, children: children) {
assert(delegate != null); assert(delegate != null);
} }
......
...@@ -1215,7 +1215,7 @@ abstract class MultiChildRenderObjectWidget extends RenderObjectWidget { ...@@ -1215,7 +1215,7 @@ abstract class MultiChildRenderObjectWidget extends RenderObjectWidget {
/// ///
/// The [children] argument must not be null and must not contain any null /// The [children] argument must not be null and must not contain any null
/// objects. /// objects.
MultiChildRenderObjectWidget({ Key key, this.children }) MultiChildRenderObjectWidget({ Key key, this.children: const <Widget>[] })
: super(key: key) { : super(key: key) {
assert(children != null); assert(children != null);
assert(!children.any((Widget child) => child == null)); assert(!children.any((Widget child) => child == null));
......
...@@ -144,7 +144,7 @@ class LazyBlockChildren extends LazyBlockDelegate { ...@@ -144,7 +144,7 @@ class LazyBlockChildren extends LazyBlockDelegate {
/// ///
/// The list of children must not be modified after being passed to this /// The list of children must not be modified after being passed to this
/// constructor. /// constructor.
LazyBlockChildren({ this.children }) { LazyBlockChildren({ this.children: const <Widget>[] }) {
assert(children != null); assert(children != null);
} }
......
...@@ -122,7 +122,7 @@ class PageableList extends Pageable { ...@@ -122,7 +122,7 @@ class PageableList extends Pageable {
ValueChanged<int> onPageChanged, ValueChanged<int> onPageChanged,
Duration duration: const Duration(milliseconds: 200), Duration duration: const Duration(milliseconds: 200),
Curve curve: Curves.ease, Curve curve: Curves.ease,
this.children this.children: const <Widget>[],
}) : super( }) : super(
key: key, key: key,
initialScrollOffset: initialScrollOffset, initialScrollOffset: initialScrollOffset,
...@@ -542,7 +542,7 @@ class PageViewport extends _VirtualPageViewport with VirtualViewportFromIterable ...@@ -542,7 +542,7 @@ class PageViewport extends _VirtualPageViewport with VirtualViewportFromIterable
Axis mainAxis: Axis.vertical, Axis mainAxis: Axis.vertical,
ViewportAnchor anchor: ViewportAnchor.start, ViewportAnchor anchor: ViewportAnchor.start,
bool itemsWrap: false, bool itemsWrap: false,
this.children this.children: const <Widget>[],
}) : super( }) : super(
startOffset, startOffset,
mainAxis, mainAxis,
......
...@@ -35,7 +35,7 @@ class ScrollableGrid extends StatelessWidget { ...@@ -35,7 +35,7 @@ class ScrollableGrid extends StatelessWidget {
this.snapOffsetCallback, this.snapOffsetCallback,
this.scrollableKey, this.scrollableKey,
@required this.delegate, @required this.delegate,
this.children this.children: const <Widget>[],
}) : super(key: key) { }) : super(key: key) {
assert(delegate != null); assert(delegate != null);
} }
...@@ -75,6 +75,10 @@ class ScrollableGrid extends StatelessWidget { ...@@ -75,6 +75,10 @@ class ScrollableGrid extends StatelessWidget {
final Key scrollableKey; final Key scrollableKey;
/// The delegate that controls the layout of the children. /// 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; final GridDelegate delegate;
/// The children that will be placed in the grid. /// The children that will be placed in the grid.
...@@ -124,7 +128,7 @@ class GridViewport extends VirtualViewportFromIterable { ...@@ -124,7 +128,7 @@ class GridViewport extends VirtualViewportFromIterable {
this.scrollOffset, this.scrollOffset,
this.delegate, this.delegate,
this.onExtentsChanged, this.onExtentsChanged,
this.children this.children: const <Widget>[],
}) { }) {
assert(delegate != null); assert(delegate != null);
} }
...@@ -140,6 +144,10 @@ class GridViewport extends VirtualViewportFromIterable { ...@@ -140,6 +144,10 @@ class GridViewport extends VirtualViewportFromIterable {
} }
/// The delegate that controls the layout of the children. /// 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; final GridDelegate delegate;
/// Called when the interior or exterior dimensions of the viewport change. /// Called when the interior or exterior dimensions of the viewport change.
......
...@@ -49,7 +49,7 @@ class ScrollableList extends StatelessWidget { ...@@ -49,7 +49,7 @@ class ScrollableList extends StatelessWidget {
@required this.itemExtent, @required this.itemExtent,
this.itemsWrap: false, this.itemsWrap: false,
this.padding, this.padding,
this.children this.children: const <Widget>[],
}) : super(key: key) { }) : super(key: key) {
assert(scrollDirection != null); assert(scrollDirection != null);
assert(scrollAnchor != null); assert(scrollAnchor != null);
...@@ -389,7 +389,7 @@ class ListViewport extends _VirtualListViewport with VirtualViewportFromIterable ...@@ -389,7 +389,7 @@ class ListViewport extends _VirtualListViewport with VirtualViewportFromIterable
@required double itemExtent, @required double itemExtent,
bool itemsWrap: false, bool itemsWrap: false,
EdgeInsets padding, EdgeInsets padding,
this.children this.children: const <Widget>[],
}) : super( }) : super(
onExtentsChanged, onExtentsChanged,
scrollOffset, scrollOffset,
......
// 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()));
});
}
// 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()));
});
}
...@@ -7,7 +7,25 @@ import 'package:flutter/widgets.dart'; ...@@ -7,7 +7,25 @@ import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() { 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 topKey = new UniqueKey();
final Key sublistKey = new UniqueKey(); final Key sublistKey = new UniqueKey();
final Key bottomKey = new UniqueKey(); final Key bottomKey = new UniqueKey();
......
...@@ -60,6 +60,10 @@ Future<Null> pageRight(WidgetTester tester) { ...@@ -60,6 +60,10 @@ Future<Null> pageRight(WidgetTester tester) {
} }
void main() { 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 { testWidgets('PageableList with itemsWrap: false', (WidgetTester tester) async {
currentPage = null; currentPage = null;
await tester.pumpWidget(buildFrame()); await tester.pumpWidget(buildFrame());
......
...@@ -7,6 +7,12 @@ import 'package:flutter/widgets.dart'; ...@@ -7,6 +7,12 @@ import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
void main() { 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 // Tests https://github.com/flutter/flutter/issues/5522
testWidgets('ScrollableGrid displays correct children with nonzero padding', (WidgetTester tester) async { testWidgets('ScrollableGrid displays correct children with nonzero padding', (WidgetTester tester) async {
GlobalKey<ScrollableState> scrollableKey = new GlobalKey<ScrollableState>(); GlobalKey<ScrollableState> scrollableKey = new GlobalKey<ScrollableState>();
......
// 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)));
});
}
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