-
Notifications
You must be signed in to change notification settings - Fork 28.7k
TextSelectionTheme support (step 1 of 3) #62014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextSelectionTheme support (step 1 of 3) #62014
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some formatting I got carried away with. Thanks for doing this!
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// | ||
/// Use [TextSelectionTheme.of] to access the closest ancestor | ||
/// [TextSelectionTheme] of the current [BuildContext]. | ||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the diagram that you have on the PR to the docs: that makes it super clear what you're talking about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -635,10 +636,21 @@ class TextField extends StatefulWidget { | |||
/// {@macro flutter.widgets.editableText.cursorRadius} | |||
final Radius cursorRadius; | |||
|
|||
/// The color to use when painting the cursor. | |||
/// The color used to paint the cursor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We seem to be on a nice trajectory here :-). How about : The color of the cursor. Here and elsewhere and in general. For example: The color of the TextField's selection handles, instead of "The color used to paint the selection handles on the text field".
/// | ||
/// Defaults to [ThemeData.cursorColor] or [CupertinoTheme.primaryColor] | ||
/// depending on [ThemeData.platform]. | ||
/// The cursor indicates the current location of text input in the field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't indicate the current text insertion point? Here and elsewhere.
} | ||
|
||
/// An inherited widget that defines the configuration for | ||
/// the rendering of text selection in this widget's subtree. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that defines the configuration for the rendering of text selection => that defines the appearance of text selection
/// cursorColor: Colors.blue, | ||
/// selectionHandleColor: Colors.lightBlue, | ||
/// ), | ||
/// child: TextField(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works because the TextField doesn't actually use TextSelectionTheme directly right? Otherwise we'd have to include a Builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextField
looks up the current theme with TextSelectionTheme.of(context)
in the build method, so it should work fine here.
@@ -319,7 +322,6 @@ class ThemeData with Diagnosticable { | |||
// Spec doesn't specify a dark theme secondaryHeaderColor, this is a guess. | |||
secondaryHeaderColor ??= isDark ? Colors.grey[700] : primarySwatch[50]; | |||
textSelectionColor ??= isDark ? accentColor : primarySwatch[200]; | |||
// TODO(hansmuller): We need a TextFieldTheme to handle this instead, https://github.com/flutter/flutter/issues/56082 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NICE
Create a new TextSelectionTheme for text selection properties.
Create a new TextSelectionTheme for text selection properties.
Description
As part of the larger theme system update, this PR provides a new
TextSelectionTheme
that configures the visual properties of text selection inTextField
andSelectableText
widgets. The initial supported properties are thecursorColor
,selectionColor
andselectionHandleColor
, with more to come in future PRs.These properties will now replace the existing equivalent properties in
ThemeData
(i.ecursorColor
,textSelectionColor
andtextSelectionHandleColor
). As such the properties onThemeData
will be deprecated.In addition to this deprecation, we are updating the default values for each of these properties to use the colors in the
ThemeData.colorScheme
. This will eventually be a breaking change. However, for this first step this is all turned off by default. To turn on the text selection theme support you can set the new temporary opt-inThemeData.useTextSelectionTheme
flag to true.A more detailed description can be found in the design doc. It also includes a migration guide for migrating application code to use the new theme.
Related Issues
#17635
#56082
#61227
Tests
I added tests for the new theme as well as updating the overall
ThemeData
tests.Checklist
///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
This PR specifically won't break any tests, as it is a soft migration. Overall however, after all stages of this are complete it will be a breaking change.