Skip to content

Characters disappear when adding characters to a TextField while typing with IME. #72980

Description

@MisakoGunjima

I want to input text input with both IME and button on Flutter and Android. I want to input text using both IME and buttons in Flutter and Android. but it is not correct with the following behavior.

  1. press a button while typing a character from IME
  2. enter additional characters from IME
  3. The text entered by the button disappears.
Here's my code
import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(home: HomePage()));
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  TextEditingController _messageInputController;

  @override
  void initState() {
    _messageInputController = TextEditingController();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Demo"),
      ),
      body: SafeArea(
        child: Column(
          children: <Widget>[
            RaisedButton(
                child: Text("add text"),
                onPressed: () {
                  String oldText = _messageInputController.text;
                  String newText = oldText + "insertText";

                  var newValue = _messageInputController.value.copyWith(
                    text: newText,
                    selection: TextSelection.collapsed(
                      offset: newText.length,
                    ),
                    composing: TextRange.empty,
                  );

                  _messageInputController.value = newValue;
                }),
            TextField(
              controller: _messageInputController,
            ),
          ],
        ),
      ),
    );
  }
}
[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.18363.1256], locale ja-JP)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 4.1.0)
    • Android Studio at C:\tools\studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

Metadata

Metadata

Labels

a: text inputEntering text in a text field or keyboard related problemsd: api docsIssues with https://api.flutter.dev/e: device-specificOnly manifests on certain devicesf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer version

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions