Unverified Commit e10310d2 authored by xubaolin's avatar xubaolin Committed by GitHub

Reland "fix a Scaffold.bottomSheet update bug" (#106775)

parent cf6b91d0
...@@ -2124,6 +2124,17 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto ...@@ -2124,6 +2124,17 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
return false; 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>( _currentBottomSheet = _buildBottomSheet<void>(
(BuildContext context) { (BuildContext context) {
return NotificationListener<DraggableScrollableNotification>( return NotificationListener<DraggableScrollableNotification>(
......
...@@ -22,6 +22,24 @@ void main() { ...@@ -22,6 +22,24 @@ void main() {
expect(dyDelta1, isNot(moreOrLessEquals(dyDelta2, epsilon: 0.1))); 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 { testWidgets('Verify that a BottomSheet can be rebuilt with ScaffoldFeatureController.setState()', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
int buildCount = 0; int buildCount = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment