From f5865e5cdb5c564079c51a70618c39410ac8cfee Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Mon, 2 May 2022 22:41:50 +0300 Subject: [PATCH] Fix `CupertinoFormRow`dark mode text color (#100313) Improved code --- .../flutter/lib/src/cupertino/form_row.dart | 5 ++- .../flutter/test/cupertino/form_row_test.dart | 42 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/cupertino/form_row.dart b/packages/flutter/lib/src/cupertino/form_row.dart index 4112d7f97d..1d9f7d9615 100644 --- a/packages/flutter/lib/src/cupertino/form_row.dart +++ b/packages/flutter/lib/src/cupertino/form_row.dart @@ -148,7 +148,10 @@ class CupertinoFormRow extends StatelessWidget { @override Widget build(BuildContext context) { - final TextStyle textStyle = CupertinoTheme.of(context).textTheme.textStyle; + final CupertinoThemeData theme = CupertinoTheme.of(context); + final TextStyle textStyle = theme.textTheme.textStyle.copyWith( + color: CupertinoDynamicColor.maybeResolve(theme.textTheme.textStyle.color, context) + ); return Padding( padding: padding ?? _kDefaultPadding, diff --git a/packages/flutter/test/cupertino/form_row_test.dart b/packages/flutter/test/cupertino/form_row_test.dart index eff039fc7d..c64515d64f 100644 --- a/packages/flutter/test/cupertino/form_row_test.dart +++ b/packages/flutter/test/cupertino/form_row_test.dart @@ -3,6 +3,8 @@ // found in the LICENSE file. import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -163,4 +165,44 @@ void main() { expect(errorTextStyle.style.color, CupertinoColors.destructiveRed); }); + + testWidgets('CupertinoFormRow adapts to MaterialApp dark mode', (WidgetTester tester) async { + const Widget prefix = Text('Prefix'); + const Widget helper = Text('Helper'); + + Widget _buildFormRow(Brightness brightness) { + return MaterialApp( + theme: ThemeData(brightness: brightness), + home: const Center( + child: CupertinoFormRow( + prefix: prefix, + helper: helper, + child: CupertinoTextField(), + ), + ), + ); + } + + // CupertinoFormRow with light theme. + await tester.pumpWidget(_buildFormRow(Brightness.light)); + RenderParagraph helperParagraph = tester.renderObject(find.text('Helper')); + expect(helperParagraph.text.style!.color, CupertinoColors.label); + // Text style should not return unresolved color. + expect(helperParagraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse); + RenderParagraph prefixParagraph = tester.renderObject(find.text('Prefix')); + expect(prefixParagraph.text.style!.color, CupertinoColors.label); + // Text style should not return unresolved color. + expect(prefixParagraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse); + + // CupertinoFormRow with light theme. + await tester.pumpWidget(_buildFormRow(Brightness.dark)); + helperParagraph = tester.renderObject(find.text('Helper')); + expect(helperParagraph.text.style!.color, CupertinoColors.label); + // Text style should not return unresolved color. + expect(helperParagraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse); + prefixParagraph = tester.renderObject(find.text('Prefix')); + expect(prefixParagraph.text.style!.color, CupertinoColors.label); + // Text style should not return unresolved color. + expect(prefixParagraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse); + }); }