Skip to content

Apps calling clear() on TextEditingController while composing Japanese text crash #24276

@kitoko552

Description

@kitoko552

My app crash when clear() on TextEditingController is run while a user is composing Japanese in TextField.
It might be caused on not only Japanese but also languages that have composing state.
Maybe it's only for iOS devices. It isn't caused in my Android device.

Steps to Reproduce

  1. Compose Japanese text in TextField using TextEditingController.
  2. Run clear() while composing text.
  3. Then the app will crash.

My minimum example is here.
If you tap clear button while composing text, the app will crash.

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController controller = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Debug')),
      body: Center(
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: 24.0),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              _buildTextField(),
              _buildClearButton(),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildTextField() {
    return Flexible(
      child: TextField(
        controller: controller,
        style: TextStyle(
          color: Colors.black,
          fontSize: 16.0,
        ),
      ),
    );
  }

  Widget _buildClearButton() {
    return Container(
      width: 50.0,
      child: FlatButton(
        padding: EdgeInsets.zero,
        child: Text(
          'Clear',
          style: TextStyle(
            fontSize: 16.0,
            fontWeight: FontWeight.bold,
          ),
        ),
        onPressed: () {
          controller.clear();
        },
      ),
    );
  }
}

If you reset composing parameter before running clear(), you can prevent crashing.

controller.value = controller.value.copyWith(
  composing: TextRange(start: 0, end: 0),
);
controller.clear();

Logs

flutter run --verbose

