skip to Main Content

I have tried to change TextFormField prefix icon alignment, but flutter don’t have a property for this.
enter image description here

My code:

TextFormField(
      keyboardType: TextInputType.multiline,
      style: typography.titleMedium,
      validator: (value) {
        if (value.isNullOrEmpty) {
          _shakeDescKey.currentState?.shake();
          return "";
        }
        bloc.onChangeDescription(value!);
        return null;
      },
      decoration: InputDecoration(
        hintText: intl.descMsg,
        hintStyle: typography.titleMedium!
            .apply(color: AppColors.black.withOpacity(0.5)),
        prefixIcon: Icon(FontAwesomeIcons.pen),
      cursorColor: Colors.black,
      maxLines: 6,
 );

I need a property to align vertically prefix icon

2

Answers


  1. This is a solution will help you , If you find another better solution, you can add it here

    you will give to prefixIcon widget like const SizedBox()

    and then wrap TextFormField with a Stack

    and use icon as widget like below code

        Positioned(
              top: 21,
              right:14,
              left: 14,
                 child:  SvgPicture.asset(
                 your icon,
                 height: 17,
                 width: 17,
                   ),
                      )
    

    THIS OUTPUT

    Login or Signup to reply.
  2. Wrap Icon widget in Column:

    prefixIcon: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                   Icon(FontAwesomeIcons.pen),
              ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search