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
61d0ca77
Commit
61d0ca77
authored
Sep 22, 2015
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1280 from Hixie/block
Fix scrolling of Block.
parents
ff586247
59f7e7f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
10 deletions
+87
-10
scrollable.dart
packages/flutter/lib/src/widgets/scrollable.dart
+23
-10
block_test.dart
packages/unit/test/widget/block_test.dart
+64
-0
No files found.
packages/flutter/lib/src/widgets/scrollable.dart
View file @
61d0ca77
...
...
@@ -277,17 +277,23 @@ class ScrollableViewport extends Scrollable {
double
_childSize
=
0.0
;
void
_handleViewportSizeChanged
(
Size
newSize
)
{
_viewportSize
=
scrollDirection
==
ScrollDirection
.
vertical
?
newSize
.
height
:
newSize
.
width
;
_updateScrollBehaviour
();
setState
(()
{
_updateScrollBehaviour
();
});
}
void
_handleChildSizeChanged
(
Size
newSize
)
{
_childSize
=
scrollDirection
==
ScrollDirection
.
vertical
?
newSize
.
height
:
newSize
.
width
;
_updateScrollBehaviour
();
setState
(()
{
_updateScrollBehaviour
();
});
}
void
_updateScrollBehaviour
()
{
// if you don't call this from build() or syncConstructorArguments(), you must call it from setState().
scrollTo
(
scrollBehavior
.
updateExtents
(
contentExtent:
_childSize
,
containerExtent:
_viewportSize
,
scrollOffset:
scrollOffset
));
scrollOffset:
scrollOffset
));
}
Widget
buildContent
()
{
...
...
@@ -423,6 +429,7 @@ abstract class ScrollableWidgetList extends Scrollable {
}
void
_updateScrollBehavior
()
{
// if you don't call this from build() or syncConstructorArguments(), you must call it from setState().
double
contentExtent
=
itemExtent
*
itemCount
;
if
(
padding
!=
null
)
contentExtent
+=
_leadingPadding
+
_trailingPadding
;
...
...
@@ -636,16 +643,22 @@ class ScrollableMixedWidgetList extends Scrollable {
OverscrollBehavior
get
scrollBehavior
=>
super
.
scrollBehavior
;
void
_handleSizeChanged
(
Size
newSize
)
{
scrollBy
(
scrollBehavior
.
updateExtents
(
containerExtent:
newSize
.
height
,
scrollOffset:
scrollOffset
));
setState
(()
{
scrollBy
(
scrollBehavior
.
updateExtents
(
containerExtent:
newSize
.
height
,
scrollOffset:
scrollOffset
));
});
}
void
_handleLayoutChanged
()
{
double
newScrollOffset
=
scrollBehavior
.
updateExtents
(
contentExtent:
layoutState
.
didReachLastChild
?
layoutState
.
contentsSize
:
double
.
INFINITY
,
scrollOffset:
scrollOffset
);
double
newScrollOffset
;
setState
(()
{
newScrollOffset
=
scrollBehavior
.
updateExtents
(
contentExtent:
layoutState
.
didReachLastChild
?
layoutState
.
contentsSize
:
double
.
INFINITY
,
scrollOffset:
scrollOffset
);
});
if
(
_contentChanged
)
{
_contentChanged
=
false
;
scrollTo
(
newScrollOffset
);
...
...
packages/unit/test/widget/block_test.dart
0 → 100644
View file @
61d0ca77
import
'package:quiver/testing/async.dart'
;
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
import
'../engine/mock_events.dart'
;
import
'widget_tester.dart'
;
final
Key
blockKey
=
new
Key
(
'test'
);
void
main
(
)
{
test
(
'Cannot scroll a non-overflowing block'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(()
{
return
new
Block
([
new
Container
(
height:
200.0
,
// less than 600, the height of the test area
child:
new
Text
(
'Hello'
)
)
],
key:
blockKey
);
});
tester
.
pumpFrameWithoutChange
();
// for SizeObservers
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
target
=
tester
.
getCenter
(
tester
.
findWidget
((
widget
)
=>
widget
.
key
==
blockKey
));
TestPointer
pointer
=
new
TestPointer
();
tester
.
dispatchEvent
(
pointer
.
down
(
target
),
target
);
tester
.
dispatchEvent
(
pointer
.
move
(
target
+
const
Offset
(
0.0
,
-
10.0
)),
target
);
tester
.
pumpFrameWithoutChange
(
1.0
);
expect
(
tester
.
getCenter
(
tester
.
findText
(
'Hello'
))
==
middleOfContainer
,
isTrue
);
tester
.
dispatchEvent
(
pointer
.
up
(),
target
);
});
test
(
'Can scroll an overflowing block'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
tester
.
pumpFrame
(()
{
return
new
Block
([
new
Container
(
height:
2000.0
,
// more than 600, the height of the test area
child:
new
Text
(
'Hello'
)
)
],
key:
blockKey
);
});
tester
.
pumpFrameWithoutChange
();
// for SizeObservers
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
target
=
tester
.
getCenter
(
tester
.
findWidget
((
widget
)
=>
widget
.
key
==
blockKey
));
TestPointer
pointer
=
new
TestPointer
();
tester
.
dispatchEvent
(
pointer
.
down
(
target
),
target
);
tester
.
dispatchEvent
(
pointer
.
move
(
target
+
const
Offset
(
0.0
,
-
10.0
)),
target
);
tester
.
pumpFrameWithoutChange
(
1.0
);
expect
(
tester
.
getCenter
(
tester
.
findText
(
'Hello'
))
==
middleOfContainer
,
isFalse
);
tester
.
dispatchEvent
(
pointer
.
up
(),
target
);
});
}
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