[ +269 ms] ------ Debug phase ------
[        ] Starting debug of dabff3d7df79cccb54e110d1cc49dc18eb8433bd (D21AP, D21AP, uknownos, unkarch) a.k.a. 'iPhone' connected through USB...
[+2231 ms] [  0%] Looking up developer disk image
[  +28 ms] [ 95%] Developer disk image mounted successfully
[ +183 ms] [100%] Connecting to remote debug server
[        ] -------------------------
[  +44 ms] (lldb) command source -s 0 '/tmp/12D98327-8756-4FDE-BE93-862C394B797E/fruitstrap-lldb-prep-cmds-dabff3d7df79cccb54e110d1cc49dc18eb8433bd'
[   +2 ms] Executing commands in '/tmp/12D98327-8756-4FDE-BE93-862C394B797E/fruitstrap-lldb-prep-cmds-dabff3d7df79cccb54e110d1cc49dc18eb8433bd'.
[        ] (lldb)     platform select remote-ios --sysroot '/Users/a13906/Library/Developer/Xcode/iOS DeviceSupport/12.0.1 (16A404)/Symbols'
[        ]   Platform: remote-ios
[        ]  Connected: no
[        ]   SDK Path: "/Users/a13906/Library/Developer/Xcode/iOS DeviceSupport/12.0.1 (16A404)/Symbols"
[        ] (lldb)     target create "/Users/a13906/Development/test_something/build/ios/iphoneos/Runner.app"
[+3873 ms] Current executable set to '/Users/a13906/Development/test_something/build/ios/iphoneos/Runner.app' (arm64).
[        ] (lldb)     script fruitstrap_device_app="/private/var/containers/Bundle/Application/81AA08C0-1403-47D5-95E0-CD97D87A1049/Runner.app"
[        ] (lldb)     script fruitstrap_connect_url="connect://127.0.0.1:51695"
[        ] (lldb)     target modules search-paths add /usr "/Users/a13906/Library/Developer/Xcode/iOS DeviceSupport/12.0.1 (16A404)/Symbols/usr" /System "/Users/a13906/Library/Developer/Xcode/iOS DeviceSupport/12.0.1 (16A404)/Symbols/System" "/private/var/containers/Bundle/Application/81AA08C0-1403-47D5-95E0-CD97D87A1049" "/Users/a13906/Development/test_something/build/ios/iphoneos" "/var/containers/Bundle/Application/81AA08C0-1403-47D5-95E0-CD97D87A1049" "/Users/a13906/Development/test_something/build/ios/iphoneos" /Developer "/Users/a13906/Library/Developer/Xcode/iOS DeviceSupport/12.0.1 (16A404)/Symbols/Developer"
[  +59 ms] (lldb)     command script import "/tmp/12D98327-8756-4FDE-BE93-862C394B797E/fruitstrap_dabff3d7df79cccb54e110d1cc49dc18eb8433bd.py"
[   +7 ms] (lldb)     command script add -f fruitstrap_dabff3d7df79cccb54e110d1cc49dc18eb8433bd.connect_command connect
[        ] (lldb)     command script add -s asynchronous -f fruitstrap_dabff3d7df79cccb54e110d1cc49dc18eb8433bd.run_command run
[        ] (lldb)     command script add -s asynchronous -f fruitstrap_dabff3d7df79cccb54e110d1cc49dc18eb8433bd.autoexit_command autoexit
[        ] (lldb)     command script add -s asynchronous -f fruitstrap_dabff3d7df79cccb54e110d1cc49dc18eb8433bd.safequit_command safequit
[        ] (lldb)     connect
[  +34 ms] (lldb)     run
[ +126 ms] success
[        ] (lldb)     safequit
[ +113 ms] Process 2258 detached
[  +37 ms] Application launched on the device. Waiting for observatory port.
[ +389 ms] Observatory URL on device: http://127.0.0.1:53330/
[   +1 ms] attempting to forward device port 53330 to host port 1024
[        ] executing: /usr/local/bin/iproxy 1024 53330 dabff3d7df79cccb54e110d1cc49dc18eb8433bd
[   +9 ms] attempting to forward device port 53330 to host port 1025
[        ] executing: /usr/local/bin/iproxy 1025 53330 dabff3d7df79cccb54e110d1cc49dc18eb8433bd
[+1018 ms] Forwarded port ForwardedPort HOST:1025 to DEVICE:53330
[        ] Forwarded host port 1025 to device port 53330 for Observatory
[   +1 ms] Installing and launching... (completed)
[   +3 ms] Connecting to service protocol: http://127.0.0.1:1025/
[ +163 ms] Successfully connected to service protocol: http://127.0.0.1:1025/
[   +2 ms] Sending to VM service: getVM({})
[   +5 ms] Result: {type: VM, name: vm, architectureBits: 64, targetCPU: dbc, hostCPU: Unknown, version: 2.1.0-dev.9.3.flutter-9c07fb64c4 (Wed Nov 7 06:47:47 2018 +0100) on "ios_dbc", _profilerMode: VM, _nativeZoneMemoryUsage: 0, pid: 2258, startTime: 1542084414182,...
[   +3 ms] Sending to VM service: getIsolate({isolateId: isolates/594973977})
[   +3 ms] Sending to VM service: _flutter.listViews({})
[  +33 ms] Result: {type: Isolate, fixedId: true, id: isolates/594973977, name: main.dart:main.dart(), number: 594973977, _originNumber: 594973977, startTime: 1542084414194, _heaps: {new: {type: HeapSpace, name: new, vmName: Scavenger, collections: 4, avgCollectionP...
[   +9 ms] Result: {type: FlutterViewList, views: [{type: FlutterView, id: _flutterView/0x108813568, isolate: {type: @Isolate, fixedId: true, id: isolates/594973977, name: main.dart$main.dart-594973977, number: 594973977}}]}
[   +4 ms] DevFS: Creating new filesystem on the device (null)
[        ] Sending to VM service: _createDevFS({fsName: test_something})
[  +14 ms] Result: {type: FileSystem, name: test_something, uri: file:///private/var/mobile/Containers/Data/Application/AE8AEC9E-84FA-43BC-BBE4-DCA9AFB38661/tmp/test_somethingx7rLDX/test_something/}
[        ] DevFS: Created new filesystem on the device (file:///private/var/mobile/Containers/Data/Application/AE8AEC9E-84FA-43BC-BBE4-DCA9AFB38661/tmp/test_somethingx7rLDX/test_something/)
[   +1 ms] Updating assets
[ +110 ms] Syncing files to device iPhone...
[   +1 ms] DevFS: Starting sync from LocalDirectory: '/Users/a13906/Development/test_something'
[        ] Scanning project files
[   +3 ms] Scanning package files
[  +88 ms] Scanning asset files
[   +1 ms] Scanning for deleted files
[  +10 ms] Compiling dart to kernel with 443 updated files
[   +5 ms] /Users/a13906/Development/flutter/bin/cache/dart-sdk/bin/dart /Users/a13906/Development/flutter/bin/cache/artifacts/engine/darwin-x64/frontend_server.dart.snapshot --sdk-root /Users/a13906/Development/flutter/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --incremental --strong --target=flutter --output-dill build/app.dill --packages /Users/a13906/Development/test_something/.packages --filesystem-scheme org-dartlang-root
[+1114 ms] Updating files
[ +115 ms] DevFS: Sync finished
[        ] Syncing files to device iPhone... (completed)
[        ] Synced 0.8MB.
[   +1 ms] Sending to VM service: _flutter.listViews({})
[   +3 ms] Result: {type: FlutterViewList, views: [{type: FlutterView, id: _flutterView/0x108813568, isolate: {type: @Isolate, fixedId: true, id: isolates/594973977, name: main.dart$main.dart-594973977, number: 594973977}}]}
[        ] Connected to _flutterView/0x108813568.
[   +1 ms] 🔥  To hot reload changes while running, press "r". To hot restart (and rebuild state), press "R".
[        ] An Observatory debugger and profiler on iPhone is available at: http://127.0.0.1:1025/
[        ] For a more detailed help message, press "h". To detach, press "d"; to quit, press "q".
[+8804 ms] Service protocol connection closed.
[   +1 ms] Lost connection to device.
[   +1 ms] DevFS: Deleting filesystem on the device (file:///private/var/mobile/Containers/Data/Application/AE8AEC9E-84FA-43BC-BBE4-DCA9AFB38661/tmp/test_somethingx7rLDX/test_something/)
[        ] Sending to VM service: _deleteDevFS({fsName: test_something})
[ +260 ms] TimeoutException after 0:00:00.250000: Future not completed
[   +6 ms] "flutter run" took 37,754ms.

flutter analyze

No issues found! (ran in 3.5s)

flutter doctor

[✓] Flutter (Channel dev, v0.11.3, on Mac OS X 10.13.6 17G65, locale ja-JP)
    • Flutter version 0.11.3 at /Users/a13906/Development/flutter
    • Framework revision 72bf075e8d (3 days ago), 2018-11-09 20:36:17 -0800
    • Engine revision 5646e86a6f
    • Dart version 2.1.0 (build 2.1.0-dev.9.3 9c07fb64c4)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/a13906/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.0, Build version 10A255
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 30.0.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] IntelliJ IDEA Community Edition (version 2018.1.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 24.1.2
    • Dart plugin version 181.4668.60

[!] VS Code (version 1.27.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (1 available)
    • iPhone • dabff3d7df79cccb54e110d1cc49dc18eb8433bd • ios • iOS 12.0.1

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

a: internationalizationSupporting other languages or locales. (aka i18n)a: text inputEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consoleengineflutter/engine related. See also e: labels.frameworkflutter/packages/flutter repository. See also f: labels.platform-iosiOS applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions