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
3b2044ab
Unverified
Commit
3b2044ab
authored
Jan 14, 2021
by
xubaolin
Committed by
GitHub
Jan 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve the Scaffold.bottomSheet update behavior (#73084)
parent
a706cd21
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
3 deletions
+39
-3
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+16
-3
persistent_bottom_sheet_test.dart
...s/flutter/test/material/persistent_bottom_sheet_test.dart
+23
-0
No files found.
packages/flutter/lib/src/material/scaffold.dart
View file @
3b2044ab
...
...
@@ -2389,6 +2389,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
// bottom sheet.
final
List
<
_StandardBottomSheet
>
_dismissedBottomSheets
=
<
_StandardBottomSheet
>[];
PersistentBottomSheetController
<
dynamic
>?
_currentBottomSheet
;
final
GlobalKey
_currentBottomSheetKey
=
GlobalKey
();
void
_maybeBuildPersistentBottomSheet
()
{
if
(
widget
.
bottomSheet
!=
null
&&
_currentBottomSheet
==
null
)
{
...
...
@@ -2421,7 +2422,10 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
return
NotificationListener
<
DraggableScrollableNotification
>(
onNotification:
_persistentBottomSheetExtentChanged
,
child:
DraggableScrollableActuator
(
child:
widget
.
bottomSheet
!,
child:
StatefulBuilder
(
key:
_currentBottomSheetKey
,
builder:
(
BuildContext
context
,
StateSetter
setState
)
=>
widget
.
bottomSheet
!,
),
),
);
},
...
...
@@ -2445,6 +2449,10 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
}
}
void
_updatePersistentBottomSheet
()
{
_currentBottomSheetKey
.
currentState
!.
setState
(()
{});
}
PersistentBottomSheetController
<
T
>
_buildBottomSheet
<
T
>(
WidgetBuilder
builder
,
bool
isPersistent
,
{
...
...
@@ -2774,8 +2782,13 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
}
return
true
;
}());
_closeCurrentBottomSheet
();
_maybeBuildPersistentBottomSheet
();
if
(
widget
.
bottomSheet
==
null
)
{
_closeCurrentBottomSheet
();
}
else
if
(
widget
.
bottomSheet
!=
null
&&
oldWidget
.
bottomSheet
==
null
)
{
_maybeBuildPersistentBottomSheet
();
}
else
{
_updatePersistentBottomSheet
();
}
}
super
.
didUpdateWidget
(
oldWidget
);
}
...
...
packages/flutter/test/material/persistent_bottom_sheet_test.dart
View file @
3b2044ab
...
...
@@ -4,6 +4,7 @@
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
void
main
(
)
{
// Pumps and ensures that the BottomSheet animates non-linearly.
...
...
@@ -475,6 +476,28 @@ void main() {
expect
(
find
.
byKey
(
bottomSheetKey
),
findsNothing
);
});
// Regression test for https://github.com/flutter/flutter/issues/71435
testWidgets
(
'Scaffold.bottomSheet should be updated without creating a new RO'
' when the new widget has the same key and type.'
,
(
WidgetTester
tester
)
async
{
Widget
buildFrame
(
String
text
)
{
return
MaterialApp
(
home:
Scaffold
(
body:
const
Placeholder
(),
bottomSheet:
Text
(
text
),
),
);
}
await
tester
.
pumpWidget
(
buildFrame
(
'I love Flutter!'
));
final
RenderParagraph
renderBeforeUpdate
=
tester
.
renderObject
(
find
.
text
(
'I love Flutter!'
));
await
tester
.
pumpWidget
(
buildFrame
(
'Flutter is the best!'
));
await
tester
.
pumpAndSettle
();
final
RenderParagraph
renderAfterUpdate
=
tester
.
renderObject
(
find
.
text
(
'Flutter is the best!'
));
expect
(
renderBeforeUpdate
,
renderAfterUpdate
);
});
testWidgets
(
'Verify that visual properties are passed through'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
ScaffoldState
>
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
const
Color
color
=
Colors
.
pink
;
...
...
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