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
0322b577
Unverified
Commit
0322b577
authored
Sep 16, 2022
by
Callum Moffat
Committed by
GitHub
Sep 16, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix changing DraggableScrollableSheet controller (#111445)
parent
eae9bba7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
1 deletion
+51
-1
draggable_scrollable_sheet.dart
...s/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
+7
-1
draggable_scrollable_sheet_test.dart
...flutter/test/widgets/draggable_scrollable_sheet_test.dart
+44
-0
No files found.
packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
View file @
0322b577
...
...
@@ -663,6 +663,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
);
}
...
...
@@ -715,7 +719,9 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
_scrollController
.
extent
=
_extent
;
// If an external facing controller was provided, let it know that the
// extent has been replaced.
widget
.
controller
?.
_onExtentReplaced
(
previousExtent
);
if
(
widget
.
controller
==
oldWidget
.
controller
)
{
widget
.
controller
?.
_onExtentReplaced
(
previousExtent
);
}
if
(
widget
.
snap
&&
(
widget
.
snap
!=
oldWidget
.
snap
||
widget
.
snapSizes
!=
oldWidget
.
snapSizes
)
&&
_scrollController
.
hasClients
...
...
packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart
View file @
0322b577
...
...
@@ -1502,4 +1502,48 @@ 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
();
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
);
await
tester
.
tap
(
find
.
text
(
'Switch controller'
));
await
tester
.
pump
();
expect
(
controller1
.
isAttached
,
false
);
expect
(
controller2
.
isAttached
,
true
);
});
}
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