does input content disappear when textfield loses focus?

The Container widget you used for the suffixIcon is taking up all the available space, using a SizedBox widget works well and produces the expected behaviour.

I added an example using your code:

Container(
        width: 330,
        height: 40,
        alignment: Alignment.centerLeft,
        child: TextField(
          controller: inputController,
          focusNode: focusNode,
          style: MyTextStyle.level9,
          keyboardType: TextInputType.number,
          decoration: InputDecoration(
            hintText: 'hint text',
            hintStyle: MyTextStyle.grey,
            border: InputBorder.none,
            suffixIcon: focusNode.hasFocus
                ? IconButton(
                    icon: MyIcon.CloseIcon,
                    onPressed: () {
                      inputController.clear();
                    })
                // use a SizedBox widget instead
                : SizedBox.shrink(),
            filled: true,
          ),
        ),
        decoration: BoxDecoration(
          color: MyColor.MidGray,
        ),
      ),

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top