Skip to content

App crash when deleting the password in TextFormField with obscureText is true(Use the keyboard's del button) #33642

@scofield-hello

Description

@scofield-hello
Form(
      key: formGlobalKey,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          TextFormField(
              decoration: const InputDecoration(
                hintText: "设置您的密码",
                labelText: "密码",
              ),
              maxLength: 16,
              obscureText: true,
              keyboardType: TextInputType.text,
              focusNode: passwordFocusNode,
              textInputAction: TextInputAction.next,
              controller: passwordController,
              validator: (value) {
                return passwordRegExp.hasMatch(value) ? null : "密码至少6位字符";
              },
              onFieldSubmitted: (value) {
                FocusScope.of(context).requestFocus(confirmFocusNode);
              }),
          TextFormField(
              decoration: const InputDecoration(
                hintText: "再次确认您的密码",
                labelText: "确认密码",
              ),
              maxLength: 16,
              obscureText: true,
              focusNode: confirmFocusNode,
              keyboardType: TextInputType.text,
              textInputAction: TextInputAction.done,
              controller: confirmController,
              validator: (value) {
                if (passwordRegExp.hasMatch(value)) {
                  if (passwordController.text != value) {
                    return "两次输入的密码不一致";
                  }
                } else {
                  return "密码至少6位字符";
                }
                return null;
              },
              onFieldSubmitted: (value) {
                FocusScope.of(context).unfocus();
              }),
          Padding(
              padding: EdgeInsets.only(top: 5.0),
              child: PrimaryButton(text: "下一步", onPressed: _onFormSubmit)),
        ],
      ),
    );

error message:

E/AndroidRuntime(13559): java.lang.IndexOutOfBoundsException: getChars (0 ... 6) ends beyond length 5
E/AndroidRuntime(13559): at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1018)
E/AndroidRuntime(13559): at android.text.SpannableStringBuilder.getChars(SpannableStringBuilder.java:915)
E/AndroidRuntime(13559): at android.text.SpannableStringBuilder.getTextRunCursor(SpannableStringBuilder.java:1270)
E/AndroidRuntime(13559): at android.graphics.Paint.getTextRunCursor(Paint.java:2082)
E/AndroidRuntime(13559): at android.text.TextLine.getOffsetBeforeAfter(TextLine.java:676)
E/AndroidRuntime(13559): at android.text.TextLine.getOffsetToLeftRightOf(TextLine.java:520)
E/AndroidRuntime(13559): at android.text.Layout.getOffsetToLeftRightOf(Layout.java:1244)
E/AndroidRuntime(13559): at android.text.Layout.getOffsetToLeftOf(Layout.java:1190)
E/AndroidRuntime(13559): at android.text.Selection.extendLeft(Selection.java:321)
E/AndroidRuntime(13559): at io.flutter.plugin.editing.InputConnectionAdaptor.sendKeyEvent(InputConnectionAdaptor.java:155)
E/AndroidRuntime(13559): at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:371)
E/AndroidRuntime(13559): at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
E/AndroidRuntime(13559): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(13559): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(13559): at android.app.ActivityThread.main(ActivityThread.java:5418)
E/AndroidRuntime(13559): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(13559): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(13559): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1037)
E/AndroidRuntime(13559): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)


Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel dev, v1.6.5, on Microsoft Windows [Version 10.0.17763.503], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.4)
[!] VS Code, 64-bit edition (version 1.33.1)
X Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[√] Connected device (1 available)

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: text inputEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consolec: regressionIt was better in the past than it is nowengineflutter/engine related. See also e: labels.platform-androidAndroid applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions