Skip to content

TextField “onChanged” was called multi times when i use Chinese inputting mode! #50163

@EdworldWang

Description

@EdworldWang

Steps to Reproduce

import 'package:flutter/material.dart';

class SearchInputWidget extends StatefulWidget {
  final String preInputText;
  final Function(String text) onSubmitted;

  const SearchInputWidget({
    @required this.onSubmitted,
    this.preInputText
  });

  @override
  State<StatefulWidget> createState() {
    return new _SearchInputWidgetState();
  }
}

class _SearchInputWidgetState extends State<SearchInputWidget> {
  bool showCancel = false;
  String inputText = "";

  @override
  void initState() {
    super.initState();
    this.inputText = (widget.preInputText != null ? widget.preInputText : "");

  }

  @override
  Widget build(BuildContext context) {
    print("searchInput build "+ this.inputText);
    TextEditingController inputController = TextEditingController.fromValue(TextEditingValue(
        text: inputText,  
        selection: TextSelection.fromPosition(TextPosition(
            affinity: TextAffinity.downstream,
            offset: '${inputText}'.length)
        )
    ));
    return new Container(
      //margin: EdgeInsets.only(left: 40, top: 40),
      alignment: Alignment(0, 0),
      height: 44,
      width: 300,
      decoration: new BoxDecoration(
        color: Colors.grey.shade200,
        borderRadius: BorderRadius.all(Radius.circular(12.0)),
        //border: new Border.all(width: 1, color: Colors.red),
      ),
      child: new TextField(
        //maxLines: 1,
        controller: inputController,
        maxLength: 30,
        cursorColor: Colors.black,
        style: TextStyle(fontSize: 16, color: Colors.black),
        onChanged: (text){
          print("searchInput onChanged "+ text);
          setState(() {
            print("searchInput setState "+ text);
            inputText = text;
            showCancel = (text.length > 0);
          });
        },
        onSubmitted: (text) {
          widget.onSubmitted != null && widget.onSubmitted(text);
        },
        decoration: InputDecoration(
          prefixIcon: Icon(
            Icons.search,
            color: Colors.black45,
            size: 24,
          ),
          suffixIcon: new Offstage(
            offstage: !showCancel,
            child: new IconButton(
                icon: Icon(
                  Icons.cancel,
                  color: Colors.black45,
                  size: 20,
                ),
                onPressed: _onClickClear),
          ),
          border: InputBorder.none,
          /*  fillColor: Colors.red,
                    filled: true,*/
          counterText: "", 
        ),
      ),
    );
  }
  void _onClickClear() {
    setState(() {
      inputText = "";
      showCancel = false;
    });
  }
}

but the same code run well if i input in english inputting mode.

flutter: searchInput build
flutter: searchInput onChanged q
flutter: searchInput setState q
**Actual results:** <!-- what did you see? -->
when i input "q" in Chinese inputting mode,the text in the TextField is "qq",here is the log.
flutter: searchInput onChanged q
flutter: searchInput setState q
flutter: searchInput build q
flutter: searchInput onChanged qq
flutter: searchInput setState qq
flutter: searchInput build qq

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: internationalizationSupporting other languages or locales. (aka i18n)a: text inputEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.found in release: 3.10Found to occur in 3.10found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions