Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I center the posts in the widget I created?

TextField textWidget(String text, IconData icon, bool isPasswordType,
    TextEditingController controller, TextAlign align) {
  return TextField(
    controller: controller,
    obscureText: isPasswordType,
    enableSuggestions: !isPasswordType,
    autocorrect: !isPasswordType,
    cursorColor: Colors.white,
    style: TextStyle(color: Colors.white.withOpacity(0.9)),
    decoration: InputDecoration(
      prefixIcon: Icon(
        icon,
        color: Colors.white70,
      ),
      labelText: text,
      labelStyle: TextStyle(color: Colors.white.withOpacity(0.9)),
      filled: true,
      floatingLabelBehavior: FloatingLabelBehavior.never,
      fillColor: const Color.fromARGB(255, 209, 107, 107).withOpacity(0.7),
      border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(30.0),
          borderSide: const BorderSide(width: 0, style: BorderStyle.none)),
    ),
    keyboardType: isPasswordType
        ? TextInputType.visiblePassword
        : TextInputType.emailAddress,
  );}

I created a widget called textWidget and it’s;

child: textWidget(
  "Mail Adress",
   Icons.people_alt_outlined,
   false,
   _numberController,
   TextAlign.center),

I tried to add it like this. I call in textWidget;

(String text, IconData icon, bool isPasswordType,TextEditingController controller, TextAlign align)

I assigned all the values ​​as seen in the second code. However, this did not bring the articles to the middle of the label.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

You can use label to place Text widget instead of labelText

  decoration: InputDecoration(
        label: Center(
          child: Text(
            text,
            style: TextStyle(
              color: Colors.white.withOpacity(0.9),
            ),
          ),
        ), 
 TextField textWidget(String text, IconData icon, bool isPasswordType,
      TextEditingController controller, TextAlign align) {
    return TextField(
      controller: controller,
      obscureText: isPasswordType,
      enableSuggestions: !isPasswordType,
      autocorrect: !isPasswordType,
      cursorColor: Colors.white,
      textAlign: TextAlign.center,
      style: TextStyle(color: Colors.white.withOpacity(0.9)),
      decoration: InputDecoration(
        label: Center(
          child: Text(
            text,
            style: TextStyle(
              color: Colors.white.withOpacity(0.9),
            ),
          ),
        ),
        prefixIcon: Icon(
          icon,
          color: Colors.white70,
        ),
        filled: true,
        floatingLabelBehavior: FloatingLabelBehavior.never,
        fillColor: const Color.fromARGB(255, 209, 107, 107).withOpacity(0.7),
        border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(30.0),
            borderSide: const BorderSide(width: 0, style: BorderStyle.none)),
      ),
      keyboardType: isPasswordType
          ? TextInputType.visiblePassword
          : TextInputType.emailAddress,
    );
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading