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
3509a1df
Unverified
Commit
3509a1df
authored
Sep 28, 2023
by
Kate Lovett
Committed by
GitHub
Sep 28, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove assertions on getOffsetToReveal (#135634)
parent
55c7a2ef
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
134 additions
and
20 deletions
+134
-20
list_wheel_viewport.dart
packages/flutter/lib/src/rendering/list_wheel_viewport.dart
+1
-4
viewport.dart
packages/flutter/lib/src/rendering/viewport.dart
+11
-7
single_child_scroll_view.dart
...ges/flutter/lib/src/widgets/single_child_scroll_view.dart
+3
-4
two_dimensional_viewport.dart
...ges/flutter/lib/src/widgets/two_dimensional_viewport.dart
+3
-4
viewport_test.dart
packages/flutter/test/rendering/viewport_test.dart
+8
-0
list_wheel_scroll_view_test.dart
...ges/flutter/test/widgets/list_wheel_scroll_view_test.dart
+31
-0
single_child_scroll_view_test.dart
...s/flutter/test/widgets/single_child_scroll_view_test.dart
+34
-0
two_dimensional_viewport_test.dart
...s/flutter/test/widgets/two_dimensional_viewport_test.dart
+43
-1
No files found.
packages/flutter/lib/src/rendering/list_wheel_viewport.dart
View file @
3509a1df
...
...
@@ -1125,11 +1125,8 @@ class RenderListWheelViewport
RenderObject
target
,
double
alignment
,
{
Rect
?
rect
,
Axis
?
axis
,
Axis
?
axis
,
// Unused, only Axis.vertical supported by this viewport.
})
{
// One dimensional viewport has only one axis, it should match if it has
// been provided.
assert
(
axis
==
null
||
axis
==
Axis
.
vertical
);
// `target` is only fully revealed when in the selected/center position. Therefore,
// this method always returns the offset that shows `target` in the center position,
// which is the same offset for all `alignment` values.
...
...
packages/flutter/lib/src/rendering/viewport.dart
View file @
3509a1df
...
...
@@ -111,9 +111,14 @@ abstract interface class RenderAbstractViewport extends RenderObject {
/// The optional [Axis] is used by
/// [RenderTwoDimensionalViewport.getOffsetToReveal] to
/// determine which of the two axes to compute an offset for. One dimensional
/// subclasses like [RenderViewportBase] and [RenderListWheelViewport] will
/// assert in debug builds if the `axis` value is provided and does not match
/// the single [Axis] that viewport is configured for.
/// subclasses like [RenderViewportBase] and [RenderListWheelViewport]
/// will ignore the `axis` value if provided, since there is only one [Axis].
///
/// If the `axis` is omitted when called on [RenderTwoDimensionalViewport],
/// the [RenderTwoDimensionalViewport.mainAxis] is used. To reveal an object
/// properly in both axes, this method should be called for each [Axis] as the
/// returned [RevealedOffset.offset] only represents the offset of one of the
/// the two [ScrollPosition]s.
///
/// See also:
///
...
...
@@ -821,10 +826,9 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
Rect
?
rect
,
Axis
?
axis
,
})
{
// One dimensional viewport has only one axis, it should match if it has
// been provided.
axis
??=
this
.
axis
;
assert
(
axis
==
this
.
axis
);
// One dimensional viewport has only one axis, override if it was
// provided/may be mismatched.
axis
=
this
.
axis
;
// Steps to convert `rect` (from a RenderBox coordinate system) to its
// scroll offset within this viewport (not in the exact order):
...
...
packages/flutter/lib/src/widgets/single_child_scroll_view.dart
View file @
3509a1df
...
...
@@ -598,10 +598,9 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix
Rect
?
rect
,
Axis
?
axis
,
})
{
// One dimensional viewport has only one axis, it should match if it has
// been provided.
axis
??=
this
.
axis
;
assert
(
axis
==
this
.
axis
);
// One dimensional viewport has only one axis, override if it was
// provided/may be mismatched.
axis
=
this
.
axis
;
rect
??=
target
.
paintBounds
;
if
(
target
is
!
RenderBox
)
{
...
...
packages/flutter/lib/src/widgets/two_dimensional_viewport.dart
View file @
3509a1df
...
...
@@ -924,11 +924,10 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA
Rect
?
rect
,
Axis
?
axis
,
})
{
// We must know which axis we are revealing for, since RevealedOffset
// refers to only one of two scroll positions.
assert
(
axis
!=
null
);
// If an axis has not been specified, use the mainAxis.
axis
??=
mainAxis
;
final
(
double
offset
,
AxisDirection
axisDirection
)
=
switch
(
axis
!
)
{
final
(
double
offset
,
AxisDirection
axisDirection
)
=
switch
(
axis
)
{
Axis
.
vertical
=>
(
verticalOffset
.
pixels
,
verticalAxisDirection
),
Axis
.
horizontal
=>
(
horizontalOffset
.
pixels
,
horizontalAxisDirection
),
};
...
...
packages/flutter/test/rendering/viewport_test.dart
View file @
3509a1df
...
...
@@ -1586,6 +1586,14 @@ void main() {
final
double
revealOffset
=
viewport
.
getOffsetToReveal
(
target
,
0.0
).
offset
;
expect
(
revealOffset
,
-(
300.0
+
padding
.
horizontal
)
*
5
+
34.0
*
2
);
});
testWidgets
(
'will not assert on mismatched axis'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
buildList
(
axis:
Axis
.
vertical
,
reverse:
true
,
reverseGrowth:
true
));
final
RenderAbstractViewport
viewport
=
tester
.
allRenderObjects
.
whereType
<
RenderAbstractViewport
>().
first
;
final
RenderObject
target
=
tester
.
renderObject
(
find
.
text
(
'Tile 0'
,
skipOffstage:
false
));
viewport
.
getOffsetToReveal
(
target
,
0.0
,
axis:
Axis
.
horizontal
);
});
});
testWidgets
(
'RenderViewportBase.showOnScreen reports the correct targetRect'
,
(
WidgetTester
tester
)
async
{
...
...
packages/flutter/test/widgets/list_wheel_scroll_view_test.dart
View file @
3509a1df
...
...
@@ -1598,6 +1598,37 @@ void main() {
expect
(
revealed
.
rect
,
const
Rect
.
fromLTWH
(
165.0
,
265.0
,
10.0
,
10.0
));
});
testWidgets
(
'will not assert on getOffsetToReveal Axis'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
SizedBox
(
height:
500.0
,
width:
300.0
,
child:
ListWheelScrollView
(
controller:
ScrollController
(
initialScrollOffset:
300.0
),
itemExtent:
100.0
,
children:
List
<
Widget
>.
generate
(
10
,
(
int
i
)
{
return
Center
(
child:
SizedBox
(
height:
50.0
,
width:
50.0
,
child:
Text
(
'Item
$i
'
),
),
);
}),
),
),
),
),
);
final
RenderListWheelViewport
viewport
=
tester
.
allRenderObjects
.
whereType
<
RenderListWheelViewport
>().
first
;
final
RenderObject
target
=
tester
.
renderObject
(
find
.
text
(
'Item 5'
));
viewport
.
getOffsetToReveal
(
target
,
0.0
,
axis:
Axis
.
horizontal
);
});
testWidgets
(
'ListWheelScrollView showOnScreen'
,
(
WidgetTester
tester
)
async
{
List
<
Widget
>
outerChildren
;
final
List
<
Widget
>
innerChildren
=
List
<
Widget
>.
generate
(
10
,
(
int
index
)
=>
Container
());
...
...
packages/flutter/test/widgets/single_child_scroll_view_test.dart
View file @
3509a1df
...
...
@@ -486,6 +486,40 @@ void main() {
expect
(
semanticsClip
.
size
.
width
,
length
);
});
testWidgetsWithLeakTracking
(
'SingleChildScrollView getOffsetToReveal - will not assert on axis mismatch'
,
(
WidgetTester
tester
)
async
{
final
ScrollController
controller
=
ScrollController
(
initialScrollOffset:
300.0
);
addTearDown
(
controller
.
dispose
);
List
<
Widget
>
children
;
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Center
(
child:
SizedBox
(
height:
200.0
,
width:
300.0
,
child:
SingleChildScrollView
(
controller:
controller
,
child:
Column
(
children:
children
=
List
<
Widget
>.
generate
(
20
,
(
int
i
)
{
return
SizedBox
(
height:
100.0
,
width:
300.0
,
child:
Text
(
'Tile
$i
'
),
);
}),
),
),
),
),
),
);
final
RenderAbstractViewport
viewport
=
tester
.
allRenderObjects
.
whereType
<
RenderAbstractViewport
>().
first
;
final
RenderObject
target
=
tester
.
renderObject
(
find
.
byWidget
(
children
[
5
]));
viewport
.
getOffsetToReveal
(
target
,
0.0
,
axis:
Axis
.
horizontal
);
});
testWidgetsWithLeakTracking
(
'SingleChildScrollView getOffsetToReveal - down'
,
(
WidgetTester
tester
)
async
{
final
ScrollController
controller
=
ScrollController
(
initialScrollOffset:
300.0
);
addTearDown
(
controller
.
dispose
);
...
...
packages/flutter/test/widgets/two_dimensional_viewport_test.dart
View file @
3509a1df
...
...
@@ -2366,11 +2366,53 @@ void main() {
);
},
variant:
TargetPlatformVariant
.
all
());
group
(
'
TwoDimensionalViewport
showOnScreen & showInViewport'
,
()
{
group
(
'showOnScreen & showInViewport'
,
()
{
Finder
findKey
(
ChildVicinity
vicinity
)
{
return
find
.
byKey
(
ValueKey
<
ChildVicinity
>(
vicinity
));
}
testWidgets
(
'getOffsetToReveal'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
simpleBuilderTest
(
useCacheExtent:
true
));
RenderAbstractViewport
viewport
=
tester
.
allRenderObjects
.
whereType
<
RenderAbstractViewport
>().
first
;
final
RevealedOffset
verticalOffset
=
viewport
.
getOffsetToReveal
(
tester
.
renderObject
(
findKey
(
const
ChildVicinity
(
xIndex:
5
,
yIndex:
5
))),
1.0
,
axis:
Axis
.
vertical
,
);
final
RevealedOffset
horizontalOffset
=
viewport
.
getOffsetToReveal
(
tester
.
renderObject
(
findKey
(
const
ChildVicinity
(
xIndex:
5
,
yIndex:
5
))),
1.0
,
axis:
Axis
.
horizontal
,
);
expect
(
verticalOffset
.
offset
,
600.0
);
expect
(
verticalOffset
.
rect
,
const
Rect
.
fromLTRB
(
1000.0
,
400.0
,
1200.0
,
600.0
));
expect
(
horizontalOffset
.
offset
,
400.0
);
expect
(
horizontalOffset
.
rect
,
const
Rect
.
fromLTRB
(
600.0
,
1000.0
,
800.0
,
1200.0
));
// default is to use mainAxis when axis is not provided, mainAxis
// defaults to Axis.vertical.
RevealedOffset
defaultOffset
=
viewport
.
getOffsetToReveal
(
tester
.
renderObject
(
findKey
(
const
ChildVicinity
(
xIndex:
5
,
yIndex:
5
))),
1.0
,
);
expect
(
defaultOffset
.
offset
,
verticalOffset
.
offset
);
expect
(
defaultOffset
.
rect
,
verticalOffset
.
rect
);
// mainAxis as Axis.horizontal
await
tester
.
pumpWidget
(
simpleBuilderTest
(
useCacheExtent:
true
,
mainAxis:
Axis
.
horizontal
,
));
viewport
=
tester
.
allRenderObjects
.
whereType
<
RenderAbstractViewport
>().
first
;
defaultOffset
=
viewport
.
getOffsetToReveal
(
tester
.
renderObject
(
findKey
(
const
ChildVicinity
(
xIndex:
5
,
yIndex:
5
))),
1.0
,
);
expect
(
defaultOffset
.
offset
,
horizontalOffset
.
offset
);
expect
(
defaultOffset
.
rect
,
horizontalOffset
.
rect
);
});
testWidgets
(
'Axis.vertical'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
simpleBuilderTest
(
useCacheExtent:
true
));
// Child visible at origin
...
...
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