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
61e938aa
Commit
61e938aa
authored
May 24, 2017
by
Jason Simmons
Committed by
GitHub
May 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid divide by zero in scroll thumb rectangle calculations (#10271)
parent
251d83a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
2 deletions
+53
-2
scrollbar.dart
packages/flutter/lib/src/material/scrollbar.dart
+7
-2
scrollbar_test.dart
packages/flutter/test/material/scrollbar_test.dart
+46
-0
No files found.
packages/flutter/lib/src/material/scrollbar.dart
View file @
61e938aa
...
...
@@ -156,8 +156,13 @@ class _ScrollbarPainter extends ChangeNotifier implements CustomPainter {
void
_paintThumb
(
double
before
,
double
inside
,
double
after
,
double
viewport
,
Canvas
canvas
,
Size
size
,
void
painter
(
Canvas
canvas
,
Size
size
,
double
thumbOffset
,
double
thumbExtent
))
{
final
double
thumbExtent
=
math
.
max
(
math
.
min
(
viewport
,
_kMinThumbExtent
),
viewport
*
inside
/
(
before
+
inside
+
after
));
final
double
thumbOffset
=
before
*
(
viewport
-
thumbExtent
)
/
(
before
+
after
);
double
thumbExtent
=
math
.
min
(
viewport
,
_kMinThumbExtent
);
if
(
before
+
inside
+
after
>
0.0
)
thumbExtent
=
math
.
max
(
thumbExtent
,
viewport
*
inside
/
(
before
+
inside
+
after
));
final
double
thumbOffset
=
(
before
+
after
>
0.0
)
?
before
*
(
viewport
-
thumbExtent
)
/
(
before
+
after
)
:
0.0
;
painter
(
canvas
,
size
,
thumbOffset
,
thumbExtent
);
}
...
...
packages/flutter/test/material/scrollbar_test.dart
View file @
61e938aa
...
...
@@ -6,6 +6,17 @@ import 'package:flutter/material.dart';
import
'package:flutter/scheduler.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
class
TestCanvas
implements
Canvas
{
TestCanvas
([
this
.
invocations
]);
final
List
<
Invocation
>
invocations
;
@override
void
noSuchMethod
(
Invocation
invocation
)
{
invocations
?.
add
(
invocation
);
}
}
void
main
(
)
{
testWidgets
(
'Scrollbar doesn
\'
t show when tapping list'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
...
...
@@ -48,4 +59,39 @@ void main() {
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
});
testWidgets
(
'ScrollbarPainter does not divide by zero'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
Container
(
height:
200.0
,
width:
300.0
,
child:
new
Scrollbar
(
child:
new
ListView
(
children:
<
Widget
>[
new
Container
(
height:
40.0
,
child:
const
Text
(
'0'
)),
]
)
)
)
);
final
CustomPaint
custom
=
tester
.
widget
(
find
.
descendant
(
of:
find
.
byType
(
Scrollbar
),
matching:
find
.
byType
(
CustomPaint
)).
first
);
final
dynamic
scrollPainter
=
custom
.
foregroundPainter
;
final
ScrollMetrics
metrics
=
new
FixedScrollMetrics
(
minScrollExtent:
0.0
,
maxScrollExtent:
0.0
,
pixels:
0.0
,
viewportDimension:
100.0
,
axisDirection:
AxisDirection
.
down
);
scrollPainter
.
update
(
metrics
,
AxisDirection
.
down
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
final
List
<
Invocation
>
invocations
=
<
Invocation
>[];
final
TestCanvas
canvas
=
new
TestCanvas
(
invocations
);
scrollPainter
.
paint
(
canvas
,
const
Size
(
10.0
,
100.0
));
final
Rect
thumbRect
=
invocations
.
single
.
positionalArguments
[
0
];
expect
(
thumbRect
.
isFinite
,
isTrue
);
});
}
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