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
f733e3a4
Unverified
Commit
f733e3a4
authored
Mar 09, 2024
by
yim
Committed by
GitHub
Mar 09, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix multiple calls to Slider's onChanged. (#143680)
Fixes #143524
parent
ff9b1a5c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
+39
-2
slider.dart
packages/flutter/lib/src/material/slider.dart
+11
-2
slider_test.dart
packages/flutter/test/material/slider_test.dart
+28
-0
No files found.
packages/flutter/lib/src/material/slider.dart
View file @
f733e3a4
...
...
@@ -612,6 +612,11 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
bool
_dragging
=
false
;
// For discrete sliders, _handleChanged might receive the same value
// multiple times. To avoid calling widget.onChanged repeatedly, the
// value from _handleChanged is temporarily saved here.
double
?
_currentChangedValue
;
FocusNode
?
_focusNode
;
FocusNode
get
focusNode
=>
widget
.
focusNode
??
_focusNode
!;
...
...
@@ -664,8 +669,11 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
void
_handleChanged
(
double
value
)
{
assert
(
widget
.
onChanged
!=
null
);
final
double
lerpValue
=
_lerp
(
value
);
if
(
lerpValue
!=
widget
.
value
)
{
widget
.
onChanged
!(
lerpValue
);
if
(
_currentChangedValue
!=
lerpValue
)
{
_currentChangedValue
=
lerpValue
;
if
(
_currentChangedValue
!=
widget
.
value
)
{
widget
.
onChanged
!(
_currentChangedValue
!);
}
}
}
...
...
@@ -676,6 +684,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
void
_handleDragEnd
(
double
value
)
{
_dragging
=
false
;
_currentChangedValue
=
null
;
widget
.
onChangeEnd
?.
call
(
_lerp
(
value
));
}
...
...
packages/flutter/test/material/slider_test.dart
View file @
f733e3a4
...
...
@@ -4253,4 +4253,32 @@ void main() {
);
});
});
// This is a regression test for https://github.com/flutter/flutter/issues/143524.
testWidgets
(
'Discrete Slider.onChanged is called only once'
,
(
WidgetTester
tester
)
async
{
int
onChangeCallbackCount
=
0
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
Slider
(
max:
5
,
divisions:
5
,
value:
0
,
onChanged:
(
double
newValue
)
{
onChangeCallbackCount
++;
},
),
),
),
),
);
final
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getTopLeft
(
find
.
byType
(
Slider
)));
await
tester
.
pump
(
kLongPressTimeout
);
await
gesture
.
moveBy
(
const
Offset
(
160.0
,
0.0
));
await
gesture
.
moveBy
(
const
Offset
(
1.0
,
0.0
));
await
gesture
.
moveBy
(
const
Offset
(
1.0
,
0.0
));
expect
(
onChangeCallbackCount
,
1
);
});
}
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