fix MediaQuery override in CupertinoDatePicker (#48001)

diff --git a/packages/flutter/lib/src/cupertino/date_picker.dart b/packages/flutter/lib/src/cupertino/date_picker.dart
index 37bdbe9..79ac686 100644
--- a/packages/flutter/lib/src/cupertino/date_picker.dart
+++ b/packages/flutter/lib/src/cupertino/date_picker.dart
@@ -777,7 +777,7 @@
     }
 
     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 @@
     }
 
     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 @@
     }
     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(
diff --git a/packages/flutter/test/cupertino/date_picker_test.dart b/packages/flutter/test/cupertino/date_picker_test.dart
index 701febc..69afc81 100644
--- a/packages/flutter/test/cupertino/date_picker_test.dart
+++ b/packages/flutter/test/cupertino/date_picker_test.dart
@@ -1187,6 +1187,51 @@
     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();