Skip to content

Selection handles position is off when switch between obscureText and non-obscureText #34607

@chunhtai

Description

@chunhtai
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool obscureText = false;
  TextEditingController controller = TextEditingController(text: 'asd asd');
  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(

        title: Text(widget.title),
        actions: <Widget>[IconButton(
          icon: Icon(Icons.clear),
          onPressed: () {
            setState(() {
              obscureText = !obscureText;
            });
          },
        )]
      ),
      body: Center(

        child: Column(

          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextField( controller: controller,
              obscureText: obscureText,
            ),
          ],
        ),
      ),
    );
  }
}

1, select at the end of text
2, click the 'X' button in the top right
3, you will see the text gets shorten because obscured characters are smaller. however the selection handles does not update its position.

This also apply to changing text width or height without changing the texteditingvalue, ex changing style , structstyle.

Metadata

Metadata

Assignees

Labels

a: text inputEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions