Fix BottomAppBar & BottomSheet M3 shadow (#119819)
* remove m3 shadows * fix * fix that test over there
This commit is contained in:
parent
0588b925a0
commit
0a97ef85c8
@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
import 'bottom_app_bar_theme.dart';
|
import 'bottom_app_bar_theme.dart';
|
||||||
|
import 'colors.dart';
|
||||||
import 'elevation_overlay.dart';
|
import 'elevation_overlay.dart';
|
||||||
import 'material.dart';
|
import 'material.dart';
|
||||||
import 'scaffold.dart';
|
import 'scaffold.dart';
|
||||||
@ -177,6 +178,7 @@ class _BottomAppBarState extends State<BottomAppBar> {
|
|||||||
final Color color = widget.color ?? babTheme.color ?? defaults.color!;
|
final Color color = widget.color ?? babTheme.color ?? defaults.color!;
|
||||||
final Color surfaceTintColor = widget.surfaceTintColor ?? babTheme.surfaceTintColor ?? defaults.surfaceTintColor!;
|
final Color surfaceTintColor = widget.surfaceTintColor ?? babTheme.surfaceTintColor ?? defaults.surfaceTintColor!;
|
||||||
final Color effectiveColor = isMaterial3 ? color : ElevationOverlay.applyOverlay(context, color, elevation);
|
final Color effectiveColor = isMaterial3 ? color : ElevationOverlay.applyOverlay(context, color, elevation);
|
||||||
|
final Color? shadowColor = isMaterial3 ? Colors.transparent : null;
|
||||||
|
|
||||||
final Widget child = Padding(
|
final Widget child = Padding(
|
||||||
padding: widget.padding ?? babTheme.padding ?? (isMaterial3 ? const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0) : EdgeInsets.zero),
|
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> {
|
|||||||
height: height,
|
height: height,
|
||||||
child: PhysicalShape(
|
child: PhysicalShape(
|
||||||
clipper: clipper,
|
clipper: clipper,
|
||||||
elevation: elevation,
|
|
||||||
color: effectiveColor,
|
color: effectiveColor,
|
||||||
clipBehavior: widget.clipBehavior,
|
clipBehavior: widget.clipBehavior,
|
||||||
|
elevation: isMaterial3 ? 0 : elevation,
|
||||||
child: Material(
|
child: Material(
|
||||||
key: materialKey,
|
key: materialKey,
|
||||||
type: isMaterial3 ? MaterialType.canvas : MaterialType.transparency,
|
type: isMaterial3 ? MaterialType.canvas : MaterialType.transparency,
|
||||||
elevation: elevation,
|
elevation: elevation,
|
||||||
color: isMaterial3 ? effectiveColor : null,
|
color: isMaterial3 ? effectiveColor : null,
|
||||||
surfaceTintColor: surfaceTintColor,
|
surfaceTintColor: surfaceTintColor,
|
||||||
|
shadowColor: shadowColor,
|
||||||
child: SafeArea(child: child),
|
child: SafeArea(child: child),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -270,14 +270,16 @@ class _BottomSheetState extends State<BottomSheet> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final bool useMaterial3 = Theme.of(context).useMaterial3;
|
||||||
final BottomSheetThemeData bottomSheetTheme = Theme.of(context).bottomSheetTheme;
|
final BottomSheetThemeData bottomSheetTheme = Theme.of(context).bottomSheetTheme;
|
||||||
final BottomSheetThemeData defaults = Theme.of(context).useMaterial3 ? _BottomSheetDefaultsM3(context) : const BottomSheetThemeData();
|
final BottomSheetThemeData defaults = useMaterial3 ? _BottomSheetDefaultsM3(context) : const BottomSheetThemeData();
|
||||||
final BoxConstraints? constraints = widget.constraints ?? bottomSheetTheme.constraints;
|
final BoxConstraints? constraints = widget.constraints ?? bottomSheetTheme.constraints;
|
||||||
final Color? color = widget.backgroundColor ?? bottomSheetTheme.backgroundColor ?? defaults.backgroundColor;
|
final Color? color = widget.backgroundColor ?? bottomSheetTheme.backgroundColor ?? defaults.backgroundColor;
|
||||||
final Color? surfaceTintColor = bottomSheetTheme.surfaceTintColor ?? defaults.surfaceTintColor;
|
final Color? surfaceTintColor = bottomSheetTheme.surfaceTintColor ?? defaults.surfaceTintColor;
|
||||||
final double elevation = widget.elevation ?? bottomSheetTheme.elevation ?? defaults.elevation ?? 0;
|
final double elevation = widget.elevation ?? bottomSheetTheme.elevation ?? defaults.elevation ?? 0;
|
||||||
final ShapeBorder? shape = widget.shape ?? bottomSheetTheme.shape ?? defaults.shape;
|
final ShapeBorder? shape = widget.shape ?? bottomSheetTheme.shape ?? defaults.shape;
|
||||||
final Clip clipBehavior = widget.clipBehavior ?? bottomSheetTheme.clipBehavior ?? Clip.none;
|
final Clip clipBehavior = widget.clipBehavior ?? bottomSheetTheme.clipBehavior ?? Clip.none;
|
||||||
|
final Color? shadowColor = useMaterial3 ? Colors.transparent : null;
|
||||||
|
|
||||||
Widget bottomSheet = Material(
|
Widget bottomSheet = Material(
|
||||||
key: _childKey,
|
key: _childKey,
|
||||||
@ -286,6 +288,7 @@ class _BottomSheetState extends State<BottomSheet> {
|
|||||||
surfaceTintColor: surfaceTintColor,
|
surfaceTintColor: surfaceTintColor,
|
||||||
shape: shape,
|
shape: shape,
|
||||||
clipBehavior: clipBehavior,
|
clipBehavior: clipBehavior,
|
||||||
|
shadowColor: shadowColor,
|
||||||
child: NotificationListener<DraggableScrollableNotification>(
|
child: NotificationListener<DraggableScrollableNotification>(
|
||||||
onNotification: extentChanged,
|
onNotification: extentChanged,
|
||||||
child: widget.builder(context),
|
child: widget.builder(context),
|
||||||
|
@ -233,6 +233,27 @@ void main() {
|
|||||||
expect(material.color, const Color(0xff0000ff));
|
expect(material.color, const Color(0xff0000ff));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('Shadow color is transparent in Material 3', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: ThemeData(useMaterial3: true,
|
||||||
|
),
|
||||||
|
home: const Scaffold(
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: null,
|
||||||
|
),
|
||||||
|
bottomNavigationBar: BottomAppBar(
|
||||||
|
color: Color(0xff0000ff),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
final Material material = tester.widget(find.byType(Material).at(1));
|
||||||
|
|
||||||
|
expect(material.shadowColor, Colors.transparent); /* no value in Material 2. */
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('dark theme applies an elevation overlay color', (WidgetTester tester) async {
|
testWidgets('dark theme applies an elevation overlay color', (WidgetTester tester) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
|
@ -173,10 +173,10 @@ void main() {
|
|||||||
home: const Scaffold(body: BottomAppBar()),
|
home: const Scaffold(body: BottomAppBar()),
|
||||||
));
|
));
|
||||||
|
|
||||||
final PhysicalShape widget = _getBabRenderObject(tester);
|
final Material material = tester.widget(find.byType(Material).at(1));
|
||||||
|
|
||||||
expect(widget.color, theme.colorScheme.surface);
|
expect(material.color, theme.colorScheme.surface);
|
||||||
expect(widget.elevation, equals(3.0));
|
expect(material.elevation, equals(3.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('BAB theme overrides surfaceTintColor - M3', (WidgetTester tester) async {
|
testWidgets('BAB theme overrides surfaceTintColor - M3', (WidgetTester tester) async {
|
||||||
|
@ -841,7 +841,7 @@ void main() {
|
|||||||
expect(modalBarrier.color, barrierColor);
|
expect(modalBarrier.color, barrierColor);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('BottomSheet uses fallback values in maretial3',
|
testWidgets('BottomSheet uses fallback values in material 3',
|
||||||
(WidgetTester tester) async {
|
(WidgetTester tester) async {
|
||||||
const Color surfaceColor = Colors.pink;
|
const Color surfaceColor = Colors.pink;
|
||||||
const Color surfaceTintColor = Colors.blue;
|
const Color surfaceTintColor = Colors.blue;
|
||||||
@ -880,6 +880,30 @@ void main() {
|
|||||||
expect(material.shape, defaultShape);
|
expect(material.shape, defaultShape);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('BottomSheet has transparent shadow in material3', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(MaterialApp(
|
||||||
|
theme: ThemeData(
|
||||||
|
useMaterial3: true,
|
||||||
|
),
|
||||||
|
home: Scaffold(
|
||||||
|
body: BottomSheet(
|
||||||
|
onClosing: () {},
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return Container();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
final Material material = tester.widget<Material>(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byType(BottomSheet),
|
||||||
|
matching: find.byType(Material),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(material.shadowColor, Colors.transparent);
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('modal BottomSheet with scrollController has semantics', (WidgetTester tester) async {
|
testWidgets('modal BottomSheet with scrollController has semantics', (WidgetTester tester) async {
|
||||||
final SemanticsTester semantics = SemanticsTester(tester);
|
final SemanticsTester semantics = SemanticsTester(tester);
|
||||||
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
|
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user