Skip to content

Commit e10310d

Browse files
authored
Reland "fix a Scaffold.bottomSheet update bug" (#106775)
1 parent cf6b91d commit e10310d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

packages/flutter/lib/src/material/scaffold.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,17 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
21242124
return false;
21252125
}
21262126

2127+
// Stop the animation and unmount the dismissed sheets from the tree immediately,
2128+
// otherwise may cause duplicate GlobalKey assertion if the sheet sub-tree contains
2129+
// GlobalKey widgets.
2130+
if (_dismissedBottomSheets.isNotEmpty) {
2131+
final List<_StandardBottomSheet> sheets = List<_StandardBottomSheet>.of(_dismissedBottomSheets, growable: false);
2132+
for (final _StandardBottomSheet sheet in sheets) {
2133+
sheet.animationController.reset();
2134+
}
2135+
assert(_dismissedBottomSheets.isEmpty);
2136+
}
2137+
21272138
_currentBottomSheet = _buildBottomSheet<void>(
21282139
(BuildContext context) {
21292140
return NotificationListener<DraggableScrollableNotification>(

packages/flutter/test/material/persistent_bottom_sheet_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ void main() {
2222
expect(dyDelta1, isNot(moreOrLessEquals(dyDelta2, epsilon: 0.1)));
2323
}
2424

25+
// Regression test for https://github.com/flutter/flutter/issues/83668
26+
testWidgets('Scaffold.bottomSheet update test', (WidgetTester tester) async {
27+
Widget buildFrame(Widget? bottomSheet) {
28+
return MaterialApp(
29+
home: Scaffold(
30+
body: const Placeholder(),
31+
bottomSheet: bottomSheet,
32+
),
33+
);
34+
}
35+
36+
await tester.pumpWidget(buildFrame(const Text('I love Flutter!')));
37+
await tester.pumpWidget(buildFrame(null));
38+
39+
// The disappearing animation has not yet been completed.
40+
await tester.pumpWidget(buildFrame(const Text('I love Flutter!')));
41+
});
42+
2543
testWidgets('Verify that a BottomSheet can be rebuilt with ScaffoldFeatureController.setState()', (WidgetTester tester) async {
2644
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
2745
int buildCount = 0;

0 commit comments

Comments
 (0)