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 {
this.applicationVersion,
this.applicationIcon,
this.applicationLegalese,
this.children
this.children,
}) : super(key: key);
/// The name of the application.
......
......@@ -30,7 +30,7 @@ class ButtonBar extends StatelessWidget {
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.
......
......@@ -68,7 +68,7 @@ class MaterialList extends StatelessWidget {
this.onScroll,
this.onScrollEnd,
this.type: MaterialListType.twoLine,
this.children,
this.children: const <Widget>[],
this.padding: EdgeInsets.zero,
this.scrollableKey
}) : super(key: key);
......
......@@ -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 @@ class TwoLevelListItem extends StatelessWidget {
TwoLevelListItem({
Key key,
this.leading,
this.title,
@required this.title,
this.trailing,
this.enabled: true,
this.onTap,
......@@ -107,10 +108,10 @@ class TwoLevelSublist extends StatefulWidget {
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 @@ class TwoLevelList extends StatelessWidget {
TwoLevelList({
Key key,
this.scrollableKey,
this.children,
this.children: const <Widget>[],
this.type: MaterialListType.twoLine,
this.padding
}) : super(key: key) {
......
......@@ -532,6 +532,10 @@ class RenderGrid extends RenderVirtualViewport<GridParentData> {
/// 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
......
......@@ -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.
///
/// The delegate can determine the layout constraints for each child and can
......@@ -767,7 +765,7 @@ class CustomMultiChildLayout extends MultiChildRenderObjectWidget {
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 @@ class BlockBody extends MultiChildRenderObjectWidget {
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 @@ class Stack extends MultiChildRenderObjectWidget {
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 @@ class IndexedStack extends Stack {
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 @@ class Positioned extends ParentDataWidget<Stack> {
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 @@ class CustomGrid extends GridRenderObjectWidget {
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 @@ class FixedColumnCountGrid extends GridRenderObjectWidget {
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 @@ class MaxTileWidthGrid extends GridRenderObjectWidget {
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 @@ class Flex extends MultiChildRenderObjectWidget {
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 @@ class Row extends Flex {
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 @@ class Column extends Flex {
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 @@ class Flow extends MultiChildRenderObjectWidget {
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 @@ class Flow extends MultiChildRenderObjectWidget {
Flow.unwrapped({
Key key,
this.delegate,
List<Widget> children: _emptyWidgetList
List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) {
assert(delegate != null);
}
......
......@@ -1215,7 +1215,7 @@ abstract class MultiChildRenderObjectWidget extends RenderObjectWidget {
///
/// 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));
......
......@@ -144,7 +144,7 @@ class LazyBlockChildren extends LazyBlockDelegate {
///
/// 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);
}
......
......@@ -122,7 +122,7 @@ class PageableList extends Pageable {
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 @@ class PageViewport extends _VirtualPageViewport with VirtualViewportFromIterable
Axis mainAxis: Axis.vertical,
ViewportAnchor anchor: ViewportAnchor.start,
bool itemsWrap: false,
this.children
this.children: const <Widget>[],
}) : super(
startOffset,
mainAxis,
......
......@@ -35,7 +35,7 @@ class ScrollableGrid extends StatelessWidget {
this.snapOffsetCallback,
this.scrollableKey,
@required this.delegate,
this.children
this.children: const <Widget>[],
}) : super(key: key) {
assert(delegate != null);
}
......@@ -75,6 +75,10 @@ class ScrollableGrid extends StatelessWidget {
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 @@ class GridViewport extends VirtualViewportFromIterable {
this.scrollOffset,
this.delegate,
this.onExtentsChanged,
this.children
this.children: const <Widget>[],
}) {
assert(delegate != null);
}
......@@ -140,6 +144,10 @@ class GridViewport extends VirtualViewportFromIterable {
}
/// 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.
......
......@@ -49,7 +49,7 @@ class ScrollableList extends StatelessWidget {
@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 @@ class ListViewport extends _VirtualListViewport with VirtualViewportFromIterable
@required double itemExtent,
bool itemsWrap: false,
EdgeInsets padding,
this.children
this.children: const <Widget>[],
}) : super(
onExtentsChanged,
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';
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();
......
......@@ -60,6 +60,10 @@ Future<Null> pageRight(WidgetTester tester) {
}
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());
......
......@@ -7,6 +7,12 @@ import 'package:flutter/widgets.dart';
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>();
......
// 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