Skip to content

TextField cursor is misplaced when textAlign is end, right, or center #18483

@HansMuller

Description

@HansMuller

TextField cursor is misplaced after one character is input if the TextField's textAlign value is TextAlign.end, TextAlign.right, or TextAlign.center.

This issue just serves to collect the existing issues that have already reported the cursor problem: #17960, #17625, #17945, #18472.

The source of the problem is the call in TextPainter.to_getOffsetFromUpstream() to ui.Paragraph.getBoxesForRange(0, 1). The value returned by getBoxesForRange() would be correct if the text was left/start aligned.

After an additional character is entered, the cursor ends up where it belongs and stays there.

import 'package:flutter/material.dart';

class AlignedTextField extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
        child: new SizedBox(
          width: 200.0,
          child: new TextField(textAlign: TextAlign.end), // or TextAlign.right, TextAlign.center
        ),
      ),
    );
  }
}

void main() {
  runApp(new MaterialApp(home: new AlignedTextField()));
}

cc @jason-simmons

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions