Unverified Commit f5865e5c authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `CupertinoFormRow`dark mode text color (#100313)

Improved code
parent 07014d57
......@@ -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,
......
......@@ -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);
});
}
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