Unverified Commit 7511d8c0 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

fix MediaQuery override in CupertinoDatePicker (#48001)

parent c924f499
......@@ -777,7 +777,7 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
}
return MediaQuery(
data: const MediaQueryData(textScaleFactor: 1.0),
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: DefaultTextStyle.merge(
style: _kDefaultPickerTextStyle,
child: CustomMultiChildLayout(
......@@ -1145,7 +1145,7 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
}
return MediaQuery(
data: const MediaQueryData(textScaleFactor: 1.0),
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: DefaultTextStyle.merge(
style: _kDefaultPickerTextStyle,
child: CustomMultiChildLayout(
......@@ -1669,11 +1669,9 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
}
final CupertinoThemeData themeData = CupertinoTheme.of(context);
return MediaQuery(
data: const MediaQueryData(
// The native iOS picker's text scaling is fixed, so we will also fix it
// as well in our picker.
textScaleFactor: 1.0,
),
// The native iOS picker's text scaling is fixed, so we will also fix it
// as well in our picker.
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: CupertinoTheme(
data: themeData.copyWith(
textTheme: themeData.textTheme.copyWith(
......
......@@ -1187,6 +1187,51 @@ void main() {
handle.dispose();
});
testWidgets('CupertinoDataPicker does not provide invalid MediaQuery', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/47989.
Brightness brightness = Brightness.light;
StateSetter setState;
await tester.pumpWidget(
CupertinoApp(
theme: const CupertinoThemeData(
textTheme: CupertinoTextThemeData(
dateTimePickerTextStyle: TextStyle(
color: CupertinoDynamicColor.withBrightness(
color: Color(0xFFFFFFFF),
darkColor: Color(0xFF000000),
),
),
),
),
home: StatefulBuilder(builder: (BuildContext context, StateSetter stateSetter) {
setState = stateSetter;
return MediaQuery(
data: MediaQuery.of(context).copyWith(platformBrightness: brightness),
child: CupertinoDatePicker(
initialDateTime: DateTime(2019),
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (DateTime date) {},
),
);
}),
),
);
expect(
tester.widget<Text>(find.text('2019')).style.color,
isSameColorAs(const Color(0xFFFFFFFF)),
);
setState(() { brightness = Brightness.dark; });
await tester.pump();
expect(
tester.widget<Text>(find.text('2019')).style.color,
isSameColorAs(const Color(0xFF000000)),
);
});
testWidgets('picker exports semantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
debugResetSemanticsIdCounter();
......
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