Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a3aeab0c
Unverified
Commit
a3aeab0c
authored
Sep 17, 2020
by
Jonah Williams
Committed by
GitHub
Sep 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "TextSelectionTheme support (step 2 of 3) (#65044)" (#66051)
This reverts commit
cb92ffc7
.
parent
48ba488d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
37 deletions
+67
-37
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+8
-4
theme_data.dart
packages/flutter/lib/src/material/theme_data.dart
+1
-10
text_selection_test.dart
packages/flutter/test/material/text_selection_test.dart
+1
-3
text_selection_theme_test.dart
...ages/flutter/test/material/text_selection_theme_test.dart
+46
-7
editable_text_cursor_test.dart
packages/flutter/test/widgets/editable_text_cursor_test.dart
+11
-13
No files found.
packages/flutter/lib/src/material/text_field.dart
View file @
a3aeab0c
...
...
@@ -1098,6 +1098,11 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
}
}
Color
_defaultSelectionColor
(
BuildContext
context
,
Color
primary
)
{
final
bool
isDark
=
Theme
.
of
(
context
).
brightness
==
Brightness
.
dark
;
return
primary
.
withOpacity
(
isDark
?
0.40
:
0.12
);
}
@override
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasMaterial
(
context
));
...
...
@@ -1131,14 +1136,13 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
switch
(
theme
.
platform
)
{
case
TargetPlatform
.
iOS
:
case
TargetPlatform
.
macOS
:
final
CupertinoThemeData
cupertinoTheme
=
CupertinoTheme
.
of
(
context
);
forcePressEnabled
=
true
;
textSelectionControls
=
cupertinoTextSelectionControls
;
paintCursorAboveText
=
true
;
cursorOpacityAnimates
=
true
;
if
(
theme
.
useTextSelectionTheme
)
{
cursorColor
??=
selectionTheme
.
cursorColor
??
cupertinoTheme
.
primaryColor
;
selectionColor
=
selectionTheme
.
selectionColor
??
cupertinoTheme
.
primaryColor
.
withOpacity
(
0.40
);
cursorColor
??=
selectionTheme
.
cursorColor
??
CupertinoTheme
.
of
(
context
)
.
primaryColor
;
selectionColor
=
selectionTheme
.
selectionColor
??
_defaultSelectionColor
(
context
,
CupertinoTheme
.
of
(
context
).
primaryColor
);
}
else
{
cursorColor
??=
CupertinoTheme
.
of
(
context
).
primaryColor
;
selectionColor
=
theme
.
textSelectionColor
;
...
...
@@ -1158,7 +1162,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
cursorOpacityAnimates
=
false
;
if
(
theme
.
useTextSelectionTheme
)
{
cursorColor
??=
selectionTheme
.
cursorColor
??
theme
.
colorScheme
.
primary
;
selectionColor
=
selectionTheme
.
selectionColor
??
theme
.
colorScheme
.
primary
.
withOpacity
(
0.40
);
selectionColor
=
selectionTheme
.
selectionColor
??
_defaultSelectionColor
(
context
,
theme
.
colorScheme
.
primary
);
}
else
{
cursorColor
??=
theme
.
cursorColor
;
selectionColor
=
theme
.
textSelectionColor
;
...
...
packages/flutter/lib/src/material/theme_data.dart
View file @
a3aeab0c
...
...
@@ -405,7 +405,7 @@ class ThemeData with Diagnosticable {
dataTableTheme
??=
const
DataTableThemeData
();
fixTextFieldOutlineLabel
??=
false
;
useTextSelectionTheme
??=
tru
e
;
useTextSelectionTheme
??=
fals
e
;
return
ThemeData
.
raw
(
visualDensity:
visualDensity
,
...
...
@@ -883,21 +883,12 @@ class ThemeData with Diagnosticable {
final
Color
secondaryHeaderColor
;
/// The color of text selections in text fields, such as [TextField].
///
/// By default this property is no longer used. It has been replaced with
/// [TextSelectionThemeData.selectionColor] and will soon be deprecated.
final
Color
textSelectionColor
;
/// The color of cursors in Material-style text fields, such as [TextField].
///
/// By default this property is no longer used. It has been replaced with
/// [TextSelectionThemeData.cursorColor] and will soon be deprecated.
final
Color
cursorColor
;
/// The color of the handles used to adjust what part of the text is currently selected.
///
/// By default this property is no longer used. It has been replaced with
/// [TextSelectionThemeData.selectionHandleColor] and will soon be deprecated.
final
Color
textSelectionHandleColor
;
/// A color that contrasts with the [primaryColor], e.g. used as the
...
...
packages/flutter/test/material/text_selection_test.dart
View file @
a3aeab0c
...
...
@@ -554,9 +554,7 @@ void main() {
await
tester
.
pumpWidget
(
RepaintBoundary
(
child:
Theme
(
data:
ThemeData
(
textSelectionTheme:
const
TextSelectionThemeData
(
selectionHandleColor:
Color
(
0x550000AA
),
),
textSelectionHandleColor:
const
Color
(
0x550000AA
),
),
isMaterialAppTheme:
true
,
child:
Builder
(
...
...
packages/flutter/test/material/text_selection_theme_test.dart
View file @
a3aeab0c
...
...
@@ -58,10 +58,6 @@ void main() {
});
testWidgets
(
'Empty textSelectionTheme will use defaults'
,
(
WidgetTester
tester
)
async
{
const
Color
defaultCursorColor
=
Color
(
0x002196f3
);
const
Color
defaultSelectionColor
=
Color
(
0x662196f3
);
const
Color
defaultSelectionHandleColor
=
Color
(
0xff2196f3
);
// Test TextField's cursor & selection color.
await
tester
.
pumpWidget
(
const
MaterialApp
(
...
...
@@ -73,12 +69,52 @@ void main() {
await
tester
.
pumpAndSettle
();
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
final
RenderEditable
renderEditable
=
editableTextState
.
renderEditable
;
expect
(
renderEditable
.
cursorColor
,
defaultCursorColor
);
expect
(
Color
(
renderEditable
.
selectionColor
.
value
),
defaultSelectionColor
);
expect
(
renderEditable
.
cursorColor
,
const
Color
(
0x004285f4
)
);
expect
(
renderEditable
.
selectionColor
,
const
Color
(
0xFF90CAF9
)
);
// Test the selection handle color.
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
Builder
(
builder:
(
BuildContext
context
)
{
return
materialTextSelectionControls
.
buildHandle
(
context
,
TextSelectionHandleType
.
left
,
10.0
);
},
),
),
),
);
await
tester
.
pumpAndSettle
();
final
RenderBox
handle
=
tester
.
firstRenderObject
<
RenderBox
>(
find
.
byType
(
CustomPaint
));
expect
(
handle
,
paints
..
path
(
color:
Colors
.
blue
[
300
]));
});
testWidgets
(
'Empty textSelectionTheme with useTextSelectionTheme set will use new defaults'
,
(
WidgetTester
tester
)
async
{
final
ThemeData
theme
=
ThemeData
.
fallback
().
copyWith
(
useTextSelectionTheme:
true
);
final
Color
primaryColor
=
Color
(
theme
.
colorScheme
.
primary
.
value
);
// Test TextField's cursor & selection color.
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
theme
,
home:
const
Material
(
child:
TextField
(),
),
),
);
await
tester
.
pumpAndSettle
();
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
final
RenderEditable
renderEditable
=
editableTextState
.
renderEditable
;
expect
(
renderEditable
.
cursorColor
,
primaryColor
.
withAlpha
(
0
));
expect
(
Color
(
renderEditable
.
selectionColor
.
value
),
primaryColor
.
withOpacity
(
0.12
));
// Test the selection handle color.
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
theme
,
home:
Material
(
child:
Builder
(
builder:
(
BuildContext
context
)
{
...
...
@@ -92,7 +128,7 @@ void main() {
);
await
tester
.
pumpAndSettle
();
final
RenderBox
handle
=
tester
.
firstRenderObject
<
RenderBox
>(
find
.
byType
(
CustomPaint
));
expect
(
handle
,
paints
..
path
(
color:
defaultSelectionHandle
Color
));
expect
(
handle
,
paints
..
path
(
color:
primary
Color
));
});
testWidgets
(
'ThemeDate.textSelectionTheme will be used if provided'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -102,6 +138,7 @@ void main() {
selectionHandleColor:
Color
(
0x00ccbbaa
),
);
final
ThemeData
theme
=
ThemeData
.
fallback
().
copyWith
(
useTextSelectionTheme:
true
,
textSelectionTheme:
textSelectionTheme
,
);
...
...
@@ -147,6 +184,7 @@ void main() {
selectionHandleColor:
Color
(
0x00ccbbaa
),
);
final
ThemeData
theme
=
ThemeData
.
fallback
().
copyWith
(
useTextSelectionTheme:
true
,
textSelectionTheme:
defaultTextSelectionTheme
,
);
const
TextSelectionThemeData
widgetTextSelectionTheme
=
TextSelectionThemeData
(
...
...
@@ -202,6 +240,7 @@ void main() {
selectionHandleColor:
Color
(
0x00ccbbaa
),
);
final
ThemeData
theme
=
ThemeData
.
fallback
().
copyWith
(
useTextSelectionTheme:
true
,
textSelectionTheme:
defaultTextSelectionTheme
,
);
const
TextSelectionThemeData
widgetTextSelectionTheme
=
TextSelectionThemeData
(
...
...
packages/flutter/test/widgets/editable_text_cursor_test.dart
View file @
a3aeab0c
...
...
@@ -208,7 +208,6 @@ void main() {
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}));
testWidgets
(
'Cursor does not animate on Android'
,
(
WidgetTester
tester
)
async
{
final
Color
defaultCursorColor
=
Color
(
ThemeData
.
fallback
().
colorScheme
.
primary
.
value
);
const
Widget
widget
=
MaterialApp
(
home:
Material
(
child:
TextField
(
...
...
@@ -226,12 +225,12 @@ void main() {
await
tester
.
pump
();
expect
(
renderEditable
.
cursorColor
.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rect
(
color:
defaultCursorColor
));
expect
(
renderEditable
,
paints
..
rect
(
color:
const
Color
(
0xff4285f4
)
));
// Android cursor goes from exactly on to exactly off on the 500ms dot.
await
tester
.
pump
(
const
Duration
(
milliseconds:
499
));
expect
(
renderEditable
.
cursorColor
.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rect
(
color:
defaultCursorColor
));
expect
(
renderEditable
,
paints
..
rect
(
color:
const
Color
(
0xff4285f4
)
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
1
));
expect
(
renderEditable
.
cursorColor
.
alpha
,
0
);
...
...
@@ -240,7 +239,7 @@ void main() {
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
expect
(
renderEditable
.
cursorColor
.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rect
(
color:
defaultCursorColor
));
expect
(
renderEditable
,
paints
..
rect
(
color:
const
Color
(
0xff4285f4
)
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
expect
(
renderEditable
.
cursorColor
.
alpha
,
0
);
...
...
@@ -249,7 +248,6 @@ void main() {
testWidgets
(
'Cursor does not animates when debugDeterministicCursor is set'
,
(
WidgetTester
tester
)
async
{
EditableText
.
debugDeterministicCursor
=
true
;
final
Color
defaultCursorColor
=
Color
(
ThemeData
.
fallback
().
colorScheme
.
primary
.
value
);
const
Widget
widget
=
MaterialApp
(
home:
Material
(
child:
TextField
(
...
...
@@ -270,24 +268,24 @@ void main() {
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
expect
(
renderEditable
.
cursorColor
.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rrect
(
color:
defaultCursorColor
));
expect
(
renderEditable
,
paints
..
rrect
(
color:
const
Color
(
0xff2196f3
)
));
// Cursor draw never changes.
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
expect
(
renderEditable
.
cursorColor
.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rrect
(
color:
defaultCursorColor
));
expect
(
renderEditable
,
paints
..
rrect
(
color:
const
Color
(
0xff2196f3
)
));
// No more transient calls.
await
tester
.
pumpAndSettle
();
expect
(
renderEditable
.
cursorColor
.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rrect
(
color:
defaultCursorColor
));
expect
(
renderEditable
,
paints
..
rrect
(
color:
const
Color
(
0xff2196f3
)
));
EditableText
.
debugDeterministicCursor
=
false
;
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}));
testWidgets
(
'Cursor does not animate on Android when debugDeterministicCursor is set'
,
(
WidgetTester
tester
)
async
{
final
Color
defaultCursorColor
=
Color
(
ThemeData
.
fallback
().
colorScheme
.
primary
.
value
);
EditableText
.
debugDeterministicCursor
=
true
;
const
Widget
widget
=
MaterialApp
(
home:
Material
(
child:
TextField
(
...
...
@@ -305,21 +303,21 @@ void main() {
await
tester
.
pump
();
expect
(
renderEditable
.
cursorColor
.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rect
(
color:
defaultCursorColor
));
expect
(
renderEditable
,
paints
..
rect
(
color:
const
Color
(
0xff4285f4
)
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
expect
(
renderEditable
.
cursorColor
.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rect
(
color:
defaultCursorColor
));
expect
(
renderEditable
,
paints
..
rect
(
color:
const
Color
(
0xff4285f4
)
));
// Cursor draw never changes.
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
expect
(
renderEditable
.
cursorColor
.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rect
(
color:
defaultCursorColor
));
expect
(
renderEditable
,
paints
..
rect
(
color:
const
Color
(
0xff4285f4
)
));
// No more transient calls.
await
tester
.
pumpAndSettle
();
expect
(
renderEditable
.
cursorColor
.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rect
(
color:
defaultCursorColor
));
expect
(
renderEditable
,
paints
..
rect
(
color:
const
Color
(
0xff4285f4
)
));
EditableText
.
debugDeterministicCursor
=
false
;
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment