Skip to content

Commit 76ae988

Browse files
fix: update _floatingActionButtonVisibility only if floatingActionButton is not null
1 parent 8a4179e commit 76ae988

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3249,7 +3249,9 @@ class _StandardBottomSheetState extends State<_StandardBottomSheet> {
32493249
_kMaxBottomSheetScrimOpacity - scaffold._floatingActionButtonVisibilityValue,
32503250
));
32513251
} else {
3252-
scaffold._floatingActionButtonVisibilityValue = 1.0;
3252+
if (scaffold.widget.floatingActionButton != null) {
3253+
scaffold._floatingActionButtonVisibilityValue = 1.0;
3254+
}
32533255
scaffold.showBodyScrim(false, 0.0);
32543256
}
32553257
// If the Scaffold.bottomSheet != null, we're a persistent bottom sheet.

packages/flutter/test/material/scaffold_test.dart

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,6 +3395,83 @@ void main() {
33953395
// FAB is not visible.
33963396
expect(find.byType(FloatingActionButton), findsNothing);
33973397
});
3398+
3399+
testWidgets('fix _floatingActionButtonVisibility update',
3400+
(WidgetTester tester) async {
3401+
final List<String> log = <String>[];
3402+
3403+
bool expanded = true;
3404+
final DraggableScrollableController controller =
3405+
DraggableScrollableController();
3406+
addTearDown(controller.dispose);
3407+
await tester.pumpWidget(
3408+
MaterialApp(
3409+
home: StatefulBuilder(
3410+
builder:
3411+
(BuildContext context, void Function(void Function()) setState) {
3412+
return Scaffold(
3413+
bottomSheet: expanded
3414+
? DraggableScrollableSheet(
3415+
expand: false,
3416+
snap: true,
3417+
initialChildSize: 0.25,
3418+
maxChildSize: 0.5,
3419+
snapSizes: const <double>[0.5],
3420+
controller: controller,
3421+
builder: (BuildContext context,
3422+
ScrollController scrollController) {
3423+
return SingleChildScrollView(
3424+
controller: scrollController,
3425+
child: Column(
3426+
children: <Widget>[
3427+
TextButton(
3428+
onPressed: () {
3429+
controller.animateTo(
3430+
0.5,
3431+
duration: Durations.short4,
3432+
curve: Curves.easeIn,
3433+
);
3434+
},
3435+
child: const Text('Toggle'),
3436+
)
3437+
],
3438+
),
3439+
);
3440+
},
3441+
)
3442+
: null,
3443+
floatingActionButton: expanded
3444+
? FloatingActionButton(
3445+
onPressed: () {
3446+
setState(() {
3447+
expanded = !expanded;
3448+
});
3449+
},
3450+
child: const Icon(Icons.add),
3451+
)
3452+
: null,
3453+
);
3454+
},
3455+
),
3456+
),
3457+
);
3458+
3459+
await tester.tap(find.byType(TextButton));
3460+
await tester.pumpAndSettle();
3461+
3462+
final double controllerValue = controller.size;
3463+
expect(controllerValue, 0.5);
3464+
3465+
await tester.tap(find.byType(FloatingActionButton));
3466+
3467+
final FlutterExceptionHandler? handler = FlutterError.onError;
3468+
FlutterError.onError = (FlutterErrorDetails details) {
3469+
log.add(details.exception.toString());
3470+
};
3471+
await tester.pump();
3472+
FlutterError.onError = handler;
3473+
expect(log.length, 0);
3474+
});
33983475
}
33993476

34003477
class _GeometryListener extends StatefulWidget {

0 commit comments

Comments
 (0)