Skip to content

Commit 0a97ef8

Browse files
authored
Fix BottomAppBar & BottomSheet M3 shadow (#119819)
* remove m3 shadows * fix * fix that test over there
1 parent 0588b92 commit 0a97ef8

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
66
import 'package:flutter/widgets.dart';
77

88
import 'bottom_app_bar_theme.dart';
9+
import 'colors.dart';
910
import 'elevation_overlay.dart';
1011
import 'material.dart';
1112
import 'scaffold.dart';
@@ -177,6 +178,7 @@ class _BottomAppBarState extends State<BottomAppBar> {
177178
final Color color = widget.color ?? babTheme.color ?? defaults.color!;
178179
final Color surfaceTintColor = widget.surfaceTintColor ?? babTheme.surfaceTintColor ?? defaults.surfaceTintColor!;
179180
final Color effectiveColor = isMaterial3 ? color : ElevationOverlay.applyOverlay(context, color, elevation);
181+
final Color? shadowColor = isMaterial3 ? Colors.transparent : null;
180182

181183
final Widget child = Padding(
182184
padding: widget.padding ?? babTheme.padding ?? (isMaterial3 ? const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0) : EdgeInsets.zero),
@@ -187,15 +189,16 @@ class _BottomAppBarState extends State<BottomAppBar> {
187189
height: height,
188190
child: PhysicalShape(
189191
clipper: clipper,
190-
elevation: elevation,
191192
color: effectiveColor,
192193
clipBehavior: widget.clipBehavior,
194+
elevation: isMaterial3 ? 0 : elevation,
193195
child: Material(
194196
key: materialKey,
195197
type: isMaterial3 ? MaterialType.canvas : MaterialType.transparency,
196198
elevation: elevation,
197199
color: isMaterial3 ? effectiveColor : null,
198200
surfaceTintColor: surfaceTintColor,
201+
shadowColor: shadowColor,
199202
child: SafeArea(child: child),
200203
),
201204
),

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,16 @@ class _BottomSheetState extends State<BottomSheet> {
270270

271271
@override
272272
Widget build(BuildContext context) {
273+
final bool useMaterial3 = Theme.of(context).useMaterial3;
273274
final BottomSheetThemeData bottomSheetTheme = Theme.of(context).bottomSheetTheme;
274-
final BottomSheetThemeData defaults = Theme.of(context).useMaterial3 ? _BottomSheetDefaultsM3(context) : const BottomSheetThemeData();
275+
final BottomSheetThemeData defaults = useMaterial3 ? _BottomSheetDefaultsM3(context) : const BottomSheetThemeData();
275276
final BoxConstraints? constraints = widget.constraints ?? bottomSheetTheme.constraints;
276277
final Color? color = widget.backgroundColor ?? bottomSheetTheme.backgroundColor ?? defaults.backgroundColor;
277278
final Color? surfaceTintColor = bottomSheetTheme.surfaceTintColor ?? defaults.surfaceTintColor;
278279
final double elevation = widget.elevation ?? bottomSheetTheme.elevation ?? defaults.elevation ?? 0;
279280
final ShapeBorder? shape = widget.shape ?? bottomSheetTheme.shape ?? defaults.shape;
280281
final Clip clipBehavior = widget.clipBehavior ?? bottomSheetTheme.clipBehavior ?? Clip.none;
282+
final Color? shadowColor = useMaterial3 ? Colors.transparent : null;
281283

282284
Widget bottomSheet = Material(
283285
key: _childKey,
@@ -286,6 +288,7 @@ class _BottomSheetState extends State<BottomSheet> {
286288
surfaceTintColor: surfaceTintColor,
287289
shape: shape,
288290
clipBehavior: clipBehavior,
291+
shadowColor: shadowColor,
289292
child: NotificationListener<DraggableScrollableNotification>(
290293
onNotification: extentChanged,
291294
child: widget.builder(context),

packages/flutter/test/material/bottom_app_bar_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,27 @@ void main() {
233233
expect(material.color, const Color(0xff0000ff));
234234
});
235235

236+
testWidgets('Shadow color is transparent in Material 3', (WidgetTester tester) async {
237+
await tester.pumpWidget(
238+
MaterialApp(
239+
theme: ThemeData(useMaterial3: true,
240+
),
241+
home: const Scaffold(
242+
floatingActionButton: FloatingActionButton(
243+
onPressed: null,
244+
),
245+
bottomNavigationBar: BottomAppBar(
246+
color: Color(0xff0000ff),
247+
),
248+
),
249+
)
250+
);
251+
252+
final Material material = tester.widget(find.byType(Material).at(1));
253+
254+
expect(material.shadowColor, Colors.transparent); /* no value in Material 2. */
255+
});
256+
236257
testWidgets('dark theme applies an elevation overlay color', (WidgetTester tester) async {
237258
await tester.pumpWidget(
238259
MaterialApp(

packages/flutter/test/material/bottom_app_bar_theme_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ void main() {
173173
home: const Scaffold(body: BottomAppBar()),
174174
));
175175

176-
final PhysicalShape widget = _getBabRenderObject(tester);
176+
final Material material = tester.widget(find.byType(Material).at(1));
177177

178-
expect(widget.color, theme.colorScheme.surface);
179-
expect(widget.elevation, equals(3.0));
178+
expect(material.color, theme.colorScheme.surface);
179+
expect(material.elevation, equals(3.0));
180180
});
181181

182182
testWidgets('BAB theme overrides surfaceTintColor - M3', (WidgetTester tester) async {

packages/flutter/test/material/bottom_sheet_test.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ void main() {
841841
expect(modalBarrier.color, barrierColor);
842842
});
843843

844-
testWidgets('BottomSheet uses fallback values in maretial3',
844+
testWidgets('BottomSheet uses fallback values in material 3',
845845
(WidgetTester tester) async {
846846
const Color surfaceColor = Colors.pink;
847847
const Color surfaceTintColor = Colors.blue;
@@ -880,6 +880,30 @@ void main() {
880880
expect(material.shape, defaultShape);
881881
});
882882

883+
testWidgets('BottomSheet has transparent shadow in material3', (WidgetTester tester) async {
884+
await tester.pumpWidget(MaterialApp(
885+
theme: ThemeData(
886+
useMaterial3: true,
887+
),
888+
home: Scaffold(
889+
body: BottomSheet(
890+
onClosing: () {},
891+
builder: (BuildContext context) {
892+
return Container();
893+
},
894+
),
895+
),
896+
));
897+
898+
final Material material = tester.widget<Material>(
899+
find.descendant(
900+
of: find.byType(BottomSheet),
901+
matching: find.byType(Material),
902+
),
903+
);
904+
expect(material.shadowColor, Colors.transparent);
905+
});
906+
883907
testWidgets('modal BottomSheet with scrollController has semantics', (WidgetTester tester) async {
884908
final SemanticsTester semantics = SemanticsTester(tester);
885909
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();

0 commit comments

Comments
 (0)