Feat : TextField cursor color matching M2 and M3 Spec in error state#119225
Feat : TextField cursor color matching M2 and M3 Spec in error state#119225justinmc merged 9 commits intoflutter:masterfrom
TextField cursor color matching M2 and M3 Spec in error state#119225Conversation
|
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):
|
|
I was wondering why the checks were failing. Thanks |
justinmc
left a comment
There was a problem hiding this comment.
Thanks for fixing this! Mostly just minor comments below.
| }); | ||
|
|
||
|
|
||
| testWidgets('Error color for cursor while validation', (WidgetTester tester) async { |
There was a problem hiding this comment.
Outdent this, and remove the extra newline above.
There was a problem hiding this comment.
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); | ||
|
|
There was a problem hiding this comment.
Remove the extra newline here.
|
|
||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| theme: ThemeData(colorScheme: const ColorScheme.light(error: errorColor)), |
There was a problem hiding this comment.
I think there are multiple spaces before the const.
Also nit: Maybe split the colorScheme parameter onto its own line.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Should theme be cupertinoTheme here?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Same thing about cupertinoTheme here too.
| /// 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. |
There was a problem hiding this comment.
Really I think this entire comment is self explanatory by looking at the code and the method signature. I would just remove it.
| /// 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){ |
There was a problem hiding this comment.
| Color _getCursorColor(DefaultSelectionStyle selectionStyle, ThemeData theme){ | |
| Color _getCursorColor (DefaultSelectionStyle selectionStyle, ThemeData theme) { |
| /// 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){ |
There was a problem hiding this comment.
| if(_hasError){ | |
| if (_hasError) { |
| /// color from theme colorScheme. | ||
| Color _getCursorColor(DefaultSelectionStyle selectionStyle, ThemeData theme){ | ||
| if(_hasError){ | ||
| return _errorColor; |
There was a problem hiding this comment.
Nit: You could just inline this here rather than making it a getter, but either way works.
There was a problem hiding this comment.
I have made it inline
|
Hi @justinmc Google Test is failing |
|
Hmm it's not showing up in the Google testing tool for me. Can you try pushing a merge commit with master? |
|
@justinmc Finally the checks are passing 😀. Please review it once |
justinmc
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Missing a trailing comma here.
| expect(editableText.magnifierConfiguration, equals(myTextMagnifierConfiguration)); | ||
| }); | ||
|
|
||
| testWidgets('Error color for cursor while validation', (WidgetTester tester) async { |
There was a problem hiding this comment.
Nit: "while validation" => "during validation" or "while validating"
| home: Material( | ||
| child: Center( | ||
| child: TextFormField( | ||
| enabled: true, |
justinmc
left a comment
There was a problem hiding this comment.
Renewing my LGTM.
Also, I forgot but we need a secondary reviewer. I'll ask around.
|
Thanks for the secondary review! I'll plan to merge this tomorrow morning. |
flutter#119225) According to Material specs, cursor should be red in error state.
|
@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. |
|
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 😊 |
|
@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. |
|
On it.Will get back after checking on native |
|
Thanks! |

TextFieldin error states should have a cursor color which matches other error-themed colours.Fixes: #113750
Related: #114950
Screen
Pre-launch Checklist
///).