Fix BottomAppBar dip without FAB (#104490)

This commit is contained in:
Taha Tesser 2022-05-24 13:13:08 +03:00 committed by GitHub
parent d7a1b498ae
commit a12a69a47c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View file

@ -128,8 +128,9 @@ class _BottomAppBarState extends State<BottomAppBar> {
@override
Widget build(BuildContext context) {
final BottomAppBarTheme babTheme = BottomAppBarTheme.of(context);
final bool hasFab = Scaffold.of(context).hasFloatingActionButton;
final NotchedShape? notchedShape = widget.shape ?? babTheme.shape;
final CustomClipper<Path> clipper = notchedShape != null
final CustomClipper<Path> clipper = notchedShape != null && hasFab
? _BottomAppBarClipper(
geometry: geometryListenable,
shape: notchedShape,

View file

@ -474,6 +474,31 @@ void main() {
),
);
});
testWidgets('BottomAppBar does not apply custom clipper without FAB', (WidgetTester tester) async {
Widget buildWidget({Widget? fab}) {
return MaterialApp(
home: Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: fab,
bottomNavigationBar: BottomAppBar(
color: Colors.green,
shape: const CircularNotchedRectangle(),
child: Container(height: 50),
),
),
);
}
await tester.pumpWidget(buildWidget(fab: FloatingActionButton(onPressed: () { })));
PhysicalShape physicalShape = tester.widget(find.byType(PhysicalShape).at(0));
expect(physicalShape.clipper.toString(), '_BottomAppBarClipper');
await tester.pumpWidget(buildWidget());
physicalShape = tester.widget(find.byType(PhysicalShape).at(0));
expect(physicalShape.clipper.toString(), 'ShapeBorderClipper');
});
}
// The bottom app bar clip path computation is only available at paint time.