When writing in input the text starts in the middle instead of the beginning

Asked

Viewed 32 times

-2

When writing in the input the text starts in the middle instead of the beginning. How do I change it? I already changed the padding but the text stays in the middle.

Sample image:

inserir a descrição da imagem aqui

Code:

    Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    elevation: (0),
    backgroundColor: Colors.grey[50],
    leading: IconButton(
      icon: Icon(Icons.arrow_back, size: 40),
      color: Colors.grey[600],
      onPressed: () {},
    ),
  ),
  body: Center(
    child: Column(
      children: <Widget>[
        Container(
          margin: EdgeInsets.fromLTRB(25, 15, 220, 50),
          padding: EdgeInsets.only(top: 20.0),
          child: Text(
            "Cadastro",
            style: TextStyle(
                fontSize: 36,
                fontWeight: FontWeight.bold,
                color: Colors.grey[600]),
          ),
        ),
        Row(mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[
          Container(
            padding: EdgeInsets.fromLTRB(50, 10, 50, 10),
            alignment: Alignment.center,
            child: Text("Nome",
                style: TextStyle(
                  fontSize: 17,
                )),
          )
        ]),
        Container(
          margin: EdgeInsets.only(),
          padding: EdgeInsets.fromLTRB(50, 10, 50, 10),
          child: TextFormField(
            decoration: InputDecoration(
              contentPadding: EdgeInsets.fromLTRB(50, 38, 50, 10),
              filled: true,
              fillColor: Colors.white,
              border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(5),
              ),
            ),
          ),
        ),
        Row(mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[
          Container(
            padding: EdgeInsets.fromLTRB(50, 10, 50, 10),
            alignment: Alignment.center,
            child: Text("E-mail",
                style: TextStyle(
                  fontSize: 17,
                )),
          )
        ]),
  • Man on Textformfield you’re putting 38 padding, wouldn’t that be it?

1 answer

1

Your problem is in question the padding...

  TextFormField(
    decoration: InputDecoration(
      contentPadding: EdgeInsets.fromLTRB(50, 38, 50, 10),
      filled: true,
      fillColor: Colors.blue,
      
      border: OutlineInputBorder(
        borderRadius: BorderRadius.circular(5),
      ),
    ),
  ),

Are you wearing a contentpadding, which in turn puts "spaces" on each side...

So that the text starts at the beginning of your Textformfield, just decrease the padding LEFT:

contentPadding: EdgeInsets.fromLTRB(10, 38, 50, 10),

Explanation

The contentPadding will create internal spacing within your Widget, in relation to the content of the same, this property asks for a EdgeInsetsGeometry that in turn you are using the fromLTRB

That guy means:

EdgeInsets.fromLTRB(left, top, right, bottom)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.