mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
* Revert "Add default selection style (#100719)"
This reverts commit c8057bc506
.
* update
* update
This commit is contained in:
parent
a63402a679
commit
95e52dac76
@ -43,12 +43,6 @@ import 'theme.dart';
|
||||
/// widget, which the [CupertinoApp] composes. If you use Material widgets, a
|
||||
/// [MaterialApp] also creates the needed dependencies for Cupertino widgets.
|
||||
///
|
||||
/// {@template flutter.cupertino.CupertinoApp.defaultSelectionStyle}
|
||||
/// The [CupertinoApp] automatically creates a [DefaultSelectionStyle] with
|
||||
/// selectionColor sets to [CupertinoThemeData.primaryColor] with 0.2 opacity
|
||||
/// and cursorColor sets to [CupertinoThemeData.primaryColor].
|
||||
/// {@endtemplate}
|
||||
///
|
||||
/// Use this widget with caution on Android since it may produce behaviors
|
||||
/// Android users are not expecting such as:
|
||||
///
|
||||
@ -590,14 +584,10 @@ class _CupertinoAppState extends State<CupertinoApp> {
|
||||
data: CupertinoUserInterfaceLevelData.base,
|
||||
child: CupertinoTheme(
|
||||
data: effectiveThemeData,
|
||||
child: DefaultSelectionStyle(
|
||||
selectionColor: effectiveThemeData.primaryColor.withOpacity(0.2),
|
||||
cursorColor: effectiveThemeData.primaryColor,
|
||||
child: HeroControllerScope(
|
||||
controller: _heroController,
|
||||
child: Builder(
|
||||
builder: _buildWidgetApp,
|
||||
),
|
||||
child: HeroControllerScope(
|
||||
controller: _heroController,
|
||||
child: Builder(
|
||||
builder: _buildWidgetApp,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -710,8 +710,7 @@ class CupertinoTextField extends StatefulWidget {
|
||||
|
||||
/// The color to use when painting the cursor.
|
||||
///
|
||||
/// Defaults to the [DefaultSelectionStyle.cursorColor]. If that color is
|
||||
/// null, it uses the [CupertinoThemeData.primaryColor] of the ambient theme,
|
||||
/// Defaults to the [CupertinoThemeData.primaryColor] of the ambient theme,
|
||||
/// which itself defaults to [CupertinoColors.activeBlue] in the light theme
|
||||
/// and [CupertinoColors.activeOrange] in the dark theme.
|
||||
final Color? cursorColor;
|
||||
@ -1179,11 +1178,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
|
||||
final TextStyle placeholderStyle = textStyle.merge(resolvedPlaceholderStyle);
|
||||
|
||||
final Brightness keyboardAppearance = widget.keyboardAppearance ?? CupertinoTheme.brightnessOf(context);
|
||||
final Color cursorColor = CupertinoDynamicColor.maybeResolve(
|
||||
widget.cursorColor ?? DefaultSelectionStyle.of(context).cursorColor,
|
||||
context,
|
||||
) ?? themeData.primaryColor;
|
||||
|
||||
final Color cursorColor = CupertinoDynamicColor.maybeResolve(widget.cursorColor, context) ?? themeData.primaryColor;
|
||||
final Color disabledColor = CupertinoDynamicColor.resolve(_kDisabledBackground, context);
|
||||
|
||||
final Color? decorationColor = CupertinoDynamicColor.maybeResolve(widget.decoration?.color, context);
|
||||
@ -1211,10 +1206,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
|
||||
color: enabled ? decorationColor : disabledColor,
|
||||
);
|
||||
|
||||
final Color selectionColor = CupertinoDynamicColor.maybeResolve(
|
||||
DefaultSelectionStyle.of(context).selectionColor,
|
||||
context,
|
||||
) ?? CupertinoTheme.of(context).primaryColor.withOpacity(0.2);
|
||||
final Color selectionColor = CupertinoTheme.of(context).primaryColor.withOpacity(0.2);
|
||||
|
||||
final Widget paddedEditable = Padding(
|
||||
padding: widget.padding,
|
||||
|
@ -82,14 +82,6 @@ enum ThemeMode {
|
||||
/// This widget also configures the observer of the top-level [Navigator] (if
|
||||
/// any) to perform [Hero] animations.
|
||||
///
|
||||
/// {@template flutter.material.MaterialApp.defaultSelectionStyle}
|
||||
/// The [MaterialApp] automatically creates a [DefaultSelectionStyle]. It uses
|
||||
/// the colors in the [ThemeData.textSelectionTheme] if they are not null;
|
||||
/// otherwise, the [MaterialApp] sets [DefaultSelectionStyle.selectionColor] to
|
||||
/// [ColorScheme.primary] with 0.4 opacity and
|
||||
/// [DefaultSelectionStyle.cursorColor] to [ColorScheme.primary].
|
||||
/// {@endtemplate}
|
||||
///
|
||||
/// If [home], [routes], [onGenerateRoute], and [onUnknownRoute] are all null,
|
||||
/// and [builder] is not null, then no [Navigator] is created.
|
||||
///
|
||||
@ -879,35 +871,29 @@ class _MaterialAppState extends State<MaterialApp> {
|
||||
theme = widget.highContrastTheme;
|
||||
}
|
||||
theme ??= widget.theme ?? ThemeData.light();
|
||||
final Color effectiveSelectionColor = theme.textSelectionTheme.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
|
||||
final Color effectiveCursorColor = theme.textSelectionTheme.cursorColor ?? theme.colorScheme.primary;
|
||||
|
||||
return ScaffoldMessenger(
|
||||
key: widget.scaffoldMessengerKey,
|
||||
child: DefaultSelectionStyle(
|
||||
selectionColor: effectiveSelectionColor,
|
||||
cursorColor: effectiveCursorColor,
|
||||
child: AnimatedTheme(
|
||||
data: theme,
|
||||
child: widget.builder != null
|
||||
? Builder(
|
||||
builder: (BuildContext context) {
|
||||
// Why are we surrounding a builder with a builder?
|
||||
//
|
||||
// The widget.builder may contain code that invokes
|
||||
// Theme.of(), which should return the theme we selected
|
||||
// above in AnimatedTheme. However, if we invoke
|
||||
// widget.builder() directly as the child of AnimatedTheme
|
||||
// then there is no Context separating them, and the
|
||||
// widget.builder() will not find the theme. Therefore, we
|
||||
// surround widget.builder with yet another builder so that
|
||||
// a context separates them and Theme.of() correctly
|
||||
// resolves to the theme we passed to AnimatedTheme.
|
||||
return widget.builder!(context, child);
|
||||
},
|
||||
)
|
||||
: child ?? const SizedBox.shrink(),
|
||||
),
|
||||
child: AnimatedTheme(
|
||||
data: theme,
|
||||
child: widget.builder != null
|
||||
? Builder(
|
||||
builder: (BuildContext context) {
|
||||
// Why are we surrounding a builder with a builder?
|
||||
//
|
||||
// The widget.builder may contain code that invokes
|
||||
// Theme.of(), which should return the theme we selected
|
||||
// above in AnimatedTheme. However, if we invoke
|
||||
// widget.builder() directly as the child of AnimatedTheme
|
||||
// then there is no Context separating them, and the
|
||||
// widget.builder() will not find the theme. Therefore, we
|
||||
// surround widget.builder with yet another builder so that
|
||||
// a context separates them and Theme.of() correctly
|
||||
// resolves to the theme we passed to AnimatedTheme.
|
||||
return widget.builder!(context, child);
|
||||
},
|
||||
)
|
||||
: child ?? const SizedBox.shrink(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import 'package:flutter/rendering.dart';
|
||||
import 'desktop_text_selection.dart';
|
||||
import 'feedback.dart';
|
||||
import 'text_selection.dart';
|
||||
import 'text_selection_theme.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
/// An eyeballed value that moves the cursor slightly left of where it is
|
||||
@ -356,14 +357,9 @@ class SelectableText extends StatefulWidget {
|
||||
/// {@macro flutter.widgets.editableText.cursorRadius}
|
||||
final Radius? cursorRadius;
|
||||
|
||||
/// The color of the cursor.
|
||||
/// The color to use when painting the cursor.
|
||||
///
|
||||
/// The cursor indicates the current text insertion point.
|
||||
///
|
||||
/// If null then [DefaultSelectionStyle.cursorColor] is used. If that is also
|
||||
/// null and [ThemeData.platform] is [TargetPlatform.iOS] or
|
||||
/// [TargetPlatform.macOS], then [CupertinoThemeData.primaryColor] is used.
|
||||
/// Otherwise [ColorScheme.primary] of [ThemeData.colorScheme] is used.
|
||||
/// Defaults to the theme's `cursorColor` when null.
|
||||
final Color? cursorColor;
|
||||
|
||||
/// Controls how tall the selection highlight boxes are computed to be.
|
||||
@ -599,14 +595,14 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
|
||||
);
|
||||
|
||||
final ThemeData theme = Theme.of(context);
|
||||
final DefaultSelectionStyle selectionStyle = DefaultSelectionStyle.of(context);
|
||||
final TextSelectionThemeData selectionTheme = TextSelectionTheme.of(context);
|
||||
final FocusNode focusNode = _effectiveFocusNode;
|
||||
|
||||
TextSelectionControls? textSelectionControls = widget.selectionControls;
|
||||
final bool paintCursorAboveText;
|
||||
final bool cursorOpacityAnimates;
|
||||
Offset? cursorOffset;
|
||||
final Color cursorColor;
|
||||
Color? cursorColor = widget.cursorColor;
|
||||
final Color selectionColor;
|
||||
Radius? cursorRadius = widget.cursorRadius;
|
||||
|
||||
@ -617,8 +613,8 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
|
||||
textSelectionControls ??= cupertinoTextSelectionControls;
|
||||
paintCursorAboveText = true;
|
||||
cursorOpacityAnimates = true;
|
||||
cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? cupertinoTheme.primaryColor;
|
||||
selectionColor = selectionStyle.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
|
||||
cursorColor ??= selectionTheme.cursorColor ?? cupertinoTheme.primaryColor;
|
||||
selectionColor = selectionTheme.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
|
||||
cursorRadius ??= const Radius.circular(2.0);
|
||||
cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0);
|
||||
break;
|
||||
@ -629,8 +625,8 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
|
||||
textSelectionControls ??= cupertinoDesktopTextSelectionControls;
|
||||
paintCursorAboveText = true;
|
||||
cursorOpacityAnimates = true;
|
||||
cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? cupertinoTheme.primaryColor;
|
||||
selectionColor = selectionStyle.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
|
||||
cursorColor ??= selectionTheme.cursorColor ?? cupertinoTheme.primaryColor;
|
||||
selectionColor = selectionTheme.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
|
||||
cursorRadius ??= const Radius.circular(2.0);
|
||||
cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0);
|
||||
break;
|
||||
@ -641,8 +637,8 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
|
||||
textSelectionControls ??= materialTextSelectionControls;
|
||||
paintCursorAboveText = false;
|
||||
cursorOpacityAnimates = false;
|
||||
cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? theme.colorScheme.primary;
|
||||
selectionColor = selectionStyle.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
|
||||
cursorColor ??= selectionTheme.cursorColor ?? theme.colorScheme.primary;
|
||||
selectionColor = selectionTheme.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
|
||||
break;
|
||||
|
||||
case TargetPlatform.linux:
|
||||
@ -651,8 +647,8 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
|
||||
textSelectionControls ??= desktopTextSelectionControls;
|
||||
paintCursorAboveText = false;
|
||||
cursorOpacityAnimates = false;
|
||||
cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? theme.colorScheme.primary;
|
||||
selectionColor = selectionStyle.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
|
||||
cursorColor ??= selectionTheme.cursorColor ?? theme.colorScheme.primary;
|
||||
selectionColor = selectionTheme.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import 'material_localizations.dart';
|
||||
import 'material_state.dart';
|
||||
import 'selectable_text.dart' show iOSHorizontalOffset;
|
||||
import 'text_selection.dart';
|
||||
import 'text_selection_theme.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
export 'package:flutter/services.dart' show TextInputType, TextInputAction, TextCapitalization, SmartQuotesType, SmartDashesType;
|
||||
@ -613,7 +614,7 @@ class TextField extends StatefulWidget {
|
||||
/// the field.
|
||||
///
|
||||
/// If this is null it will default to the ambient
|
||||
/// [DefaultSelectionStyle.cursorColor]. If that is null, and the
|
||||
/// [TextSelectionThemeData.cursorColor]. If that is null, and the
|
||||
/// [ThemeData.platform] is [TargetPlatform.iOS] or [TargetPlatform.macOS]
|
||||
/// it will use [CupertinoThemeData.primaryColor]. Otherwise it will use
|
||||
/// the value of [ColorScheme.primary] of [ThemeData.colorScheme].
|
||||
@ -1115,7 +1116,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
||||
);
|
||||
|
||||
final ThemeData theme = Theme.of(context);
|
||||
final DefaultSelectionStyle selectionStyle = DefaultSelectionStyle.of(context);
|
||||
final TextSelectionThemeData selectionTheme = TextSelectionTheme.of(context);
|
||||
final TextStyle style = theme.textTheme.subtitle1!.merge(widget.style);
|
||||
final Brightness keyboardAppearance = widget.keyboardAppearance ?? theme.brightness;
|
||||
final TextEditingController controller = _effectiveController;
|
||||
@ -1133,7 +1134,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
||||
final bool paintCursorAboveText;
|
||||
final bool cursorOpacityAnimates;
|
||||
Offset? cursorOffset;
|
||||
final Color cursorColor;
|
||||
Color? cursorColor = widget.cursorColor;
|
||||
final Color selectionColor;
|
||||
Color? autocorrectionTextRectColor;
|
||||
Radius? cursorRadius = widget.cursorRadius;
|
||||
@ -1146,8 +1147,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
||||
textSelectionControls ??= cupertinoTextSelectionControls;
|
||||
paintCursorAboveText = true;
|
||||
cursorOpacityAnimates = true;
|
||||
cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? cupertinoTheme.primaryColor;
|
||||
selectionColor = selectionStyle.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
|
||||
cursorColor ??= selectionTheme.cursorColor ?? cupertinoTheme.primaryColor;
|
||||
selectionColor = selectionTheme.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
|
||||
cursorRadius ??= const Radius.circular(2.0);
|
||||
cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0);
|
||||
autocorrectionTextRectColor = selectionColor;
|
||||
@ -1159,8 +1160,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
||||
textSelectionControls ??= cupertinoDesktopTextSelectionControls;
|
||||
paintCursorAboveText = true;
|
||||
cursorOpacityAnimates = true;
|
||||
cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? cupertinoTheme.primaryColor;
|
||||
selectionColor = selectionStyle.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
|
||||
cursorColor ??= selectionTheme.cursorColor ?? cupertinoTheme.primaryColor;
|
||||
selectionColor = selectionTheme.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
|
||||
cursorRadius ??= const Radius.circular(2.0);
|
||||
cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0);
|
||||
handleDidGainAccessibilityFocus = () {
|
||||
@ -1177,8 +1178,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
||||
textSelectionControls ??= materialTextSelectionControls;
|
||||
paintCursorAboveText = false;
|
||||
cursorOpacityAnimates = false;
|
||||
cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? theme.colorScheme.primary;
|
||||
selectionColor = selectionStyle.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
|
||||
cursorColor ??= selectionTheme.cursorColor ?? theme.colorScheme.primary;
|
||||
selectionColor = selectionTheme.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
|
||||
break;
|
||||
|
||||
case TargetPlatform.linux:
|
||||
@ -1186,8 +1187,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
||||
textSelectionControls ??= desktopTextSelectionControls;
|
||||
paintCursorAboveText = false;
|
||||
cursorOpacityAnimates = false;
|
||||
cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? theme.colorScheme.primary;
|
||||
selectionColor = selectionStyle.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
|
||||
cursorColor ??= selectionTheme.cursorColor ?? theme.colorScheme.primary;
|
||||
selectionColor = selectionTheme.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
|
||||
break;
|
||||
|
||||
case TargetPlatform.windows:
|
||||
@ -1195,8 +1196,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
||||
textSelectionControls ??= desktopTextSelectionControls;
|
||||
paintCursorAboveText = false;
|
||||
cursorOpacityAnimates = false;
|
||||
cursorColor = widget.cursorColor ?? selectionStyle.cursorColor ?? theme.colorScheme.primary;
|
||||
selectionColor = selectionStyle.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
|
||||
cursorColor ??= selectionTheme.cursorColor ?? theme.colorScheme.primary;
|
||||
selectionColor = selectionTheme.selectionColor ?? theme.colorScheme.primary.withOpacity(0.40);
|
||||
handleDidGainAccessibilityFocus = () {
|
||||
// Automatically activate the TextField when it receives accessibility focus.
|
||||
if (!_effectiveFocusNode.hasFocus && _effectiveFocusNode.canRequestFocus) {
|
||||
|
@ -129,9 +129,6 @@ class TextSelectionThemeData with Diagnosticable {
|
||||
/// )
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
///
|
||||
/// This widget also creates a [DefaultSelectionStyle] for its subtree with
|
||||
/// [data].
|
||||
class TextSelectionTheme extends InheritedTheme {
|
||||
/// Creates a text selection theme widget that specifies the text
|
||||
/// selection properties for all widgets below it in the widget tree.
|
||||
@ -140,29 +137,12 @@ class TextSelectionTheme extends InheritedTheme {
|
||||
const TextSelectionTheme({
|
||||
super.key,
|
||||
required this.data,
|
||||
required Widget child,
|
||||
}) : assert(data != null),
|
||||
_child = child,
|
||||
// See `get child` override below.
|
||||
super(child: const _NullWidget());
|
||||
required super.child,
|
||||
}) : assert(data != null);
|
||||
|
||||
/// The properties for descendant [TextField] and [SelectableText] widgets.
|
||||
final TextSelectionThemeData data;
|
||||
|
||||
// Overriding the getter to insert `DefaultSelectionStyle` into the subtree
|
||||
// without breaking API. In general, this approach should be avoided
|
||||
// because it relies on an implementation detail of ProxyWidget. This
|
||||
// workaround is necessary because TextSelectionTheme is const.
|
||||
@override
|
||||
Widget get child {
|
||||
return DefaultSelectionStyle(
|
||||
selectionColor: data.selectionColor,
|
||||
cursorColor: data.cursorColor,
|
||||
child: _child,
|
||||
);
|
||||
}
|
||||
final Widget _child;
|
||||
|
||||
/// Returns the [data] from the closest [TextSelectionTheme] ancestor. If
|
||||
/// there is no ancestor, it returns [ThemeData.textSelectionTheme].
|
||||
/// Applications can assume that the returned value will not be null.
|
||||
@ -185,10 +165,3 @@ class TextSelectionTheme extends InheritedTheme {
|
||||
@override
|
||||
bool updateShouldNotify(TextSelectionTheme oldWidget) => data != oldWidget.data;
|
||||
}
|
||||
|
||||
class _NullWidget extends Widget {
|
||||
const _NullWidget();
|
||||
|
||||
@override
|
||||
Element createElement() => throw UnimplementedError();
|
||||
}
|
||||
|
@ -1,94 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'framework.dart';
|
||||
import 'inherited_theme.dart';
|
||||
|
||||
|
||||
/// The selection style to apply to descendant [EditableText] widgets which
|
||||
/// don't have an explicit style.
|
||||
///
|
||||
/// {@macro flutter.cupertino.CupertinoApp.defaultSelectionStyle}
|
||||
///
|
||||
/// {@macro flutter.material.MaterialApp.defaultSelectionStyle}
|
||||
///
|
||||
/// See also:
|
||||
/// * [TextSelectionTheme]: which also creates a [DefaultSelectionStyle] for
|
||||
/// the subtree.
|
||||
class DefaultSelectionStyle extends InheritedTheme {
|
||||
/// Creates a default selection style widget that specifies the selection
|
||||
/// properties for all widgets below it in the widget tree.
|
||||
const DefaultSelectionStyle({
|
||||
super.key,
|
||||
this.cursorColor,
|
||||
this.selectionColor,
|
||||
required super.child,
|
||||
});
|
||||
|
||||
/// A const-constructable default selection style that provides fallback
|
||||
/// values.
|
||||
///
|
||||
/// Returned from [of] when the given [BuildContext] doesn't have an enclosing
|
||||
/// default selection style.
|
||||
///
|
||||
/// This constructor creates a [DefaultTextStyle] with an invalid [child],
|
||||
/// which means the constructed value cannot be incorporated into the tree.
|
||||
const DefaultSelectionStyle.fallback({ super.key })
|
||||
: cursorColor = null,
|
||||
selectionColor = null,
|
||||
super(child: const _NullWidget());
|
||||
|
||||
/// The color of the text field's cursor.
|
||||
///
|
||||
/// The cursor indicates the current location of the text insertion point in
|
||||
/// the field.
|
||||
final Color? cursorColor;
|
||||
|
||||
/// The background color of selected text.
|
||||
final Color? selectionColor;
|
||||
|
||||
/// The closest instance of this class that encloses the given context.
|
||||
///
|
||||
/// If no such instance exists, returns an instance created by
|
||||
/// [DefaultSelectionStyle.fallback], which contains fallback values.
|
||||
///
|
||||
/// Typical usage is as follows:
|
||||
///
|
||||
/// ```dart
|
||||
/// DefaultSelectionStyle style = DefaultSelectionStyle.of(context);
|
||||
/// ```
|
||||
static DefaultSelectionStyle of(BuildContext context) {
|
||||
return context.dependOnInheritedWidgetOfExactType<DefaultSelectionStyle>() ?? const DefaultSelectionStyle.fallback();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget wrap(BuildContext context, Widget child) {
|
||||
return DefaultSelectionStyle(
|
||||
cursorColor: cursorColor,
|
||||
selectionColor: selectionColor,
|
||||
child: child
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(DefaultSelectionStyle oldWidget) {
|
||||
return cursorColor != oldWidget.cursorColor ||
|
||||
selectionColor != oldWidget.selectionColor;
|
||||
}
|
||||
}
|
||||
|
||||
class _NullWidget extends StatelessWidget {
|
||||
const _NullWidget();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
throw FlutterError(
|
||||
'A DefaultTextStyle constructed with DefaultTextStyle.fallback cannot be incorporated into the widget tree, '
|
||||
'it is meant only to provide a fallback value returned by DefaultTextStyle.of() '
|
||||
'when no enclosing default text style is present in a BuildContext.',
|
||||
);
|
||||
}
|
||||
}
|
@ -20,7 +20,6 @@ import 'basic.dart';
|
||||
import 'binding.dart';
|
||||
import 'constants.dart';
|
||||
import 'debug.dart';
|
||||
import 'default_selection_style.dart';
|
||||
import 'focus_manager.dart';
|
||||
import 'focus_scope.dart';
|
||||
import 'focus_traversal.dart';
|
||||
@ -961,9 +960,6 @@ class EditableText extends StatefulWidget {
|
||||
|
||||
/// The color to use when painting the selection.
|
||||
///
|
||||
/// If this property is null, this widget gets the selection color from the
|
||||
/// [DefaultSelectionStyle].
|
||||
///
|
||||
/// For [CupertinoTextField]s, the value is set to the ambient
|
||||
/// [CupertinoThemeData.primaryColor] with 20% opacity. For [TextField]s, the
|
||||
/// value is set to the ambient [TextSelectionThemeData.selectionColor].
|
||||
@ -3253,8 +3249,6 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
|
||||
assert(debugCheckHasMediaQuery(context));
|
||||
super.build(context); // See AutomaticKeepAliveClientMixin.
|
||||
|
||||
final Color? effectiveSelectionColor = widget.selectionColor ?? DefaultSelectionStyle.of(context).selectionColor;
|
||||
|
||||
final TextSelectionControls? controls = widget.selectionControls;
|
||||
return MouseRegion(
|
||||
cursor: widget.mouseCursor ?? SystemMouseCursors.text,
|
||||
@ -3316,7 +3310,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
|
||||
minLines: widget.minLines,
|
||||
expands: widget.expands,
|
||||
strutStyle: widget.strutStyle,
|
||||
selectionColor: effectiveSelectionColor,
|
||||
selectionColor: widget.selectionColor,
|
||||
textScaleFactor: widget.textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
|
||||
textAlign: widget.textAlign,
|
||||
textDirection: _textDirection,
|
||||
|
@ -34,7 +34,6 @@ export 'src/widgets/bottom_navigation_bar_item.dart';
|
||||
export 'src/widgets/color_filter.dart';
|
||||
export 'src/widgets/container.dart';
|
||||
export 'src/widgets/debug.dart';
|
||||
export 'src/widgets/default_selection_style.dart';
|
||||
export 'src/widgets/default_text_editing_shortcuts.dart';
|
||||
export 'src/widgets/desktop_text_selection_toolbar_layout_delegate.dart';
|
||||
export 'src/widgets/dismissible.dart';
|
||||
|
@ -17,7 +17,6 @@ import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle, Color;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart' show DragStartBehavior, PointerDeviceKind, kSecondaryMouseButton, kDoubleTapTimeout;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@ -407,32 +406,6 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'uses DefaultSelectionStyle for selection and cursor colors if provided',
|
||||
(WidgetTester tester) async {
|
||||
const Color selectionColor = Colors.black;
|
||||
const Color cursorColor = Colors.white;
|
||||
|
||||
await tester.pumpWidget(
|
||||
const CupertinoApp(
|
||||
home: Center(
|
||||
child: DefaultSelectionStyle(
|
||||
selectionColor: selectionColor,
|
||||
cursorColor: cursorColor,
|
||||
child: CupertinoTextField(
|
||||
autofocus: true,
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText));
|
||||
expect(state.widget.selectionColor, selectionColor);
|
||||
expect(state.widget.cursorColor, cursorColor);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'multi-lined text fields are intrinsically taller no-strut',
|
||||
(WidgetTester tester) async {
|
||||
|
@ -170,7 +170,6 @@ void main() {
|
||||
' _InheritedTheme\n'
|
||||
' Theme\n'
|
||||
' AnimatedTheme\n'
|
||||
' DefaultSelectionStyle\n'
|
||||
' _ScaffoldMessengerScope\n'
|
||||
' ScaffoldMessenger\n'
|
||||
' Builder\n'
|
||||
|
@ -286,27 +286,6 @@ void main() {
|
||||
skip: isContextMenuProvidedByPlatform, // [intended] only applies to platforms where we supply the context menu.
|
||||
);
|
||||
|
||||
testWidgets('uses DefaultSelectionStyle for selection and cursor colors if provided', (WidgetTester tester) async {
|
||||
const Color selectionColor = Colors.orange;
|
||||
const Color cursorColor = Colors.red;
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Material(
|
||||
child: DefaultSelectionStyle(
|
||||
selectionColor: selectionColor,
|
||||
cursorColor: cursorColor,
|
||||
child: TextField(autofocus: true),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText));
|
||||
expect(state.widget.selectionColor, selectionColor);
|
||||
expect(state.widget.cursorColor, cursorColor);
|
||||
});
|
||||
|
||||
testWidgets('Activates the text field when receives semantics focus on Mac, Windows', (WidgetTester tester) async {
|
||||
final SemanticsTester semantics = SemanticsTester(tester);
|
||||
final SemanticsOwner semanticsOwner = tester.binding.pipelineOwner.semanticsOwner!;
|
||||
|
@ -262,43 +262,4 @@ void main() {
|
||||
final RenderEditable renderSelectable = selectableTextState.renderEditable;
|
||||
expect(renderSelectable.cursorColor, cursorColor.withAlpha(0));
|
||||
});
|
||||
|
||||
testWidgets('TextSelectionThem overrides DefaultSelectionStyle', (WidgetTester tester) async {
|
||||
const Color themeSelectionColor = Color(0xffaabbcc);
|
||||
const Color themeCursorColor = Color(0x00ccbbaa);
|
||||
const Color defaultSelectionColor = Color(0xffaa1111);
|
||||
const Color defaultCursorColor = Color(0x00cc2222);
|
||||
final Key defaultSelectionStyle = UniqueKey();
|
||||
final Key themeStyle = UniqueKey();
|
||||
// Test TextField's cursor color.
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DefaultSelectionStyle(
|
||||
selectionColor: defaultSelectionColor,
|
||||
cursorColor: defaultCursorColor,
|
||||
child: Container(
|
||||
key: defaultSelectionStyle,
|
||||
child: TextSelectionTheme(
|
||||
data: const TextSelectionThemeData(
|
||||
selectionColor: themeSelectionColor,
|
||||
cursorColor: themeCursorColor,
|
||||
),
|
||||
child: Placeholder(
|
||||
key: themeStyle,
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
final BuildContext defaultSelectionStyleContext = tester.element(find.byKey(defaultSelectionStyle));
|
||||
DefaultSelectionStyle style = DefaultSelectionStyle.of(defaultSelectionStyleContext);
|
||||
expect(style.selectionColor, defaultSelectionColor);
|
||||
expect(style.cursorColor, defaultCursorColor);
|
||||
|
||||
final BuildContext themeStyleContext = tester.element(find.byKey(themeStyle));
|
||||
style = DefaultSelectionStyle.of(themeStyleContext);
|
||||
expect(style.selectionColor, themeSelectionColor);
|
||||
expect(style.cursorColor, themeCursorColor);
|
||||
});
|
||||
}
|
||||
|
@ -660,36 +660,6 @@ void main() {
|
||||
expect(focusNode.hasFocus, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('use DefaultSelectionStyle for selection color', (WidgetTester tester) async {
|
||||
const TextEditingValue value = TextEditingValue(
|
||||
text: 'test test',
|
||||
selection: TextSelection(affinity: TextAffinity.upstream, baseOffset: 5, extentOffset: 7),
|
||||
);
|
||||
const Color selectionColor = Colors.orange;
|
||||
controller.value = value;
|
||||
await tester.pumpWidget(
|
||||
DefaultSelectionStyle(
|
||||
selectionColor: selectionColor,
|
||||
child: MediaQuery(
|
||||
data: const MediaQueryData(),
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: EditableText(
|
||||
controller: controller,
|
||||
backgroundCursorColor: Colors.grey,
|
||||
focusNode: focusNode,
|
||||
keyboardType: TextInputType.multiline,
|
||||
style: textStyle,
|
||||
cursorColor: cursorColor,
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText));
|
||||
expect(state.renderEditable.selectionColor, selectionColor);
|
||||
});
|
||||
|
||||
testWidgets('visiblePassword keyboard is requested when set explicitly', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
|
@ -297,27 +297,6 @@ void main() {
|
||||
expect(tester.testTextInput.hasAnyClients, false);
|
||||
});
|
||||
|
||||
testWidgets('uses DefaultSelectionStyle for selection and cursor colors if provided', (WidgetTester tester) async {
|
||||
const Color selectionColor = Colors.orange;
|
||||
const Color cursorColor = Colors.red;
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Material(
|
||||
child: DefaultSelectionStyle(
|
||||
selectionColor: selectionColor,
|
||||
cursorColor: cursorColor,
|
||||
child: SelectableText('text'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText));
|
||||
expect(state.widget.selectionColor, selectionColor);
|
||||
expect(state.widget.cursorColor, cursorColor);
|
||||
});
|
||||
|
||||
testWidgets('Selectable Text has adaptive size', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
boilerplate(
|
||||
|
Loading…
Reference in New Issue
Block a user