Unverified Commit 440753ba authored by Darren Austin's avatar Darren Austin Committed by GitHub

Fix regression with ModalBottomSheets not responding to changes in theme (#42189)

Fix regression with ModalBottomSheets not responding to changes in theme
after they are shown.
parent 85cc3131
......@@ -380,6 +380,7 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
@override
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
final BottomSheetThemeData sheetTheme = theme?.bottomSheetTheme ?? Theme.of(context).bottomSheetTheme;
// By definition, the bottom sheet is aligned to the bottom of the page
// and isn't exposed to the top padding of the MediaQuery.
Widget bottomSheet = MediaQuery.removePadding(
......@@ -387,8 +388,8 @@ class _ModalBottomSheetRoute<T> extends PopupRoute<T> {
removeTop: true,
child: _ModalBottomSheet<T>(
route: this,
backgroundColor: backgroundColor,
elevation: elevation,
backgroundColor: backgroundColor ?? sheetTheme?.modalBackgroundColor ?? sheetTheme?.backgroundColor,
elevation: elevation ?? sheetTheme?.modalElevation ?? sheetTheme?.elevation,
shape: shape,
clipBehavior: clipBehavior,
isScrollControlled: isScrollControlled,
......@@ -460,15 +461,13 @@ Future<T> showModalBottomSheet<T>({
assert(debugCheckHasMediaQuery(context));
assert(debugCheckHasMaterialLocalizations(context));
final BottomSheetThemeData theme = Theme.of(context).bottomSheetTheme;
return Navigator.of(context, rootNavigator: useRootNavigator).push(_ModalBottomSheetRoute<T>(
builder: builder,
theme: Theme.of(context, shadowThemeOnly: true),
isScrollControlled: isScrollControlled,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
backgroundColor: backgroundColor ?? theme?.modalBackgroundColor ?? theme?.backgroundColor,
elevation: elevation ?? theme?.modalElevation ?? theme?.elevation,
backgroundColor: backgroundColor,
elevation: elevation,
shape: shape,
clipBehavior: clipBehavior,
));
......
......@@ -4,6 +4,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
......@@ -214,6 +215,75 @@ void main() {
expect(material.elevation, 0);
expect(material.color, null);
});
testWidgets('Modal bottom sheets respond to theme changes', (WidgetTester tester) async {
const double lightElevation = 5.0;
const double darkElevation = 3.0;
const Color lightBackgroundColor = Colors.green;
const Color darkBackgroundColor = Colors.grey;
await tester.pumpWidget(MaterialApp(
theme: ThemeData.light().copyWith(
bottomSheetTheme: const BottomSheetThemeData(
elevation: lightElevation,
backgroundColor: lightBackgroundColor,
),
),
darkTheme: ThemeData.dark().copyWith(
bottomSheetTheme: const BottomSheetThemeData(
elevation: darkElevation,
backgroundColor: darkBackgroundColor,
),
),
home: Scaffold(
body: Builder(
builder: (BuildContext context) {
return Column(
children: <Widget>[
RawMaterialButton(
child: const Text('Show Modal'),
onPressed: () {
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return Container(
child: const Text('This is a modal bottom sheet.'),
);
},
);
},
),
],
);
},
),
),
));
await tester.tap(find.text('Show Modal'));
await tester.pumpAndSettle();
final Material lightMaterial = tester.widget<Material>(
find.descendant(
of: find.byType(BottomSheet),
matching: find.byType(Material),
),
);
expect(lightMaterial.elevation, lightElevation);
expect(lightMaterial.color, lightBackgroundColor);
// Simulate the user changing to dark theme
tester.binding.window.platformBrightnessTestValue = Brightness.dark;
await tester.pumpAndSettle();
final Material darkMaterial = tester.widget<Material>(
find.descendant(
of: find.byType(BottomSheet),
matching: find.byType(Material),
),
);
expect(darkMaterial.elevation, darkElevation);
expect(darkMaterial.color, darkBackgroundColor);
});
}
Widget bottomSheetWithElevations(BottomSheetThemeData bottomSheetTheme) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment