Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextField handles twinkle when insert text with TextEditingController #36048

Closed
zmtzawqlp opened this issue Jul 12, 2019 · 6 comments
Closed
Labels
a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Comments

@zmtzawqlp
Copy link
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

@zmtzawqlp zmtzawqlp changed the title Text handles twinkle when insert text with TextEditingController TextField handles twinkle when insert text with TextEditingController Jul 12, 2019
@zmtzawqlp
Copy link
Contributor Author

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

@shihaohong shihaohong added a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jul 12, 2019
@zmtzawqlp
Copy link
Contributor Author

zmtzawqlp commented Jul 13, 2019

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

zmtzawqlp added a commit to fluttercandies/extended_text_field that referenced this issue Jul 13, 2019
@csells
Copy link
Contributor

csells commented Jan 10, 2020

@zmtzawqlp what is the behavior you expect?

@TahaTesser
Copy link
Member

Hi @zmtzawqlp
Please provide your expect behaviour
Thank you

@TahaTesser TahaTesser added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jun 5, 2020
@zmtzawqlp
Copy link
Contributor Author

It's fixed in 1.17.0 now

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jun 5, 2020
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

No branches or pull requests

4 participants