Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
41a13a3a
Unverified
Commit
41a13a3a
authored
Oct 07, 2022
by
Greg Spencer
Committed by
GitHub
Oct 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `SliverGrid.builder` constructor (#113116)
parent
3eef3ff3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
3 deletions
+86
-3
scroll_view.dart
packages/flutter/lib/src/widgets/scroll_view.dart
+4
-3
sliver.dart
packages/flutter/lib/src/widgets/sliver.dart
+43
-0
slivers_test.dart
packages/flutter/test/widgets/slivers_test.dart
+39
-0
No files found.
packages/flutter/lib/src/widgets/scroll_view.dart
View file @
41a13a3a
...
...
@@ -1757,13 +1757,14 @@ class GridView extends BoxScrollView {
///
/// {@macro flutter.widgets.PageView.findChildIndexCallback}
///
/// The [gridDelegate] argument
must not be null
.
/// The [gridDelegate] argument
is required
.
///
/// The `addAutomaticKeepAlives` argument corresponds to the
/// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The
/// `addRepaintBoundaries` argument corresponds to the
/// [SliverChildBuilderDelegate.addRepaintBoundaries] property. Both must not
/// be null.
/// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The
/// `addSemanticIndexes` argument corresponds to the
/// [SliverChildBuilderDelegate.addSemanticIndexes] property.
GridView
.
builder
({
super
.
key
,
super
.
scrollDirection
,
...
...
packages/flutter/lib/src/widgets/sliver.dart
View file @
41a13a3a
...
...
@@ -1166,6 +1166,49 @@ class SliverGrid extends SliverMultiBoxAdaptorWidget {
required
this
.
gridDelegate
,
});
/// A sliver that creates a 2D array of widgets that are created on demand.
///
/// This constructor is appropriate for sliver grids with a large (or
/// infinite) number of children because the builder is called only for those
/// children that are actually visible.
///
/// Providing a non-null `itemCount` improves the ability of the [SliverGrid]
/// to estimate the maximum scroll extent.
///
/// `itemBuilder` will be called only with indices greater than or equal to
/// zero and less than `itemCount`.
///
/// {@macro flutter.widgets.ListView.builder.itemBuilder}
///
/// {@macro flutter.widgets.PageView.findChildIndexCallback}
///
/// The [gridDelegate] argument is required.
///
/// The `addAutomaticKeepAlives` argument corresponds to the
/// [SliverChildBuilderDelegate.addAutomaticKeepAlives] property. The
/// `addRepaintBoundaries` argument corresponds to the
/// [SliverChildBuilderDelegate.addRepaintBoundaries] property. The
/// `addSemanticIndexes` argument corresponds to the
/// [SliverChildBuilderDelegate.addSemanticIndexes] property.
SliverGrid
.
builder
({
super
.
key
,
required
this
.
gridDelegate
,
required
NullableIndexedWidgetBuilder
itemBuilder
,
ChildIndexGetter
?
findChildIndexCallback
,
int
?
itemCount
,
bool
addAutomaticKeepAlives
=
true
,
bool
addRepaintBoundaries
=
true
,
bool
addSemanticIndexes
=
true
,
})
:
assert
(
gridDelegate
!=
null
),
super
(
delegate:
SliverChildBuilderDelegate
(
itemBuilder
,
findChildIndexCallback:
findChildIndexCallback
,
childCount:
itemCount
,
addAutomaticKeepAlives:
addAutomaticKeepAlives
,
addRepaintBoundaries:
addRepaintBoundaries
,
addSemanticIndexes:
addSemanticIndexes
,
));
/// Creates a sliver that places multiple box children in a two dimensional
/// arrangement with a fixed number of tiles in the cross axis.
///
...
...
packages/flutter/test/widgets/slivers_test.dart
View file @
41a13a3a
...
...
@@ -991,6 +991,45 @@ void main() {
expect
(
firstTapped
,
1
);
expect
(
secondTapped
,
1
);
});
testWidgets
(
'SliverGrid.builder can build children'
,
(
WidgetTester
tester
)
async
{
int
firstTapped
=
0
;
int
secondTapped
=
0
;
final
Key
key
=
UniqueKey
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
key:
key
,
body:
CustomScrollView
(
slivers:
<
Widget
>[
SliverGrid
.
builder
(
itemCount:
2
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Material
(
color:
index
.
isEven
?
Colors
.
yellow
:
Colors
.
red
,
child:
InkWell
(
onTap:
()
{
index
.
isEven
?
firstTapped
++
:
secondTapped
++;
},
child:
Text
(
'Index
$index
'
),
),
);
},
gridDelegate:
_TestArbitrarySliverGridDelegate
(),
),
],
),
),
));
// Verify correct hit testing
await
tester
.
tap
(
find
.
text
(
'Index 0'
));
expect
(
firstTapped
,
1
);
expect
(
secondTapped
,
0
);
firstTapped
=
0
;
await
tester
.
tap
(
find
.
text
(
'Index 1'
));
expect
(
firstTapped
,
0
);
expect
(
secondTapped
,
1
);
});
}
bool
isRight
(
Offset
a
,
Offset
b
)
=>
b
.
dx
>
a
.
dx
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment