Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 4 commits into from
Aug 4, 2020
Merged

TextSelectionTheme support (step 1 of 3) #62014

merged 4 commits into from
Aug 4, 2020

Conversation

darrenaustin
Copy link
Contributor

@darrenaustin darrenaustin commented Jul 22, 2020

Description

As part of the larger theme system update, this PR provides a new TextSelectionTheme that configures the visual properties of text selection in TextField and SelectableText widgets. The initial supported properties are the cursorColor, selectionColor and selectionHandleColor, with more to come in future PRs.

TextSelectionTheme

These properties will now replace the existing equivalent properties in ThemeData (i.e cursorColor, textSelectionColor and textSelectionHandleColor). As such the properties on ThemeData 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-in ThemeData.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

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

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.

@darrenaustin darrenaustin requested a review from HansMuller July 22, 2020 07:51
@darrenaustin darrenaustin added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jul 22, 2020
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, just some formatting I got carried away with. Thanks for doing this!

@googlebot
Copy link

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.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

///
/// Use [TextSelectionTheme.of] to access the closest ancestor
/// [TextSelectionTheme] of the current [BuildContext].
///
Copy link
Contributor

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.

Copy link
Contributor

@HansMuller HansMuller left a 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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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(),
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

NICE

@darrenaustin darrenaustin merged commit bebc119 into flutter:master Aug 4, 2020
@darrenaustin darrenaustin deleted the text_selection_theme branch August 4, 2020 23:06
Pragya007 pushed a commit to Pragya007/flutter that referenced this pull request Aug 11, 2020
Create a new TextSelectionTheme for text selection properties.
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
Create a new TextSelectionTheme for text selection properties.
@darrenaustin darrenaustin restored the text_selection_theme branch September 8, 2020 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

5 participants