fluttertextfieldtexteditingcontroller

Flutter TextField selection highlighter controls appear too high


Screenshot of the issue and code in use below, the selection controls are above the textfield for some bizarre reason.

Example of issue

var textField = TextField(
  selectionHeightStyle: BoxHeightStyle.max,
  scrollPadding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom + 20 * 4),
  textInputAction: TextInputAction.done,
  keyboardType: TextInputType.numberWithOptions(signed: true, decimal: true),
  decoration: InputDecoration(
    border: InputBorder.none,
  ),
  controller: textEditingController,
  onTap: () {
    Future.delayed(const Duration(milliseconds: 800), () {
      textEditingController.selectAll();
    });
  },
  onSubmitted: (newText) {
    if (newText.length == 0) {
      callback(0, true);
    } else {
      callback(int.parse(newText), true);
    }
  },
  textAlign: TextAlign.center,
  style: Theme.of(context).textTheme.headline4!.copyWith(
        fontWeight: FontWeight.w700,
        fontSize: 16.0,
        color: WWColors.pinkBrandColor(),
      ),
);

return Padding(
  padding: padding,
  child: Container(alignment: Alignment.center, child: textField),
);

Solution

  • In answer to my own question, this in the TextField attributes did the job in my case:

      decoration: InputDecoration(
        isDense: true, // important line
        contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
        border: InputBorder.none,
      ),