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
fd30f631
Commit
fd30f631
authored
Feb 14, 2017
by
Adam Barth
Committed by
GitHub
Feb 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace Scrollbar with Scrollbar2 (#8133)
parent
ef004ae9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
13 additions
and
203 deletions
+13
-203
list_demo.dart
examples/flutter_gallery/lib/demo/list_demo.dart
+1
-1
about.dart
packages/flutter/lib/src/material/about.dart
+1
-1
drop_down.dart
packages/flutter/lib/src/material/drop_down.dart
+1
-1
scrollbar.dart
packages/flutter/lib/src/material/scrollbar.dart
+5
-195
scrollbar_paint_test.dart
packages/flutter/test/material/scrollbar_paint_test.dart
+3
-3
scrollbar_test.dart
packages/flutter/test/material/scrollbar_test.dart
+1
-1
slivers_evil_test.dart
packages/flutter/test/widgets/slivers_evil_test.dart
+1
-1
No files found.
examples/flutter_gallery/lib/demo/list_demo.dart
View file @
fd30f631
...
...
@@ -190,7 +190,7 @@ class ListDemoState extends State<ListDemo> {
),
],
),
body:
new
Scrollbar
2
(
body:
new
Scrollbar
(
child:
new
ListView
(
padding:
new
EdgeInsets
.
symmetric
(
vertical:
_dense
?
4.0
:
8.0
),
children:
listItems
.
toList
(),
...
...
packages/flutter/lib/src/material/about.dart
View file @
fd30f631
...
...
@@ -447,7 +447,7 @@ class _LicensePageState extends State<LicensePage> {
),
body:
new
DefaultTextStyle
(
style:
Theme
.
of
(
context
).
textTheme
.
caption
,
child:
new
Scrollbar
2
(
child:
new
Scrollbar
(
child:
new
ListView
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
8.0
,
vertical:
12.0
),
shrinkWrap:
true
,
...
...
packages/flutter/lib/src/material/drop_down.dart
View file @
fd30f631
...
...
@@ -184,7 +184,7 @@ class _DropdownMenuState<T> extends State<_DropdownMenu<T>> {
textStyle:
route
.
style
,
child:
new
ScrollConfiguration
(
delegate:
new
_DropdownScrollConfigurationDelegate
(
Theme
.
of
(
context
).
platform
),
child:
new
Scrollbar
2
(
child:
new
Scrollbar
(
child:
new
ListView
(
controller:
config
.
route
.
scrollController
,
padding:
_kMenuVerticalPadding
,
...
...
packages/flutter/lib/src/material/scrollbar.dart
View file @
fd30f631
...
...
@@ -10,22 +10,22 @@ import 'package:flutter/widgets.dart';
import
'theme.dart'
;
class
Scrollbar
2
extends
StatefulWidget
{
Scrollbar
2
({
class
Scrollbar
extends
StatefulWidget
{
Scrollbar
({
Key
key
,
this
.
child
,
})
:
super
(
key:
key
);
/// The subtree to place inside the [Scrollbar
2
]. This should include
/// The subtree to place inside the [Scrollbar]. This should include
/// a source of [ScrollNotification2] notifications, typically a [Scrollable2]
/// widget.
final
Widget
child
;
@override
_Scrollbar
2State
createState
()
=>
new
_Scrollbar2
State
();
_Scrollbar
State
createState
()
=>
new
_Scrollbar
State
();
}
class
_Scrollbar
2State
extends
State
<
Scrollbar2
>
with
TickerProviderStateMixin
{
class
_Scrollbar
State
extends
State
<
Scrollbar
>
with
TickerProviderStateMixin
{
_ScrollbarController
_controller
;
@override
...
...
@@ -179,193 +179,3 @@ class _ScrollbarPainter extends CustomPainter {
return
oldDelegate
.
controller
!=
controller
;
}
}
////////////////////////////////////////////////////////////////////////////////
// DELETE EVERYTHING BELOW THIS LINE WHEN REMOVING LEGACY SCROLLING CODE
////////////////////////////////////////////////////////////////////////////////
const
double
_kMinScrollbarThumbExtent
=
18.0
;
const
double
_kScrollbarThumbGirth
=
6.0
;
const
Duration
_kScrollbarThumbFadeDuration
=
const
Duration
(
milliseconds:
300
);
class
_Painter
extends
CustomPainter
{
_Painter
({
this
.
scrollOffset
,
this
.
scrollDirection
,
this
.
contentExtent
,
this
.
containerExtent
,
this
.
color
});
final
double
scrollOffset
;
final
Axis
scrollDirection
;
final
double
contentExtent
;
final
double
containerExtent
;
final
Color
color
;
void
paintScrollbar
(
Canvas
canvas
,
Size
size
)
{
Point
thumbOrigin
;
Size
thumbSize
;
switch
(
scrollDirection
)
{
case
Axis
.
vertical
:
double
thumbHeight
=
size
.
height
*
containerExtent
/
contentExtent
;
thumbHeight
=
thumbHeight
.
clamp
(
_kMinScrollbarThumbExtent
,
size
.
height
);
final
double
maxThumbTop
=
size
.
height
-
thumbHeight
;
double
thumbTop
=
(
scrollOffset
/
(
contentExtent
-
containerExtent
))
*
maxThumbTop
;
thumbTop
=
thumbTop
.
clamp
(
0.0
,
maxThumbTop
);
thumbOrigin
=
new
Point
(
size
.
width
-
_kScrollbarThumbGirth
,
thumbTop
);
thumbSize
=
new
Size
(
_kScrollbarThumbGirth
,
thumbHeight
);
break
;
case
Axis
.
horizontal
:
double
thumbWidth
=
size
.
width
*
containerExtent
/
contentExtent
;
thumbWidth
=
thumbWidth
.
clamp
(
_kMinScrollbarThumbExtent
,
size
.
width
);
final
double
maxThumbLeft
=
size
.
width
-
thumbWidth
;
double
thumbLeft
=
(
scrollOffset
/
(
contentExtent
-
containerExtent
))
*
maxThumbLeft
;
thumbLeft
=
thumbLeft
.
clamp
(
0.0
,
maxThumbLeft
);
thumbOrigin
=
new
Point
(
thumbLeft
,
size
.
height
-
_kScrollbarThumbGirth
);
thumbSize
=
new
Size
(
thumbWidth
,
_kScrollbarThumbGirth
);
break
;
}
final
Paint
paint
=
new
Paint
()..
color
=
color
;
canvas
.
drawRect
(
thumbOrigin
&
thumbSize
,
paint
);
}
@override
void
paint
(
Canvas
canvas
,
Size
size
)
{
if
(
scrollOffset
==
null
||
color
.
alpha
==
0
)
return
;
paintScrollbar
(
canvas
,
size
);
}
@override
bool
shouldRepaint
(
_Painter
oldPainter
)
{
return
oldPainter
.
scrollOffset
!=
scrollOffset
||
oldPainter
.
scrollDirection
!=
scrollDirection
||
oldPainter
.
contentExtent
!=
contentExtent
||
oldPainter
.
containerExtent
!=
containerExtent
||
oldPainter
.
color
!=
color
;
}
}
/// Displays a scrollbar that tracks the scrollOffset of its child's [Scrollable]
/// descendant. If the Scrollbar's child has more than one Scrollable descendant
/// the scrollableKey parameter can be used to identify the one the Scrollbar
/// should track.
class
Scrollbar
extends
StatefulWidget
{
/// Creates a scrollbar.
///
/// The child argument must not be null.
Scrollbar
({
Key
key
,
this
.
scrollableKey
,
this
.
child
})
:
super
(
key:
key
)
{
assert
(
child
!=
null
);
}
/// Identifies the [Scrollable] descendant of child that the scrollbar will
/// track. Can be null if there's only one [Scrollable] descendant.
final
Key
scrollableKey
;
/// The scrollbar will be stacked on top of this child. The scrollbar will
/// display when child's [Scrollable] descendant is scrolled.
final
Widget
child
;
@override
_ScrollbarState
createState
()
=>
new
_ScrollbarState
();
}
class
_ScrollbarState
extends
State
<
Scrollbar
>
with
SingleTickerProviderStateMixin
{
AnimationController
_fade
;
CurvedAnimation
_opacity
;
double
_scrollOffset
;
Axis
_scrollDirection
;
double
_containerExtent
;
double
_contentExtent
;
@override
void
initState
()
{
super
.
initState
();
_fade
=
new
AnimationController
(
duration:
_kScrollbarThumbFadeDuration
,
vsync:
this
);
_opacity
=
new
CurvedAnimation
(
parent:
_fade
,
curve:
Curves
.
fastOutSlowIn
);
}
@override
void
dispose
()
{
_fade
.
stop
();
super
.
dispose
();
}
void
_updateState
(
ScrollableState
scrollable
)
{
if
(
scrollable
.
scrollBehavior
is
!
ExtentScrollBehavior
)
return
;
if
(
_scrollOffset
!=
scrollable
.
scrollOffset
)
setState
(()
{
_scrollOffset
=
scrollable
.
scrollOffset
;
});
if
(
_scrollDirection
!=
scrollable
.
config
.
scrollDirection
)
setState
(()
{
_scrollDirection
=
scrollable
.
config
.
scrollDirection
;
});
final
ExtentScrollBehavior
scrollBehavior
=
scrollable
.
scrollBehavior
;
if
(
_contentExtent
!=
scrollBehavior
.
contentExtent
)
setState
(()
{
_contentExtent
=
scrollBehavior
.
contentExtent
;
});
if
(
_containerExtent
!=
scrollBehavior
.
containerExtent
)
setState
(()
{
_containerExtent
=
scrollBehavior
.
containerExtent
;
});
}
void
_onScrollStarted
(
ScrollableState
scrollable
)
{
_updateState
(
scrollable
);
}
void
_onScrollUpdated
(
ScrollableState
scrollable
)
{
_updateState
(
scrollable
);
if
(
_fade
.
status
!=
AnimationStatus
.
completed
)
_fade
.
forward
();
}
void
_onScrollEnded
(
ScrollableState
scrollable
)
{
_updateState
(
scrollable
);
_fade
.
reverse
();
}
bool
_handleScrollNotification
(
ScrollNotification
notification
)
{
if
(
config
.
scrollableKey
==
null
)
{
if
(
notification
.
depth
!=
0
)
return
false
;
}
else
if
(
config
.
scrollableKey
!=
notification
.
scrollable
.
config
.
key
)
{
return
false
;
}
final
ScrollableState
scrollable
=
notification
.
scrollable
;
switch
(
notification
.
kind
)
{
case
ScrollNotificationKind
.
started
:
_onScrollStarted
(
scrollable
);
break
;
case
ScrollNotificationKind
.
updated
:
_onScrollUpdated
(
scrollable
);
break
;
case
ScrollNotificationKind
.
ended
:
_onScrollEnded
(
scrollable
);
break
;
}
return
false
;
}
@override
Widget
build
(
BuildContext
context
)
{
return
new
NotificationListener
<
ScrollNotification
>(
onNotification:
_handleScrollNotification
,
child:
new
AnimatedBuilder
(
animation:
_opacity
,
builder:
(
BuildContext
context
,
Widget
child
)
{
return
new
CustomPaint
(
foregroundPainter:
new
_Painter
(
scrollOffset:
_scrollOffset
,
scrollDirection:
_scrollDirection
,
containerExtent:
_containerExtent
,
contentExtent:
_contentExtent
,
color:
Theme
.
of
(
context
).
highlightColor
.
withOpacity
(
_opacity
.
value
)
),
child:
child
);
},
child:
config
.
child
)
);
}
}
packages/flutter/test/material/scrollbar_paint_test.dart
View file @
fd30f631
...
...
@@ -9,13 +9,13 @@ import '../rendering/mock_canvas.dart';
void
main
(
)
{
testWidgets
(
'Viewport2 basic test'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
Scrollbar
2
(
await
tester
.
pumpWidget
(
new
Scrollbar
(
child:
new
SingleChildScrollView
(
child:
const
SizedBox
(
width:
4000.0
,
height:
4000.0
),
),
));
expect
(
find
.
byType
(
Scrollbar
2
),
isNot
(
paints
..
rect
()));
expect
(
find
.
byType
(
Scrollbar
),
isNot
(
paints
..
rect
()));
await
tester
.
fling
(
find
.
byType
(
SingleChildScrollView
),
const
Offset
(
0.0
,
-
10.0
),
10.0
);
expect
(
find
.
byType
(
Scrollbar
2
),
paints
..
rect
());
expect
(
find
.
byType
(
Scrollbar
),
paints
..
rect
());
});
}
packages/flutter/test/material/scrollbar_test.dart
View file @
fd30f631
...
...
@@ -16,7 +16,7 @@ void main() {
),
height:
200.0
,
width:
300.0
,
child:
new
Scrollbar
2
(
child:
new
Scrollbar
(
child:
new
ListView
(
children:
<
Widget
>[
new
Container
(
height:
40.0
,
child:
new
Text
(
'0'
)),
...
...
packages/flutter/test/widgets/slivers_evil_test.dart
View file @
fd30f631
...
...
@@ -74,7 +74,7 @@ void main() {
await
tester
.
pumpWidget
(
new
ScrollConfiguration2
(
behavior:
new
TestBehavior
(),
child:
new
Scrollbar
2
(
child:
new
Scrollbar
(
child:
new
Scrollable2
(
axisDirection:
AxisDirection
.
down
,
physics:
const
TestScrollPhysics
(),
...
...
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