Closed
Description
Steps to Reproduce
import 'package:flutter/material.dart';
class TextDeom1 extends StatefulWidget {
@override
_TextDeom1State createState() => _TextDeom1State();
}
class _TextDeom1State extends State<TextDeom1> {
TextEditingController _textEditingController = TextEditingController()
..text = "handles twinkle when insert text with TextEditingController";
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: EdgeInsets.all(50),
child: Column(
children: <Widget>[
FlatButton(
child: Text("inset text"),
onPressed: () {
insertText("test");
},
),
Expanded(
child: TextField(
controller: _textEditingController,
maxLines: null,
//textDirection: TextDirection.rtl,
))
],
),
),
);
}
void insertText(String text) {
var value = _textEditingController.value;
var start = value.selection.baseOffset;
var end = value.selection.extentOffset;
if (value.selection.isValid) {
String newText = "";
if (value.selection.isCollapsed) {
if (end > 0) {
newText += value.text.substring(0, end);
}
newText += text;
if (value.text.length > end) {
newText += value.text.substring(end, value.text.length);
}
} else {
newText = value.text.replaceRange(start, end, text);
}
setState(() {
//FocusScope.of(context).requestFocus(_focusNode);
_textEditingController.value = value.copyWith(
text: newText,
selection: value.selection.copyWith(
baseOffset: end + text.length,
extentOffset: end + text.length));
});
}
}
}
- click on TextField then TextField handles shows
- click button to insert text by TextEditingController
- handles twinkle at Offset.zero
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.7.8+hotfix.3, on Microsoft Windows [Version 10.0.17134.829], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.1)
[√] VS Code (version 1.36.0)
[√] Connected device (1 available)
handles build before text(paragraph.dart) is changed, the selection has changed but text is not changed, so getOffsetForCaret return Offset.zero
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Text handles twinkle when insert text with TextEditingController[/-][+]TextField handles twinkle when insert text with TextEditingController[/+]zmtzawqlp commentedon Jul 12, 2019
_selectionOverlay build before RenderEditable ,so TextPainter is not change at that moment
zmtzawqlp commentedon Jul 13, 2019
more research
there are three ways to change text
3.change TextEditingController.value/TextEditingController.text

i can only find in updateEditingValue(text input)

hide overlay when text is changed
but for case 1 and 3, i think also need to hide overlay when text is changed.
hope this is helpful
fix flutter/flutter#36048
csells commentedon Jan 10, 2020
@zmtzawqlp what is the behavior you expect?
TahaTesser commentedon Jun 5, 2020
Hi @zmtzawqlp
Please provide your expect behaviour
Thank you
zmtzawqlp commentedon Jun 5, 2020
It's fixed in 1.17.0 now
github-actions commentedon Aug 20, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -v
and a minimal reproduction of the issue.