Unverified Commit 11f7ff00 authored by Darren Austin's avatar Darren Austin Committed by GitHub

Complete the migration to the TextSelectionTheme by deprecating the opt-in...

Complete the migration to the TextSelectionTheme by deprecating the opt-in flag and text selection properties in ThemeData. (#66482)
parent 506998cf
...@@ -82,7 +82,6 @@ ThemeData _buildShrineTheme() { ...@@ -82,7 +82,6 @@ ThemeData _buildShrineTheme() {
buttonColor: kShrinePink100, buttonColor: kShrinePink100,
scaffoldBackgroundColor: kShrineBackgroundWhite, scaffoldBackgroundColor: kShrineBackgroundWhite,
cardColor: kShrineBackgroundWhite, cardColor: kShrineBackgroundWhite,
textSelectionColor: kShrinePink100,
errorColor: kShrineErrorRed, errorColor: kShrineErrorRed,
buttonTheme: const ButtonThemeData( buttonTheme: const ButtonThemeData(
colorScheme: kShrineColorScheme, colorScheme: kShrineColorScheme,
......
...@@ -578,17 +578,13 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive ...@@ -578,17 +578,13 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
switch (theme.platform) { switch (theme.platform) {
case TargetPlatform.iOS: case TargetPlatform.iOS:
case TargetPlatform.macOS: case TargetPlatform.macOS:
final CupertinoThemeData cupertinoTheme = CupertinoTheme.of(context);
forcePressEnabled = true; forcePressEnabled = true;
textSelectionControls = cupertinoTextSelectionControls; textSelectionControls = cupertinoTextSelectionControls;
paintCursorAboveText = true; paintCursorAboveText = true;
cursorOpacityAnimates = true; cursorOpacityAnimates = true;
if (theme.useTextSelectionTheme) { cursorColor ??= selectionTheme.cursorColor ?? cupertinoTheme.primaryColor;
cursorColor ??= selectionTheme.cursorColor ?? CupertinoTheme.of(context).primaryColor; selectionColor = selectionTheme.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
selectionColor = selectionTheme.selectionColor ?? CupertinoTheme.of(context).primaryColor;
} else {
cursorColor ??= CupertinoTheme.of(context).primaryColor;
selectionColor = theme.textSelectionColor;
}
cursorRadius ??= const Radius.circular(2.0); cursorRadius ??= const Radius.circular(2.0);
cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0); cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0);
break; break;
...@@ -601,13 +597,8 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive ...@@ -601,13 +597,8 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
textSelectionControls = materialTextSelectionControls; textSelectionControls = materialTextSelectionControls;
paintCursorAboveText = false; paintCursorAboveText = false;
cursorOpacityAnimates = false; cursorOpacityAnimates = false;
if (theme.useTextSelectionTheme) {
cursorColor ??= selectionTheme.cursorColor ?? theme.colorScheme.primary; cursorColor ??= selectionTheme.cursorColor ?? theme.colorScheme.primary;
selectionColor = selectionTheme.selectionColor ?? theme.colorScheme.primary; selectionColor = selectionTheme.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
} else {
cursorColor ??= theme.cursorColor;
selectionColor = theme.textSelectionColor;
}
break; break;
} }
......
...@@ -663,17 +663,11 @@ class TextField extends StatefulWidget { ...@@ -663,17 +663,11 @@ class TextField extends StatefulWidget {
/// The cursor indicates the current location of text insertion point in /// The cursor indicates the current location of text insertion point in
/// the field. /// the field.
/// ///
/// If this is null it will default to a value based on the following: /// If this is null it will default to the ambient
/// /// [TextSelectionThemeData.cursorColor]. If that is null, and the
/// * If the ambient [ThemeData.useTextSelectionTheme] is true then it /// [ThemeData.platform] is [TargetPlatform.iOS] or [TargetPlatform.macOS]
/// will use the value of the ambient [TextSelectionThemeData.cursorColor]. /// it will use [CupertinoThemeData.primaryColor]. Otherwise it will use
/// If that is null then if the [ThemeData.platform] is [TargetPlatform.iOS] /// the value of [ColorScheme.primary] of [ThemeData.colorScheme].
/// or [TargetPlatform.macOS] then it will use [CupertinoThemeData.primaryColor].
/// Otherwise it will use the value of [ColorScheme.primary] of [ThemeData.colorScheme].
///
/// * If the ambient [ThemeData.useTextSelectionTheme] is false then it
/// will use either [ThemeData.cursorColor] or [CupertinoThemeData.primaryColor]
/// depending on [ThemeData.platform].
final Color cursorColor; final Color cursorColor;
/// Controls how tall the selection highlight boxes are computed to be. /// Controls how tall the selection highlight boxes are computed to be.
...@@ -1136,13 +1130,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements ...@@ -1136,13 +1130,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
textSelectionControls = cupertinoTextSelectionControls; textSelectionControls = cupertinoTextSelectionControls;
paintCursorAboveText = true; paintCursorAboveText = true;
cursorOpacityAnimates = true; cursorOpacityAnimates = true;
if (theme.useTextSelectionTheme) {
cursorColor ??= selectionTheme.cursorColor ?? cupertinoTheme.primaryColor; cursorColor ??= selectionTheme.cursorColor ?? cupertinoTheme.primaryColor;
selectionColor = selectionTheme.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40); selectionColor = selectionTheme.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
} else {
cursorColor ??= CupertinoTheme.of(context).primaryColor;
selectionColor = theme.textSelectionColor;
}
cursorRadius ??= const Radius.circular(2.0); cursorRadius ??= const Radius.circular(2.0);
cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0); cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0);
autocorrectionTextRectColor = selectionColor; autocorrectionTextRectColor = selectionColor;
...@@ -1156,13 +1145,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements ...@@ -1156,13 +1145,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
textSelectionControls = materialTextSelectionControls; textSelectionControls = materialTextSelectionControls;
paintCursorAboveText = false; paintCursorAboveText = false;
cursorOpacityAnimates = false; cursorOpacityAnimates = false;
if (theme.useTextSelectionTheme) {
cursorColor ??= selectionTheme.cursorColor ?? theme.colorScheme.primary; cursorColor ??= selectionTheme.cursorColor ?? theme.colorScheme.primary;
selectionColor = selectionTheme.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40); selectionColor = selectionTheme.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
} else {
cursorColor ??= theme.cursorColor;
selectionColor = theme.textSelectionColor;
}
break; break;
} }
......
...@@ -797,9 +797,7 @@ class _MaterialTextSelectionControls extends TextSelectionControls { ...@@ -797,9 +797,7 @@ class _MaterialTextSelectionControls extends TextSelectionControls {
@override @override
Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textHeight) { Widget buildHandle(BuildContext context, TextSelectionHandleType type, double textHeight) {
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
final Color handleColor = theme.useTextSelectionTheme ? final Color handleColor = TextSelectionTheme.of(context).selectionHandleColor ?? theme.colorScheme.primary;
TextSelectionTheme.of(context).selectionHandleColor ?? theme.colorScheme.primary :
theme.textSelectionHandleColor;
final Widget handle = SizedBox( final Widget handle = SizedBox(
width: _kHandleSize, width: _kHandleSize,
height: _kHandleSize, height: _kHandleSize,
......
...@@ -238,8 +238,20 @@ class ThemeData with Diagnosticable { ...@@ -238,8 +238,20 @@ class ThemeData with Diagnosticable {
ButtonThemeData buttonTheme, ButtonThemeData buttonTheme,
ToggleButtonsThemeData toggleButtonsTheme, ToggleButtonsThemeData toggleButtonsTheme,
Color secondaryHeaderColor, Color secondaryHeaderColor,
@Deprecated(
'Use TextSelectionThemeData.selectionColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color textSelectionColor, Color textSelectionColor,
@Deprecated(
'Use TextSelectionThemeData.cursorColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color cursorColor, Color cursorColor,
@Deprecated(
'Use TextSelectionThemeData.selectionHandleColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color textSelectionHandleColor, Color textSelectionHandleColor,
Color backgroundColor, Color backgroundColor,
Color dialogBackgroundColor, Color dialogBackgroundColor,
...@@ -286,6 +298,10 @@ class ThemeData with Diagnosticable { ...@@ -286,6 +298,10 @@ class ThemeData with Diagnosticable {
TextSelectionThemeData textSelectionTheme, TextSelectionThemeData textSelectionTheme,
DataTableThemeData dataTableTheme, DataTableThemeData dataTableTheme,
bool fixTextFieldOutlineLabel, bool fixTextFieldOutlineLabel,
@Deprecated(
'No longer used by the framework, please remove any reference to it. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
bool useTextSelectionTheme, bool useTextSelectionTheme,
}) { }) {
assert(colorScheme?.brightness == null || brightness == null || colorScheme.brightness == brightness); assert(colorScheme?.brightness == null || brightness == null || colorScheme.brightness == brightness);
...@@ -883,21 +899,24 @@ class ThemeData with Diagnosticable { ...@@ -883,21 +899,24 @@ class ThemeData with Diagnosticable {
final Color secondaryHeaderColor; final Color secondaryHeaderColor;
/// The color of text selections in text fields, such as [TextField]. /// The color of text selections in text fields, such as [TextField].
/// @Deprecated(
/// By default this property is no longer used. It has been replaced with 'Use TextSelectionThemeData.selectionColor instead. '
/// [TextSelectionThemeData.selectionColor] and will soon be deprecated. 'This feature was deprecated after v1.23.0-4.0.pre.'
)
final Color textSelectionColor; final Color textSelectionColor;
/// The color of cursors in Material-style text fields, such as [TextField]. /// The color of cursors in Material-style text fields, such as [TextField].
/// @Deprecated(
/// By default this property is no longer used. It has been replaced with 'Use TextSelectionThemeData.cursorColor instead. '
/// [TextSelectionThemeData.cursorColor] and will soon be deprecated. 'This feature was deprecated after v1.23.0-4.0.pre.'
)
final Color cursorColor; final Color cursorColor;
/// The color of the handles used to adjust what part of the text is currently selected. /// The color of the handles used to adjust what part of the text is currently selected.
/// @Deprecated(
/// By default this property is no longer used. It has been replaced with 'Use TextSelectionThemeData.selectionHandleColor instead. '
/// [TextSelectionThemeData.selectionHandleColor] and will soon be deprecated. 'This feature was deprecated after v1.23.0-4.0.pre.'
)
final Color textSelectionHandleColor; final Color textSelectionHandleColor;
/// A color that contrasts with the [primaryColor], e.g. used as the /// A color that contrasts with the [primaryColor], e.g. used as the
...@@ -1137,16 +1156,14 @@ class ThemeData with Diagnosticable { ...@@ -1137,16 +1156,14 @@ class ThemeData with Diagnosticable {
/// stable release (1.19). /// stable release (1.19).
final bool fixTextFieldOutlineLabel; final bool fixTextFieldOutlineLabel;
/// A temporary flag to allow apps to opt-in to the new [TextSelectionTheme], with /// A temporary flag that was used to opt-in to the new [TextSelectionTheme]
/// its new defaults for the [cursorColor] and [textSelectionHandleColor]. /// during the migration to this new theme. That migration is now complete
/// /// and this flag is not longer used by the framework. Please remove any
/// Setting this flag to true will cause the [textSelectionTheme] to be used /// reference to this property, as it will be removed in future releases.
/// instead of the [cursorColor] and [textSelectionHandleColor] by [TextField] @Deprecated(
/// and [SelectableText] widgets. In addition, the default values of these 'No longer used by the framework, please remove any reference to it. '
/// colors have changed to [ColorScheme.primary]. 'This feature was deprecated after v1.23.0-4.0.pre.'
/// )
/// The flag is currently false by default. It will be removed after migration
/// to the [TextSelectionTheme] has been completed.
final bool useTextSelectionTheme; final bool useTextSelectionTheme;
/// Creates a copy of this theme but with the given fields replaced with the new values. /// Creates a copy of this theme but with the given fields replaced with the new values.
...@@ -1179,8 +1196,20 @@ class ThemeData with Diagnosticable { ...@@ -1179,8 +1196,20 @@ class ThemeData with Diagnosticable {
ToggleButtonsThemeData toggleButtonsTheme, ToggleButtonsThemeData toggleButtonsTheme,
Color buttonColor, Color buttonColor,
Color secondaryHeaderColor, Color secondaryHeaderColor,
@Deprecated(
'Use TextSelectionThemeData.selectionColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color textSelectionColor, Color textSelectionColor,
@Deprecated(
'Use TextSelectionThemeData.cursorColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color cursorColor, Color cursorColor,
@Deprecated(
'Use TextSelectionThemeData.selectionHandleColor instead. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
Color textSelectionHandleColor, Color textSelectionHandleColor,
Color backgroundColor, Color backgroundColor,
Color dialogBackgroundColor, Color dialogBackgroundColor,
...@@ -1226,6 +1255,10 @@ class ThemeData with Diagnosticable { ...@@ -1226,6 +1255,10 @@ class ThemeData with Diagnosticable {
TextSelectionThemeData textSelectionTheme, TextSelectionThemeData textSelectionTheme,
DataTableThemeData dataTableTheme, DataTableThemeData dataTableTheme,
bool fixTextFieldOutlineLabel, bool fixTextFieldOutlineLabel,
@Deprecated(
'No longer used by the framework, please remove any reference to it. '
'This feature was deprecated after v1.23.0-4.0.pre.'
)
bool useTextSelectionTheme, bool useTextSelectionTheme,
}) { }) {
cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault(); cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault();
......
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