Skip to content

Commit 0da8012

Browse files
authored
Fix: Closing bottom sheet and removing FAB cause assertion failure (flutter#128566)
Fixes flutter#128562
1 parent 2e05371 commit 0da8012

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,11 +1358,9 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
13581358

13591359
void _handlePreviousAnimationStatusChanged(AnimationStatus status) {
13601360
setState(() {
1361-
if (status == AnimationStatus.dismissed) {
1361+
if (widget.child != null && status == AnimationStatus.dismissed) {
13621362
assert(widget.currentController.status == AnimationStatus.dismissed);
1363-
if (widget.child != null) {
1364-
widget.currentController.forward();
1365-
}
1363+
widget.currentController.forward();
13661364
}
13671365
});
13681366
}

packages/flutter/test/material/scaffold_test.dart

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,6 +2801,65 @@ void main() {
28012801
// The scrim should be gone.
28022802
expect(findModalBarrier(), findsNothing);
28032803
});
2804+
2805+
testWidgets("Closing bottom sheet & removing FAB at the same time doesn't throw assertion", (WidgetTester tester) async {
2806+
final Key bottomSheetKey = UniqueKey();
2807+
PersistentBottomSheetController<void>? controller;
2808+
bool show = true;
2809+
2810+
await tester.pumpWidget(StatefulBuilder(
2811+
builder: (_, StateSetter setState) => MaterialApp(
2812+
home: Scaffold(
2813+
body: Center(
2814+
child: Builder(
2815+
builder: (BuildContext context) => ElevatedButton(
2816+
onPressed: () {
2817+
if (controller == null) {
2818+
controller = showBottomSheet(
2819+
context: context,
2820+
builder: (_) => Container(
2821+
key: bottomSheetKey,
2822+
height: 200,
2823+
),
2824+
);
2825+
} else {
2826+
controller!.close();
2827+
controller = null;
2828+
}
2829+
},
2830+
child: const Text('BottomSheet'),
2831+
)),
2832+
),
2833+
floatingActionButton: show
2834+
? FloatingActionButton(onPressed: () => setState(() => show = false))
2835+
: null,
2836+
),
2837+
),
2838+
));
2839+
2840+
// Show bottom sheet.
2841+
await tester.tap(find.byType(ElevatedButton));
2842+
await tester.pumpAndSettle(const Duration(seconds: 1));
2843+
2844+
// Bottom sheet and FAB are visible.
2845+
expect(find.byType(FloatingActionButton), findsOneWidget);
2846+
expect(find.byKey(bottomSheetKey), findsOneWidget);
2847+
2848+
// Close bottom sheet while removing FAB.
2849+
await tester.tap(find.byType(FloatingActionButton));
2850+
await tester.pump(); // start animation
2851+
await tester.tap(find.byType(ElevatedButton));
2852+
// Let the animation finish.
2853+
await tester.pumpAndSettle(const Duration(seconds: 1));
2854+
2855+
// Bottom sheet and FAB are gone.
2856+
expect(find.byType(FloatingActionButton), findsNothing);
2857+
expect(find.byKey(bottomSheetKey), findsNothing);
2858+
2859+
// No exception is thrown.
2860+
expect(tester.takeException(), isNull);
2861+
});
2862+
28042863
}
28052864

28062865
class _GeometryListener extends StatefulWidget {

0 commit comments

Comments
 (0)