Add a non-null builder assert to Builders, renamed IndexedBuilder (#3694)
This commit is contained in:
parent
b38927e70e
commit
1a2f19b7fa
@ -52,6 +52,7 @@ class BottomSheet extends StatefulWidget {
|
|||||||
this.builder
|
this.builder
|
||||||
}) : super(key: key) {
|
}) : super(key: key) {
|
||||||
assert(onClosing != null);
|
assert(onClosing != null);
|
||||||
|
assert(builder != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The animation that controls the bottom sheet's position.
|
/// The animation that controls the bottom sheet's position.
|
||||||
|
@ -2893,7 +2893,9 @@ class KeyedSubtree extends StatelessWidget {
|
|||||||
|
|
||||||
/// A platonic widget that invokes a closure to obtain its child widget.
|
/// A platonic widget that invokes a closure to obtain its child widget.
|
||||||
class Builder extends StatelessWidget {
|
class Builder extends StatelessWidget {
|
||||||
Builder({ Key key, this.builder }) : super(key: key);
|
Builder({ Key key, this.builder }) : super(key: key) {
|
||||||
|
assert(builder != null);
|
||||||
|
}
|
||||||
|
|
||||||
/// Called to obtain the child widget.
|
/// Called to obtain the child widget.
|
||||||
///
|
///
|
||||||
@ -2910,7 +2912,9 @@ class Builder extends StatelessWidget {
|
|||||||
|
|
||||||
typedef Widget StatefulWidgetBuilder(BuildContext context, StateSetter setState);
|
typedef Widget StatefulWidgetBuilder(BuildContext context, StateSetter setState);
|
||||||
class StatefulBuilder extends StatefulWidget {
|
class StatefulBuilder extends StatefulWidget {
|
||||||
StatefulBuilder({ Key key, this.builder }) : super(key: key);
|
StatefulBuilder({ Key key, this.builder }) : super(key: key) {
|
||||||
|
assert(builder != null);
|
||||||
|
}
|
||||||
|
|
||||||
final StatefulWidgetBuilder builder;
|
final StatefulWidgetBuilder builder;
|
||||||
|
|
||||||
|
@ -348,6 +348,7 @@ class _DragTargetState<T> extends State<DragTarget<T>> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
assert(config.builder != null);
|
||||||
return new MetaData(
|
return new MetaData(
|
||||||
metaData: this,
|
metaData: this,
|
||||||
behavior: HitTestBehavior.translucent,
|
behavior: HitTestBehavior.translucent,
|
||||||
|
@ -1472,7 +1472,7 @@ abstract class BuildableElement extends Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef Widget WidgetBuilder(BuildContext context);
|
typedef Widget WidgetBuilder(BuildContext context);
|
||||||
typedef Widget IndexedBuilder(BuildContext context, int index);
|
typedef Widget IndexedWidgetBuilder(BuildContext context, int index);
|
||||||
|
|
||||||
// See ComponentElement._builder.
|
// See ComponentElement._builder.
|
||||||
Widget _buildNothing(BuildContext context) => null;
|
Widget _buildNothing(BuildContext context) => null;
|
||||||
|
@ -17,7 +17,9 @@ typedef Widget LayoutWidgetBuilder(BuildContext context, Size size);
|
|||||||
/// when the parent constrains the child's size and doesn't depend on the child's
|
/// when the parent constrains the child's size and doesn't depend on the child's
|
||||||
/// intrinsic size.
|
/// intrinsic size.
|
||||||
class LayoutBuilder extends RenderObjectWidget {
|
class LayoutBuilder extends RenderObjectWidget {
|
||||||
LayoutBuilder({ Key key, this.builder }) : super(key: key);
|
LayoutBuilder({ Key key, this.builder }) : super(key: key) {
|
||||||
|
assert(builder != null);
|
||||||
|
}
|
||||||
|
|
||||||
/// Called at layout time to construct the widget tree. The builder must not
|
/// Called at layout time to construct the widget tree. The builder must not
|
||||||
/// return null.
|
/// return null.
|
||||||
|
@ -15,7 +15,7 @@ import 'scroll_behavior.dart';
|
|||||||
/// Provides children for [LazyBlock] or [LazyBlockViewport].
|
/// Provides children for [LazyBlock] or [LazyBlockViewport].
|
||||||
///
|
///
|
||||||
/// See also [LazyBlockBuilder] for an implementation of LazyBlockDelegate based
|
/// See also [LazyBlockBuilder] for an implementation of LazyBlockDelegate based
|
||||||
/// on an [IndexedBuilder] closure.
|
/// on an [IndexedWidgetBuilder] closure.
|
||||||
abstract class LazyBlockDelegate {
|
abstract class LazyBlockDelegate {
|
||||||
/// Abstract const constructor. This constructor enables subclasses to provide
|
/// Abstract const constructor. This constructor enables subclasses to provide
|
||||||
/// const constructors so that they can be used in const expressions.
|
/// const constructors so that they can be used in const expressions.
|
||||||
@ -49,7 +49,7 @@ abstract class LazyBlockDelegate {
|
|||||||
bool shouldRebuild(LazyBlockDelegate oldDelegate);
|
bool shouldRebuild(LazyBlockDelegate oldDelegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uses an [IndexedBuilder] to provide children for [LazyBlock].
|
/// Uses an [IndexedWidgetBuilder] to provide children for [LazyBlock].
|
||||||
///
|
///
|
||||||
/// A LazyBlockBuilder rebuilds the children whenever the [LazyBlock] is
|
/// A LazyBlockBuilder rebuilds the children whenever the [LazyBlock] is
|
||||||
/// rebuilt, similar to the behavior of [Builder].
|
/// rebuilt, similar to the behavior of [Builder].
|
||||||
@ -65,13 +65,13 @@ class LazyBlockBuilder extends LazyBlockDelegate {
|
|||||||
///
|
///
|
||||||
/// This function might be called with index parameters in any order. This
|
/// This function might be called with index parameters in any order. This
|
||||||
/// function should return null for indices that exceed the number of children
|
/// function should return null for indices that exceed the number of children
|
||||||
/// provided by this delegate. If this function must not return a null value
|
/// provided by this delegate. This function must not return a null value
|
||||||
/// for an index if it previously returned a non-null value for that index or
|
/// for an index if it previously returned a non-null value for that index or
|
||||||
/// a larger index.
|
/// a larger index.
|
||||||
///
|
///
|
||||||
/// This function might be called during the build or layout phases of the
|
/// This function might be called during the build or layout phases of the
|
||||||
/// pipeline.
|
/// pipeline.
|
||||||
final IndexedBuilder builder;
|
final IndexedWidgetBuilder builder;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, int index) => builder(context, index);
|
Widget buildItem(BuildContext context, int index) => builder(context, index);
|
||||||
@ -478,7 +478,7 @@ class _LazyBlockElement extends RenderObjectElement {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void performRebuild() {
|
void performRebuild() {
|
||||||
IndexedBuilder builder = widget.delegate.buildItem;
|
IndexedWidgetBuilder builder = widget.delegate.buildItem;
|
||||||
List<Widget> widgets = <Widget>[];
|
List<Widget> widgets = <Widget>[];
|
||||||
for (int i = 0; i < _children.length; ++i) {
|
for (int i = 0; i < _children.length; ++i) {
|
||||||
int logicalIndex = _firstChildLogicalIndex + i;
|
int logicalIndex = _firstChildLogicalIndex + i;
|
||||||
@ -494,7 +494,7 @@ class _LazyBlockElement extends RenderObjectElement {
|
|||||||
void _layout(BoxConstraints constraints) {
|
void _layout(BoxConstraints constraints) {
|
||||||
final double blockExtent = _getMainAxisExtent(renderObject.size);
|
final double blockExtent = _getMainAxisExtent(renderObject.size);
|
||||||
|
|
||||||
final IndexedBuilder builder = widget.delegate.buildItem;
|
final IndexedWidgetBuilder builder = widget.delegate.buildItem;
|
||||||
final double startLogicalOffset = widget.startOffset;
|
final double startLogicalOffset = widget.startOffset;
|
||||||
final double endLogicalOffset = startLogicalOffset + blockExtent;
|
final double endLogicalOffset = startLogicalOffset + blockExtent;
|
||||||
final _RenderLazyBlock block = renderObject;
|
final _RenderLazyBlock block = renderObject;
|
||||||
|
@ -44,7 +44,9 @@ class OverlayEntry {
|
|||||||
OverlayEntry({
|
OverlayEntry({
|
||||||
this.builder,
|
this.builder,
|
||||||
bool opaque: false
|
bool opaque: false
|
||||||
}) : _opaque = opaque;
|
}) : _opaque = opaque {
|
||||||
|
assert(builder != null);
|
||||||
|
}
|
||||||
|
|
||||||
/// This entry will include the widget built by this builder in the overlay at the entry's position.
|
/// This entry will include the widget built by this builder in the overlay at the entry's position.
|
||||||
///
|
///
|
||||||
|
@ -36,7 +36,9 @@ class TextSelectionHandles {
|
|||||||
this.renderObject,
|
this.renderObject,
|
||||||
this.onSelectionHandleChanged,
|
this.onSelectionHandleChanged,
|
||||||
this.builder
|
this.builder
|
||||||
}): _selection = selection;
|
}): _selection = selection {
|
||||||
|
assert(builder != null);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(mpcomplete): what if the renderObject is removed or replaced, or
|
// TODO(mpcomplete): what if the renderObject is removed or replaced, or
|
||||||
// moves? Not sure what cases I need to handle, or how to handle them.
|
// moves? Not sure what cases I need to handle, or how to handle them.
|
||||||
|
@ -349,7 +349,9 @@ class AnimatedBuilder extends AnimatedWidget {
|
|||||||
Animation<Object> animation,
|
Animation<Object> animation,
|
||||||
this.builder,
|
this.builder,
|
||||||
this.child
|
this.child
|
||||||
}) : super(key: key, animation: animation);
|
}) : super(key: key, animation: animation) {
|
||||||
|
assert(builder != null);
|
||||||
|
}
|
||||||
|
|
||||||
/// Called every time the animation changes value.
|
/// Called every time the animation changes value.
|
||||||
final TransitionBuilder builder;
|
final TransitionBuilder builder;
|
||||||
|
@ -61,7 +61,7 @@ void main() {
|
|||||||
|
|
||||||
double offset = 300.0;
|
double offset = 300.0;
|
||||||
|
|
||||||
IndexedBuilder itemBuilder = (BuildContext context, int i) {
|
IndexedWidgetBuilder itemBuilder = (BuildContext context, int i) {
|
||||||
callbackTracker.add(i);
|
callbackTracker.add(i);
|
||||||
return new Container(
|
return new Container(
|
||||||
key: new ValueKey<int>(i),
|
key: new ValueKey<int>(i),
|
||||||
@ -111,7 +111,7 @@ void main() {
|
|||||||
|
|
||||||
double offset = 300.0;
|
double offset = 300.0;
|
||||||
|
|
||||||
IndexedBuilder itemBuilder = (BuildContext context, int i) {
|
IndexedWidgetBuilder itemBuilder = (BuildContext context, int i) {
|
||||||
callbackTracker.add(i);
|
callbackTracker.add(i);
|
||||||
return new Container(
|
return new Container(
|
||||||
key: new ValueKey<int>(i),
|
key: new ValueKey<int>(i),
|
||||||
@ -158,7 +158,7 @@ void main() {
|
|||||||
List<int> callbackTracker = <int>[];
|
List<int> callbackTracker = <int>[];
|
||||||
List<String> text = <String>[];
|
List<String> text = <String>[];
|
||||||
|
|
||||||
IndexedBuilder itemBuilder = (BuildContext context, int i) {
|
IndexedWidgetBuilder itemBuilder = (BuildContext context, int i) {
|
||||||
callbackTracker.add(i);
|
callbackTracker.add(i);
|
||||||
return new Container(
|
return new Container(
|
||||||
key: new ValueKey<int>(i),
|
key: new ValueKey<int>(i),
|
||||||
@ -201,7 +201,7 @@ void main() {
|
|||||||
StateSetter setState;
|
StateSetter setState;
|
||||||
ThemeData themeData = new ThemeData.light();
|
ThemeData themeData = new ThemeData.light();
|
||||||
|
|
||||||
IndexedBuilder itemBuilder = (BuildContext context, int i) {
|
IndexedWidgetBuilder itemBuilder = (BuildContext context, int i) {
|
||||||
return new Container(
|
return new Container(
|
||||||
key: new ValueKey<int>(i),
|
key: new ValueKey<int>(i),
|
||||||
width: 500.0, // this should be ignored
|
width: 500.0, // this should be ignored
|
||||||
@ -242,7 +242,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('LazyBlockViewport padding', (WidgetTester tester) {
|
testWidgets('LazyBlockViewport padding', (WidgetTester tester) {
|
||||||
IndexedBuilder itemBuilder = (BuildContext context, int i) {
|
IndexedWidgetBuilder itemBuilder = (BuildContext context, int i) {
|
||||||
return new Container(
|
return new Container(
|
||||||
key: new ValueKey<int>(i),
|
key: new ValueKey<int>(i),
|
||||||
width: 500.0, // this should be ignored
|
width: 500.0, // this should be ignored
|
||||||
|
Loading…
x
Reference in New Issue
Block a user