Skip to content

Feat : TextField cursor color matching M2 and M3 Spec in error state#119225

Merged
justinmc merged 9 commits intoflutter:masterfrom
hasnentai:fix-text-feild
Mar 9, 2023
Merged

Feat : TextField cursor color matching M2 and M3 Spec in error state#119225
justinmc merged 9 commits intoflutter:masterfrom
hasnentai:fix-text-feild

Conversation

@hasnentai
Copy link
Contributor

@hasnentai hasnentai commented Jan 26, 2023

TextField in error states should have a cursor color which matches other error-themed colours.

Fixes: #113750
Related: #114950

Screen

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jan 26, 2023
@LongCatIsLooong
Copy link
Contributor

Could you add the newline back at the end of text_field.dart? The analyzer is complaining (https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8790918503105134049/+/u/Analyze/analyze/test_stdout):

info • Missing a newline at the end of the file • packages/flutter/lib/src/material/text_field.dart:1465:46 • eol_at_end_of_file

@hasnentai
Copy link
Contributor Author

I was wondering why the checks were failing. Thanks
I have added a new line in the file

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this! Mostly just minor comments below.

});


testWidgets('Error color for cursor while validation', (WidgetTester tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdent this, and remove the extra newline above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh sorry, I just missed it. I have made the changes

final EditableText textField = tester.widget(find.byType(EditableText).first);
await tester.pump();
expect(textField.cursorColor, errorColor);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra newline here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


await tester.pumpWidget(
MaterialApp(
theme: ThemeData(colorScheme: const ColorScheme.light(error: errorColor)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are multiple spaces before the const.

Also nit: Maybe split the colorScheme parameter onto its own line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made it to a newline of color scheme to its own

paintCursorAboveText = true;
cursorOpacityAnimates = true;
cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? cupertinoTheme.primaryColor;
cursorColor = _getCursorColor(selectionStyle, theme);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should theme be cupertinoTheme here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, Added Cupertino Theme for Mac and Ios platform case

paintCursorAboveText = true;
cursorOpacityAnimates = false;
cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? cupertinoTheme.primaryColor;
cursorColor = _getCursorColor(selectionStyle, theme);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing about cupertinoTheme here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +1154 to +1156
/// Sets the cursor color to error color from decoration or from theme colorScheme if [_hasError] is true else
/// it will return the color from [widget.cursorColor] param if not null. if [widget.cursorColor] is null then it will return default style else return
/// color from theme colorScheme.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really I think this entire comment is self explanatory by looking at the code and the method signature. I would just remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

/// Sets the cursor color to error color from decoration or from theme colorScheme if [_hasError] is true else
/// it will return the color from [widget.cursorColor] param if not null. if [widget.cursorColor] is null then it will return default style else return
/// color from theme colorScheme.
Color _getCursorColor(DefaultSelectionStyle selectionStyle, ThemeData theme){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Color _getCursorColor(DefaultSelectionStyle selectionStyle, ThemeData theme){
Color _getCursorColor (DefaultSelectionStyle selectionStyle, ThemeData theme) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added space

/// it will return the color from [widget.cursorColor] param if not null. if [widget.cursorColor] is null then it will return default style else return
/// color from theme colorScheme.
Color _getCursorColor(DefaultSelectionStyle selectionStyle, ThemeData theme){
if(_hasError){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(_hasError){
if (_hasError) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added space

/// color from theme colorScheme.
Color _getCursorColor(DefaultSelectionStyle selectionStyle, ThemeData theme){
if(_hasError){
return _errorColor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You could just inline this here rather than making it a getter, but either way works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made it inline

@hasnentai hasnentai requested review from justinmc and removed request for LongCatIsLooong January 27, 2023 07:08
@hasnentai
Copy link
Contributor Author

Hi @justinmc Google Test is failing
What could be the possible reason ?

@justinmc
Copy link
Contributor

justinmc commented Feb 2, 2023

Hmm it's not showing up in the Google testing tool for me. Can you try pushing a merge commit with master?

@justinmc justinmc mentioned this pull request Mar 3, 2023
5 tasks
@hasnentai
Copy link
Contributor Author

@justinmc Finally the checks are passing 😀. Please review it once

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

I've triggered Google tests for this PR, so let's see what that says too before merge.

const Color errorColor = Color(0xff123456);
await tester.pumpWidget(MaterialApp(
theme: ThemeData(
colorScheme: const ColorScheme.light(error: errorColor)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a trailing comma here.

Copy link
Contributor Author

@hasnentai hasnentai Mar 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

expect(editableText.magnifierConfiguration, equals(myTextMagnifierConfiguration));
});

testWidgets('Error color for cursor while validation', (WidgetTester tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "while validation" => "during validation" or "while validating"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the desc

home: Material(
child: Center(
child: TextFormField(
enabled: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renewing my LGTM.

Also, I forgot but we need a secondary reviewer. I'll ask around.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@justinmc
Copy link
Contributor

justinmc commented Mar 9, 2023

Thanks for the secondary review! I'll plan to merge this tomorrow morning.

@justinmc justinmc merged commit c5da507 into flutter:master Mar 9, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 9, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 10, 2023
hannah-hyj pushed a commit to hannah-hyj/flutter that referenced this pull request Mar 11, 2023
flutter#119225)

According to Material specs, cursor should be red in error state.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 11, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 12, 2023
@justinmc
Copy link
Contributor

@hasnentai Should the handle also be red instead of blue? I made an issue to track this (#122538) but I couldn't find a spec or anything that showed it being red.

Screenshot from 2023-03-13 10-29-39

@hasnentai
Copy link
Contributor Author

Hi, @justinmc I think having a red handle makes more sense in error state and also maintains the colour uniformity.Let me know if we have to implement the handle colour I would be more then happy to take it up 😊

@justinmc
Copy link
Contributor

@hasnentai Can you confirm that the handle should be red by default on native Android? If so then I think we should definitely make the change.

@hasnentai
Copy link
Contributor Author

On it.Will get back after checking on native

@justinmc
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextField cursor color does not match state spec in error state

4 participants