Skip to content

Commit

Permalink
Reland "fix a Scaffold.bottomSheet update bug" (#106775)
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-baolin committed Jun 30, 2022
1 parent cf6b91d commit e10310d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/flutter/lib/src/material/scaffold.dart
Expand Up @@ -2124,6 +2124,17 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
return false;
}

// Stop the animation and unmount the dismissed sheets from the tree immediately,
// otherwise may cause duplicate GlobalKey assertion if the sheet sub-tree contains
// GlobalKey widgets.
if (_dismissedBottomSheets.isNotEmpty) {
final List<_StandardBottomSheet> sheets = List<_StandardBottomSheet>.of(_dismissedBottomSheets, growable: false);
for (final _StandardBottomSheet sheet in sheets) {
sheet.animationController.reset();
}
assert(_dismissedBottomSheets.isEmpty);
}

_currentBottomSheet = _buildBottomSheet<void>(
(BuildContext context) {
return NotificationListener<DraggableScrollableNotification>(
Expand Down
18 changes: 18 additions & 0 deletions packages/flutter/test/material/persistent_bottom_sheet_test.dart
Expand Up @@ -22,6 +22,24 @@ void main() {
expect(dyDelta1, isNot(moreOrLessEquals(dyDelta2, epsilon: 0.1)));
}

// Regression test for https://github.com/flutter/flutter/issues/83668
testWidgets('Scaffold.bottomSheet update test', (WidgetTester tester) async {
Widget buildFrame(Widget? bottomSheet) {
return MaterialApp(
home: Scaffold(
body: const Placeholder(),
bottomSheet: bottomSheet,
),
);
}

await tester.pumpWidget(buildFrame(const Text('I love Flutter!')));
await tester.pumpWidget(buildFrame(null));

// The disappearing animation has not yet been completed.
await tester.pumpWidget(buildFrame(const Text('I love Flutter!')));
});

testWidgets('Verify that a BottomSheet can be rebuilt with ScaffoldFeatureController.setState()', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
int buildCount = 0;
Expand Down

0 comments on commit e10310d

Please sign in to comment.