@@ -1114,13 +1114,22 @@ class ListView extends BoxScrollView {
1114
1114
/// The `itemBuilder` callback will be called only with indices greater than
1115
1115
/// or equal to zero and less than `itemCount` .
1116
1116
///
1117
- /// The `itemBuilder` should always return a non-null widget, and actually
1118
- /// create the widget instances when called. Avoid using a builder that
1119
- /// returns a previously-constructed widget; if the list view's children are
1120
- /// created in advance, or all at once when the [ListView] itself is created,
1121
- /// it is more efficient to use the [ListView] constructor. Even more
1122
- /// efficient, however, is to create the instances on demand using this
1123
- /// constructor's `itemBuilder` callback.
1117
+ /// {@template flutter.widgets.ListView.builder.itemBuilder}
1118
+ /// It is legal for `itemBuilder` to return `null` . If it does, the scroll view
1119
+ /// will stop calling `itemBuilder` , even if it has yet to reach `itemCount` .
1120
+ /// By returning `null` , the [ScrollPosition.maxScrollExtent] will not be accurate
1121
+ /// unless the user has reached the end of the [ScrollView] . This can also cause the
1122
+ /// [Scrollbar] to grow as the user scrolls.
1123
+ ///
1124
+ /// For more accurate [ScrollMetrics] , consider specifying `itemCount` .
1125
+ /// {@endtemplate}
1126
+ ///
1127
+ /// The `itemBuilder` should always create the widget instances when called.
1128
+ /// Avoid using a builder that returns a previously-constructed widget; if the
1129
+ /// list view's children are created in advance, or all at once when the
1130
+ /// [ListView] itself is created, it is more efficient to use the [ListView]
1131
+ /// constructor. Even more efficient, however, is to create the instances on
1132
+ /// demand using this constructor's `itemBuilder` callback.
1124
1133
///
1125
1134
/// {@macro flutter.widgets.PageView.findChildIndexCallback}
1126
1135
///
@@ -1142,7 +1151,7 @@ class ListView extends BoxScrollView {
1142
1151
super .padding,
1143
1152
this .itemExtent,
1144
1153
this .prototypeItem,
1145
- required IndexedWidgetBuilder itemBuilder,
1154
+ required NullableIndexedWidgetBuilder itemBuilder,
1146
1155
ChildIndexGetter ? findChildIndexCallback,
1147
1156
int ? itemCount,
1148
1157
bool addAutomaticKeepAlives = true ,
@@ -1188,11 +1197,13 @@ class ListView extends BoxScrollView {
1188
1197
/// The `separatorBuilder` callback will be called with indices greater than
1189
1198
/// or equal to zero and less than `itemCount - 1` .
1190
1199
///
1191
- /// The `itemBuilder` and `separatorBuilder` callbacks should always return a
1192
- /// non-null widget, and actually create widget instances when called. Avoid
1193
- /// using a builder that returns a previously-constructed widget; if the list
1194
- /// view's children are created in advance, or all at once when the [ListView]
1195
- /// itself is created, it is more efficient to use the [ListView] constructor.
1200
+ /// The `itemBuilder` and `separatorBuilder` callbacks should always
1201
+ /// actually create widget instances when called. Avoid using a builder that
1202
+ /// returns a previously-constructed widget; if the list view's children are
1203
+ /// created in advance, or all at once when the [ListView] itself is created,
1204
+ /// it is more efficient to use the [ListView] constructor.
1205
+ ///
1206
+ /// {@macro flutter.widgets.ListView.builder.itemBuilder}
1196
1207
///
1197
1208
/// {@macro flutter.widgets.PageView.findChildIndexCallback}
1198
1209
///
@@ -1230,7 +1241,7 @@ class ListView extends BoxScrollView {
1230
1241
super .physics,
1231
1242
super .shrinkWrap,
1232
1243
super .padding,
1233
- required IndexedWidgetBuilder itemBuilder,
1244
+ required NullableIndexedWidgetBuilder itemBuilder,
1234
1245
ChildIndexGetter ? findChildIndexCallback,
1235
1246
required IndexedWidgetBuilder separatorBuilder,
1236
1247
required int itemCount,
@@ -1250,7 +1261,7 @@ class ListView extends BoxScrollView {
1250
1261
childrenDelegate = SliverChildBuilderDelegate (
1251
1262
(BuildContext context, int index) {
1252
1263
final int itemIndex = index ~ / 2 ;
1253
- final Widget widget;
1264
+ final Widget ? widget;
1254
1265
if (index.isEven) {
1255
1266
widget = itemBuilder (context, itemIndex);
1256
1267
} else {
@@ -1742,6 +1753,8 @@ class GridView extends BoxScrollView {
1742
1753
/// `itemBuilder` will be called only with indices greater than or equal to
1743
1754
/// zero and less than `itemCount` .
1744
1755
///
1756
+ /// {@macro flutter.widgets.ListView.builder.itemBuilder}
1757
+ ///
1745
1758
/// {@macro flutter.widgets.PageView.findChildIndexCallback}
1746
1759
///
1747
1760
/// The [gridDelegate] argument must not be null.
@@ -1761,7 +1774,7 @@ class GridView extends BoxScrollView {
1761
1774
super .shrinkWrap,
1762
1775
super .padding,
1763
1776
required this .gridDelegate,
1764
- required IndexedWidgetBuilder itemBuilder,
1777
+ required NullableIndexedWidgetBuilder itemBuilder,
1765
1778
ChildIndexGetter ? findChildIndexCallback,
1766
1779
int ? itemCount,
1767
1780
bool addAutomaticKeepAlives = true ,
0 commit comments