Skip to content

TextField handles twinkle when insert text with TextEditingController #36048

Closed
@zmtzawqlp

Description

@zmtzawqlp
Contributor

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));
      });
    }
  }
}
  1. click on TextField then TextField handles shows
  2. click button to insert text by TextEditingController
  3. 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

Activity

changed the title [-]Text handles twinkle when insert text with TextEditingController[/-] [+]TextField handles twinkle when insert text with TextEditingController[/+] on Jul 12, 2019
zmtzawqlp

zmtzawqlp commented on Jul 12, 2019

@zmtzawqlp
ContributorAuthor

image
_selectionOverlay build before RenderEditable ,so TextPainter is not change at that moment

added
a: text inputEntering text in a text field or keyboard related problems
f: material designflutter/packages/flutter/material repository.
frameworkflutter/packages/flutter repository. See also f: labels.
on Jul 12, 2019
zmtzawqlp

zmtzawqlp commented on Jul 13, 2019

@zmtzawqlp
ContributorAuthor

more research
there are three ways to change text

  1. paste
  2. text input
    image

3.change TextEditingController.value/TextEditingController.text
image

i can only find in updateEditingValue(text input)
image
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

added a commit that references this issue on Jul 13, 2019
csells

csells commented on Jan 10, 2020

@csells
Contributor

@zmtzawqlp what is the behavior you expect?

TahaTesser

TahaTesser commented on Jun 5, 2020

@TahaTesser
Member

Hi @zmtzawqlp
Please provide your expect behaviour
Thank you

added
waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds
on Jun 5, 2020
zmtzawqlp

zmtzawqlp commented on Jun 5, 2020

@zmtzawqlp
ContributorAuthor

It's fixed in 1.17.0 now

removed
waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds
on Jun 5, 2020
github-actions

github-actions commented on Aug 20, 2021

@github-actions

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.

locked as resolved and limited conversation to collaborators on Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: text inputEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @csells@zmtzawqlp@shihaohong@TahaTesser

        Issue actions

          TextField handles twinkle when insert text with TextEditingController · Issue #36048 · flutter/flutter