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
210f6f8b
Unverified
Commit
210f6f8b
authored
Jul 06, 2021
by
Ahmed Ashour
Committed by
GitHub
Jul 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix EditableText when a controller listener changes values (#85956)
parent
e1534725
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
2 deletions
+37
-2
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+2
-2
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+35
-0
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
210f6f8b
...
...
@@ -2312,11 +2312,11 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
(
userInteraction
&&
(
cause
==
SelectionChangedCause
.
longPress
||
cause
==
SelectionChangedCause
.
keyboard
)))
{
_handleSelectionChanged
(
value
.
selection
,
cause
);
_handleSelectionChanged
(
_
value
.
selection
,
cause
);
}
if
(
textChanged
)
{
try
{
widget
.
onChanged
?.
call
(
value
.
text
);
widget
.
onChanged
?.
call
(
_
value
.
text
);
}
catch
(
exception
,
stack
)
{
FlutterError
.
reportError
(
FlutterErrorDetails
(
exception:
exception
,
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
210f6f8b
...
...
@@ -6212,6 +6212,41 @@ void main() {
final
TextSpan
textSpan
=
renderEditable
.
text
!
as
TextSpan
;
expect
(
textSpan
.
style
!.
color
,
color
);
});
testWidgets
(
'controller listener changes value'
,
(
WidgetTester
tester
)
async
{
const
double
maxValue
=
5.5555
;
final
TextEditingController
controller
=
TextEditingController
();
controller
.
addListener
(()
{
final
double
value
=
double
.
tryParse
(
controller
.
text
.
trim
())
??
.
0
;
if
(
value
>
maxValue
)
{
controller
.
text
=
maxValue
.
toString
();
controller
.
selection
=
TextSelection
.
fromPosition
(
TextPosition
(
offset:
maxValue
.
toString
().
length
));
}
});
await
tester
.
pumpWidget
(
MaterialApp
(
home:
EditableText
(
controller:
controller
,
focusNode:
focusNode
,
style:
textStyle
,
cursorColor:
Colors
.
blue
,
backgroundCursorColor:
Colors
.
grey
,
),
));
final
EditableTextState
state
=
tester
.
state
<
EditableTextState
>(
find
.
byType
(
EditableText
));
state
.
updateEditingValue
(
const
TextEditingValue
(
text:
'1'
,
selection:
TextSelection
.
collapsed
(
offset:
1
)));
await
tester
.
pump
();
state
.
updateEditingValue
(
const
TextEditingValue
(
text:
'12'
,
selection:
TextSelection
.
collapsed
(
offset:
2
)));
await
tester
.
pump
();
expect
(
controller
.
text
,
'5.5555'
);
expect
(
controller
.
selection
.
baseOffset
,
6
);
expect
(
controller
.
selection
.
extentOffset
,
6
);
});
});
testWidgets
(
'autofocus:true on first frame does not throw'
,
(
WidgetTester
tester
)
async
{
...
...
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