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
60f30e5d
Unverified
Commit
60f30e5d
authored
Jun 22, 2022
by
LongCatIsLooong
Committed by
GitHub
Jun 22, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable cursor opacity animation on macOS, make iOS cursor animation discrete (#104335)
parent
18575321
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
238 additions
and
228 deletions
+238
-228
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+1
-1
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+143
-77
text_field_test.dart
packages/flutter/test/cupertino/text_field_test.dart
+0
-34
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+1
-37
editable_text_cursor_test.dart
packages/flutter/test/widgets/editable_text_cursor_test.dart
+93
-43
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+0
-36
No files found.
packages/flutter/lib/src/material/text_field.dart
View file @
60f30e5d
...
...
@@ -1168,7 +1168,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
forcePressEnabled
=
false
;
textSelectionControls
??=
cupertinoDesktopTextSelectionControls
;
paintCursorAboveText
=
true
;
cursorOpacityAnimates
=
tru
e
;
cursorOpacityAnimates
=
fals
e
;
cursorColor
=
widget
.
cursorColor
??
selectionStyle
.
cursorColor
??
cupertinoTheme
.
primaryColor
;
selectionColor
=
selectionStyle
.
selectionColor
??
cupertinoTheme
.
primaryColor
.
withOpacity
(
0.40
);
cursorRadius
??=
const
Radius
.
circular
(
2.0
);
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
60f30e5d
This diff is collapsed.
Click to expand it.
packages/flutter/test/cupertino/text_field_test.dart
View file @
60f30e5d
...
...
@@ -702,40 +702,6 @@ void main() {
expect
(
editableText
.
cursorOffset
,
const
Offset
(-
2.0
/
3.0
,
0
));
});
testWidgets
(
'Cursor animates'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
CupertinoApp
(
home:
CupertinoTextField
(),
),
);
final
Finder
textFinder
=
find
.
byType
(
CupertinoTextField
);
await
tester
.
tap
(
textFinder
);
await
tester
.
pump
();
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
final
RenderEditable
renderEditable
=
editableTextState
.
renderEditable
;
expect
(
renderEditable
.
cursorColor
!.
alpha
,
255
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
400
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
255
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
110
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
16
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
0
);
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}));
testWidgets
(
'Cursor radius is 2.0'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
CupertinoApp
(
...
...
packages/flutter/test/material/text_field_test.dart
View file @
60f30e5d
...
...
@@ -609,42 +609,6 @@ void main() {
await
checkCursorToggle
();
});
testWidgets
(
'Cursor animates'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
MaterialApp
(
home:
Material
(
child:
TextField
(),
),
),
);
final
Finder
textFinder
=
find
.
byType
(
TextField
);
await
tester
.
tap
(
textFinder
);
await
tester
.
pump
();
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
final
RenderEditable
renderEditable
=
editableTextState
.
renderEditable
;
expect
(
renderEditable
.
cursorColor
!.
alpha
,
255
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
400
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
255
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
110
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
16
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
0
);
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}));
// Regression test for https://github.com/flutter/flutter/issues/78918.
testWidgets
(
'RenderEditable sets correct text editing value'
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
controller
=
TextEditingController
(
text:
'how are you'
);
...
...
@@ -1328,7 +1292,7 @@ void main() {
editText
=
(
findRenderEditable
(
tester
).
text
!
as
TextSpan
).
text
!;
expect
(
editText
.
substring
(
editText
.
length
-
1
),
'
\
u2022'
);
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
android
}));
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
android
}));
testWidgets
(
'desktop obscureText control test'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
...
...
packages/flutter/test/widgets/editable_text_cursor_test.dart
View file @
60f30e5d
...
...
@@ -166,61 +166,75 @@ void main() {
);
});
testWidgets
(
'Cursor animates'
,
(
WidgetTester
tester
)
async
{
const
Widget
widget
=
MaterialApp
(
home:
Material
(
child:
TextField
(
maxLines:
3
,
testWidgets
(
'Cursor animates
on iOS
'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
MaterialApp
(
home:
Material
(
child:
TextField
()
,
),
),
);
await
tester
.
pumpWidget
(
widget
);
await
tester
.
tap
(
find
.
byType
(
TextField
));
final
Finder
textFinder
=
find
.
byType
(
TextField
);
await
tester
.
tap
(
textFinder
);
await
tester
.
pump
();
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
final
RenderEditable
renderEditable
=
editableTextState
.
renderEditable
;
expect
(
renderEditable
.
cursorColor
!.
alpha
,
255
);
expect
(
renderEditable
.
cursorColor
!.
opacity
,
1.0
);
int
walltimeMicrosecond
=
0
;
double
lastVerifiedOpacity
=
1.0
;
Future
<
void
>
verifyKeyFrame
({
required
double
opacity
,
required
int
at
})
async
{
const
int
delta
=
1
;
assert
(
at
-
delta
>
walltimeMicrosecond
);
await
tester
.
pump
(
Duration
(
microseconds:
at
-
delta
-
walltimeMicrosecond
));
// Instead of verifying the opacity at each key frame, this function
// verifies the opacity immediately *before* each key frame to avoid
// fp precision issues.
expect
(
renderEditable
.
cursorColor
!.
opacity
,
closeTo
(
lastVerifiedOpacity
,
0.01
),
reason:
'opacity at
${at-delta}
microseconds'
,
);
walltimeMicrosecond
=
at
-
delta
;
lastVerifiedOpacity
=
opacity
;
}
await
verifyKeyFrame
(
opacity:
1.0
,
at:
500000
);
await
verifyKeyFrame
(
opacity:
0.75
,
at:
537500
);
await
verifyKeyFrame
(
opacity:
0.5
,
at:
575000
);
await
verifyKeyFrame
(
opacity:
0.25
,
at:
612500
);
await
verifyKeyFrame
(
opacity:
0.0
,
at:
650000
);
await
verifyKeyFrame
(
opacity:
0.0
,
at:
850000
);
await
verifyKeyFrame
(
opacity:
0.25
,
at:
887500
);
await
verifyKeyFrame
(
opacity:
0.5
,
at:
925000
);
await
verifyKeyFrame
(
opacity:
0.75
,
at:
962500
);
await
verifyKeyFrame
(
opacity:
1.0
,
at:
1000000
);
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
}));
testWidgets
(
'Cursor does not animate on non-iOS platforms'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
MaterialApp
(
home:
Material
(
child:
TextField
(
maxLines:
3
)),
),
);
// Trigger initial timer. When focusing the first time, the cursor shows
// for slightly longer than the average on time.
await
tester
.
tap
(
find
.
byType
(
TextField
));
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
// Start timing standard cursor show period.
expect
(
renderEditable
.
cursorColor
!.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rrect
(
color:
const
Color
(
0xff2196f3
)));
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
// Start to animate the cursor away.
expect
(
renderEditable
.
cursorColor
!.
alpha
,
255
);
expect
(
renderEditable
,
paints
..
rrect
(
color:
const
Color
(
0xff2196f3
)));
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
110
);
expect
(
renderEditable
,
paints
..
rrect
(
color:
const
Color
(
0x6e2196f3
)));
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
16
);
expect
(
renderEditable
,
paints
..
rrect
(
color:
const
Color
(
0x102196f3
)));
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
0
);
// Don't try to draw the cursor.
expect
(
renderEditable
,
paintsExactlyCountTimes
(
#drawRRect
,
0
));
// Wait some more while the cursor is gone. It'll trigger the cursor to
// start animating in again.
await
tester
.
pump
(
const
Duration
(
milliseconds:
300
));
expect
(
renderEditable
.
cursorColor
!.
alpha
,
0
);
expect
(
renderEditable
,
paintsExactlyCountTimes
(
#drawRRect
,
0
));
// Wait for the current animation to finish. If the cursor never stops its
// blinking animation the test will timeout.
await
tester
.
pumpAndSettle
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
// Cursor starts coming back.
expect
(
renderEditable
.
cursorColor
!.
alpha
,
79
);
expect
(
renderEditable
,
paints
..
rrect
(
color:
const
Color
(
0x4f2196f3
)));
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}
));
for
(
int
i
=
0
;
i
<
40
;
i
+=
1
)
{
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
expect
(
tester
.
hasRunningAnimations
,
false
);
}
},
variant:
TargetPlatformVariant
(
TargetPlatform
.
values
.
toSet
()..
remove
(
TargetPlatform
.
iOS
)
));
testWidgets
(
'Cursor does not animate on Android'
,
(
WidgetTester
tester
)
async
{
final
Color
defaultCursorColor
=
Color
(
ThemeData
.
fallback
().
colorScheme
.
primary
.
value
);
...
...
@@ -956,4 +970,40 @@ void main() {
);
EditableText
.
debugDeterministicCursor
=
false
;
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}));
testWidgets
(
'password briefly does not show last character when disabled by system'
,
(
WidgetTester
tester
)
async
{
final
bool
debugDeterministicCursor
=
EditableText
.
debugDeterministicCursor
;
EditableText
.
debugDeterministicCursor
=
false
;
addTearDown
(()
{
EditableText
.
debugDeterministicCursor
=
debugDeterministicCursor
;
});
await
tester
.
pumpWidget
(
MaterialApp
(
home:
EditableText
(
backgroundCursorColor:
Colors
.
grey
,
controller:
controller
,
obscureText:
true
,
focusNode:
focusNode
,
style:
textStyle
,
cursorColor:
cursorColor
,
),
));
await
tester
.
enterText
(
find
.
byType
(
EditableText
),
'AA'
);
await
tester
.
pump
();
await
tester
.
enterText
(
find
.
byType
(
EditableText
),
'AAA'
);
await
tester
.
pump
();
tester
.
binding
.
platformDispatcher
.
brieflyShowPasswordTestValue
=
false
;
addTearDown
(()
{
tester
.
binding
.
platformDispatcher
.
brieflyShowPasswordTestValue
=
true
;
});
expect
((
findRenderEditable
(
tester
).
text
!
as
TextSpan
).
text
,
'••A'
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
expect
((
findRenderEditable
(
tester
).
text
!
as
TextSpan
).
text
,
'•••'
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
expect
((
findRenderEditable
(
tester
).
text
!
as
TextSpan
).
text
,
'•••'
);
});
}
packages/flutter/test/widgets/editable_text_test.dart
View file @
60f30e5d
...
...
@@ -3943,42 +3943,6 @@ void main() {
expect
((
findRenderEditable
(
tester
).
text
!
as
TextSpan
).
text
,
'•••'
);
});
testWidgets
(
'password briefly does not show last character on Android if turned off'
,
(
WidgetTester
tester
)
async
{
final
bool
debugDeterministicCursor
=
EditableText
.
debugDeterministicCursor
;
EditableText
.
debugDeterministicCursor
=
false
;
addTearDown
(()
{
EditableText
.
debugDeterministicCursor
=
debugDeterministicCursor
;
});
await
tester
.
pumpWidget
(
MaterialApp
(
home:
EditableText
(
backgroundCursorColor:
Colors
.
grey
,
controller:
controller
,
obscureText:
true
,
focusNode:
focusNode
,
style:
textStyle
,
cursorColor:
cursorColor
,
),
));
await
tester
.
enterText
(
find
.
byType
(
EditableText
),
'AA'
);
await
tester
.
pump
();
await
tester
.
enterText
(
find
.
byType
(
EditableText
),
'AAA'
);
await
tester
.
pump
();
tester
.
binding
.
platformDispatcher
.
brieflyShowPasswordTestValue
=
false
;
addTearDown
(()
{
tester
.
binding
.
platformDispatcher
.
brieflyShowPasswordTestValue
=
true
;
});
expect
((
findRenderEditable
(
tester
).
text
!
as
TextSpan
).
text
,
'••A'
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
expect
((
findRenderEditable
(
tester
).
text
!
as
TextSpan
).
text
,
'•••'
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
expect
((
findRenderEditable
(
tester
).
text
!
as
TextSpan
).
text
,
'•••'
);
});
group
(
'a11y copy/cut/paste'
,
()
{
Future
<
void
>
buildApp
(
MockTextSelectionControls
controls
,
WidgetTester
tester
)
{
return
tester
.
pumpWidget
(
MaterialApp
(
...
...
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