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
5c522996
Unverified
Commit
5c522996
authored
Sep 29, 2022
by
xubaolin
Committed by
GitHub
Sep 29, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some DSS bugs (#112142)
parent
f22f1344
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
4 deletions
+75
-4
draggable_scrollable_sheet.dart
...s/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
+17
-4
draggable_scrollable_sheet_test.dart
...flutter/test/widgets/draggable_scrollable_sheet_test.dart
+58
-0
No files found.
packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
View file @
5c522996
...
...
@@ -201,8 +201,12 @@ class DraggableScrollableController extends ChangeNotifier {
}
}
void
_detach
()
{
_attachedController
?.
extent
.
_currentSize
.
removeListener
(
notifyListeners
);
void
_detach
({
bool
disposeExtent
=
false
})
{
if
(
disposeExtent
)
{
_attachedController
?.
extent
.
dispose
();
}
else
{
_attachedController
?.
extent
.
_currentSize
.
removeListener
(
notifyListeners
);
}
_attachedController
=
null
;
}
...
...
@@ -593,6 +597,10 @@ class _DraggableSheetExtent {
return
size
/
maxSize
*
availablePixels
;
}
void
dispose
()
{
_currentSize
.
dispose
();
}
_DraggableSheetExtent
copyWith
({
required
double
minSize
,
required
double
maxSize
,
...
...
@@ -663,6 +671,10 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
@override
void
didUpdateWidget
(
covariant
DraggableScrollableSheet
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
if
(
widget
.
controller
!=
oldWidget
.
controller
)
{
oldWidget
.
controller
?.
_detach
();
widget
.
controller
?.
_attach
(
_scrollController
);
}
_replaceExtent
(
oldWidget
);
}
...
...
@@ -695,14 +707,14 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
@override
void
dispose
()
{
widget
.
controller
?.
_detach
();
widget
.
controller
?.
_detach
(
disposeExtent:
true
);
_scrollController
.
dispose
();
super
.
dispose
();
}
void
_replaceExtent
(
covariant
DraggableScrollableSheet
oldWidget
)
{
final
_DraggableSheetExtent
previousExtent
=
_extent
;
_extent
=
_e
xtent
.
copyWith
(
_extent
=
previousE
xtent
.
copyWith
(
minSize:
widget
.
minChildSize
,
maxSize:
widget
.
maxChildSize
,
snap:
widget
.
snap
,
...
...
@@ -716,6 +728,7 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
// If an external facing controller was provided, let it know that the
// extent has been replaced.
widget
.
controller
?.
_onExtentReplaced
(
previousExtent
);
previousExtent
.
dispose
();
if
(
widget
.
snap
&&
(
widget
.
snap
!=
oldWidget
.
snap
||
widget
.
snapSizes
!=
oldWidget
.
snapSizes
)
&&
_scrollController
.
hasClients
...
...
packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart
View file @
5c522996
...
...
@@ -1512,4 +1512,62 @@ void main() {
// DraggableScrollableSheet has rebuilt, so expect the builder to be called.
expect
(
buildCount
,
2
);
});
testWidgets
(
'DraggableScrollableSheet controller can be changed'
,
(
WidgetTester
tester
)
async
{
final
DraggableScrollableController
controller1
=
DraggableScrollableController
();
final
DraggableScrollableController
controller2
=
DraggableScrollableController
();
final
List
<
double
>
loggedSizes
=
<
double
>[];
DraggableScrollableController
controller
=
controller1
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
=>
Scaffold
(
body:
DraggableScrollableSheet
(
initialChildSize:
0.25
,
snap:
true
,
snapSizes:
const
<
double
>[
0.25
,
0.5
,
1.0
],
controller:
controller
,
builder:
(
BuildContext
context
,
ScrollController
scrollController
)
{
return
ListView
(
controller:
scrollController
,
children:
<
Widget
>[
ElevatedButton
(
onPressed:
()
=>
setState
(()
{
controller
=
controller2
;
}),
child:
const
Text
(
'Switch controller'
),
),
Container
(
height:
10000
,
color:
Colors
.
blue
,
),
],
);
},
),
),
),
));
expect
(
controller1
.
isAttached
,
true
);
expect
(
controller2
.
isAttached
,
false
);
controller1
.
addListener
(()
{
loggedSizes
.
add
(
controller1
.
size
);
});
controller1
.
jumpTo
(
0.5
);
expect
(
loggedSizes
,
<
double
>[
0.5
].
map
((
double
v
)
=>
closeTo
(
v
,
precisionErrorTolerance
)));
loggedSizes
.
clear
();
await
tester
.
tap
(
find
.
text
(
'Switch controller'
));
await
tester
.
pump
();
expect
(
controller1
.
isAttached
,
false
);
expect
(
controller2
.
isAttached
,
true
);
controller2
.
addListener
(()
{
loggedSizes
.
add
(
controller2
.
size
);
});
controller2
.
jumpTo
(
1.0
);
expect
(
loggedSizes
,
<
double
>[
1.0
].
map
((
double
v
)
=>
closeTo
(
v
,
precisionErrorTolerance
)));
});
}
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