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
bc7d3bbc
Unverified
Commit
bc7d3bbc
authored
Apr 26, 2022
by
Bruno Leroux
Committed by
GitHub
Apr 26, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix DraggableScrollableController.animateTo leaks Ticker (#102504)
parent
646b910c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
draggable_scrollable_sheet.dart
...s/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
+17
-0
draggable_scrollable_sheet_test.dart
...flutter/test/widgets/draggable_scrollable_sheet_test.dart
+15
-0
No files found.
packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
View file @
bc7d3bbc
...
@@ -52,6 +52,7 @@ typedef ScrollableWidgetBuilder = Widget Function(
...
@@ -52,6 +52,7 @@ typedef ScrollableWidgetBuilder = Widget Function(
/// constraints provided to an attached sheet change.
/// constraints provided to an attached sheet change.
class
DraggableScrollableController
extends
ChangeNotifier
{
class
DraggableScrollableController
extends
ChangeNotifier
{
_DraggableScrollableSheetScrollController
?
_attachedController
;
_DraggableScrollableSheetScrollController
?
_attachedController
;
final
Set
<
AnimationController
>
_animationControllers
=
<
AnimationController
>{};
/// Get the current size (as a fraction of the parent height) of the attached sheet.
/// Get the current size (as a fraction of the parent height) of the attached sheet.
double
get
size
{
double
get
size
{
...
@@ -115,6 +116,7 @@ class DraggableScrollableController extends ChangeNotifier {
...
@@ -115,6 +116,7 @@ class DraggableScrollableController extends ChangeNotifier {
vsync:
_attachedController
!.
position
.
context
.
vsync
,
vsync:
_attachedController
!.
position
.
context
.
vsync
,
value:
_attachedController
!.
extent
.
currentSize
,
value:
_attachedController
!.
extent
.
currentSize
,
);
);
_animationControllers
.
add
(
animationController
);
_attachedController
!.
position
.
goIdle
();
_attachedController
!.
position
.
goIdle
();
// This disables any snapping until the next user interaction with the sheet.
// This disables any snapping until the next user interaction with the sheet.
_attachedController
!.
extent
.
hasDragged
=
false
;
_attachedController
!.
extent
.
hasDragged
=
false
;
...
@@ -175,6 +177,7 @@ class DraggableScrollableController extends ChangeNotifier {
...
@@ -175,6 +177,7 @@ class DraggableScrollableController extends ChangeNotifier {
assert
(
_attachedController
==
null
,
'Draggable scrollable controller is already attached to a sheet.'
);
assert
(
_attachedController
==
null
,
'Draggable scrollable controller is already attached to a sheet.'
);
_attachedController
=
scrollController
;
_attachedController
=
scrollController
;
_attachedController
!.
extent
.
_currentSize
.
addListener
(
notifyListeners
);
_attachedController
!.
extent
.
_currentSize
.
addListener
(
notifyListeners
);
_attachedController
!.
onPositionDetached
=
_disposeAnimationControllers
;
}
}
void
_onExtentReplaced
(
_DraggableSheetExtent
previousExtent
)
{
void
_onExtentReplaced
(
_DraggableSheetExtent
previousExtent
)
{
...
@@ -193,6 +196,13 @@ class DraggableScrollableController extends ChangeNotifier {
...
@@ -193,6 +196,13 @@ class DraggableScrollableController extends ChangeNotifier {
_attachedController
?.
extent
.
_currentSize
.
removeListener
(
notifyListeners
);
_attachedController
?.
extent
.
_currentSize
.
removeListener
(
notifyListeners
);
_attachedController
=
null
;
_attachedController
=
null
;
}
}
void
_disposeAnimationControllers
()
{
for
(
final
AnimationController
animationController
in
_animationControllers
)
{
animationController
.
dispose
();
}
_animationControllers
.
clear
();
}
}
}
/// A container for a [Scrollable] that responds to drag gestures by resizing
/// A container for a [Scrollable] that responds to drag gestures by resizing
...
@@ -724,6 +734,7 @@ class _DraggableScrollableSheetScrollController extends ScrollController {
...
@@ -724,6 +734,7 @@ class _DraggableScrollableSheetScrollController extends ScrollController {
})
:
assert
(
extent
!=
null
);
})
:
assert
(
extent
!=
null
);
_DraggableSheetExtent
extent
;
_DraggableSheetExtent
extent
;
VoidCallback
?
onPositionDetached
;
@override
@override
_DraggableScrollableSheetScrollPosition
createScrollPosition
(
_DraggableScrollableSheetScrollPosition
createScrollPosition
(
...
@@ -764,6 +775,12 @@ class _DraggableScrollableSheetScrollController extends ScrollController {
...
@@ -764,6 +775,12 @@ class _DraggableScrollableSheetScrollController extends ScrollController {
}
}
extent
.
updateSize
(
extent
.
initialSize
,
position
.
context
.
notificationContext
!);
extent
.
updateSize
(
extent
.
initialSize
,
position
.
context
.
notificationContext
!);
}
}
@override
void
detach
(
ScrollPosition
position
)
{
onPositionDetached
?.
call
();
super
.
detach
(
position
);
}
}
}
/// A scroll position that manages scroll activities for
/// A scroll position that manages scroll activities for
...
...
packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart
View file @
bc7d3bbc
...
@@ -1209,4 +1209,19 @@ void main() {
...
@@ -1209,4 +1209,19 @@ void main() {
expect
(
controller
.
isAttached
,
true
);
expect
(
controller
.
isAttached
,
true
);
expect
(
controller
.
size
,
isNotNull
);
expect
(
controller
.
size
,
isNotNull
);
});
});
testWidgets
(
'DraggableScrollableController.animateTo should not leak Ticker'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/102483
final
DraggableScrollableController
controller
=
DraggableScrollableController
();
await
tester
.
pumpWidget
(
_boilerplate
(()
{},
controller:
controller
));
controller
.
animateTo
(
0.0
,
curve:
Curves
.
linear
,
duration:
const
Duration
(
milliseconds:
200
));
await
tester
.
pump
();
// Dispose the DraggableScrollableSheet
await
tester
.
pumpWidget
(
const
SizedBox
.
shrink
());
// Controller should be detached and no exception should be thrown
expect
(
controller
.
isAttached
,
false
);
expect
(
tester
.
takeException
(),
isNull
);
});
}
}
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