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
20936eea
Unverified
Commit
20936eea
authored
Sep 03, 2020
by
Kate Lovett
Committed by
GitHub
Sep 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow for arbitrary placement in SliverGrid (#64750)
parent
08e3ed9e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
2 deletions
+94
-2
sliver_grid.dart
packages/flutter/lib/src/rendering/sliver_grid.dart
+1
-2
slivers_test.dart
packages/flutter/test/widgets/slivers_test.dart
+93
-0
No files found.
packages/flutter/lib/src/rendering/sliver_grid.dart
View file @
20936eea
...
...
@@ -606,7 +606,6 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
final
int
lastIndex
=
indexOf
(
lastChild
!);
assert
(
childScrollOffset
(
firstChild
!)!
<=
scrollOffset
);
assert
(
debugAssertChildListIsNonEmptyAndContiguous
());
assert
(
indexOf
(
firstChild
!)
==
firstIndex
);
assert
(
targetLastIndex
==
null
||
lastIndex
<=
targetLastIndex
);
...
...
@@ -621,7 +620,7 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
final
double
paintExtent
=
calculatePaintOffset
(
constraints
,
from:
leadingScrollOffset
,
from:
math
.
min
(
constraints
.
scrollOffset
,
leadingScrollOffset
)
,
to:
trailingScrollOffset
,
);
final
double
cacheExtent
=
calculateCacheOffset
(
...
...
packages/flutter/test/widgets/slivers_test.dart
View file @
20936eea
...
...
@@ -877,6 +877,66 @@ void main() {
await
tester
.
pumpAndSettle
();
expect
(
tester
.
takeException
(),
isNull
);
});
testWidgets
(
'SliverGrid children can be arbitrarily placed'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/64006
int
firstTapped
=
0
;
int
secondTapped
=
0
;
final
Key
key
=
UniqueKey
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
key:
key
,
body:
CustomScrollView
(
slivers:
<
Widget
>[
SliverGrid
(
delegate:
SliverChildBuilderDelegate
(
(
BuildContext
context
,
int
index
)
{
return
Container
(
child:
Material
(
color:
index
%
2
==
0
?
Colors
.
yellow
:
Colors
.
red
,
child:
InkWell
(
onTap:
()
{
index
%
2
==
0
?
firstTapped
++
:
secondTapped
++;
},
child:
Text
(
'Index
$index
'
),
),
),
);
},
childCount:
2
,
),
gridDelegate:
_TestArbitrarySliverGridDelegate
(),
)
],
),
)
));
// Assertion not triggered by arbitrary placement
expect
(
tester
.
takeException
(),
isNull
);
// Verify correct hit testing
await
tester
.
tap
(
find
.
text
(
'Index 0'
));
expect
(
firstTapped
,
1
);
expect
(
secondTapped
,
0
);
await
tester
.
tap
(
find
.
text
(
'Index 1'
));
expect
(
firstTapped
,
1
);
expect
(
secondTapped
,
1
);
// Check other places too
final
Offset
bottomLeft
=
tester
.
getBottomLeft
(
find
.
byKey
(
key
));
await
tester
.
tapAt
(
bottomLeft
);
expect
(
firstTapped
,
1
);
expect
(
secondTapped
,
1
);
final
Offset
topRight
=
tester
.
getTopRight
(
find
.
byKey
(
key
));
await
tester
.
tapAt
(
topRight
);
expect
(
firstTapped
,
1
);
expect
(
secondTapped
,
1
);
await
tester
.
tapAt
(
const
Offset
(
100.0
,
100.0
));
expect
(
firstTapped
,
1
);
expect
(
secondTapped
,
1
);
await
tester
.
tapAt
(
const
Offset
(
700.0
,
500.0
));
expect
(
firstTapped
,
1
);
expect
(
secondTapped
,
1
);
});
}
bool
isRight
(
Offset
a
,
Offset
b
)
=>
b
.
dx
>
a
.
dx
;
...
...
@@ -909,6 +969,39 @@ class TestSliverGrid extends StatelessWidget {
}
}
class
_TestArbitrarySliverGridDelegate
implements
SliverGridDelegate
{
@override
SliverGridLayout
getLayout
(
SliverConstraints
constraints
)
{
return
_TestArbitrarySliverGridLayout
();
}
@override
bool
shouldRelayout
(
SliverGridDelegate
oldDelegate
)
{
return
false
;
}
}
class
_TestArbitrarySliverGridLayout
implements
SliverGridLayout
{
@override
double
computeMaxScrollOffset
(
int
childCount
)
=>
1000
;
@override
int
getMinChildIndexForScrollOffset
(
double
scrollOffset
)
=>
0
;
@override
int
getMaxChildIndexForScrollOffset
(
double
scrollOffset
)
=>
2
;
@override
SliverGridGeometry
getGeometryForChildIndex
(
int
index
)
{
return
SliverGridGeometry
(
scrollOffset:
index
*
100.0
+
300.0
,
crossAxisOffset:
200.0
,
mainAxisExtent:
100.0
,
crossAxisExtent:
100.0
,
);
}
}
class
TestSliverFixedExtentList
extends
StatelessWidget
{
const
TestSliverFixedExtentList
(
this
.
children
,
{
Key
key
})
:
super
(
key:
key
);
...
...
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