Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple text fields in a row with padding

Tags:

flutter

dart

I want to create a row with multiple texts filed side by side. adding text fileds inside row widget caused errors so I google the problem and found a solution which uses Flexible widget for putting text fields inside a row and It worked perfectly, however when I tried to add padding to text filed in order to have vision of multiple texts filed, it won't work here is my code:

new Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        new Flexible(
          child: new TextField(
              decoration: InputDecoration(
                  contentPadding: EdgeInsets.all(10)
              )
          ),
        ),
        new Flexible(
          child: new TextField(
              decoration: InputDecoration(
                  contentPadding: EdgeInsets.all(10)
              )
          ),
        ),
        new Flexible(
          child: new TextField(
              decoration: InputDecoration(
                  contentPadding: EdgeInsets.all(10)
              )
          ),
        ),
      ],
),

I want to have something like picutre bellow:
enter image description here

how can I add some padding to text filed. And I wonder is there any way that I achieve this with one text filed?

like image 325
Daniel.V Avatar asked Nov 08 '18 21:11

Daniel.V


People also ask

How do you align two text in a row in Flutter?

You just have to add the Row property mainAxisAlignment: MainAxisAlignment.

How do you add multiple Textfields in Flutter?

In Flutter, this can be done using TextEditingController . First, create a TextEditingController and set it as a controller property of your TextField widget. In this example, I have added an extra Button and Text widget which will show the added text when you click the “Show Text” button.

Which is typically created by a TextField Cannot have an unbounded width?

An InputDecorator, which is typically created by a TextField, cannot have an unbounded width.


1 Answers

You could add SizedBox in between. The TextField tries to get the maximum size when you use the Flexible so no space is left in the middle, even if you use spaceBetween.

new Row(
  mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: <Widget>[
    new Flexible(
      child: new TextField(
          decoration: InputDecoration(
              contentPadding: EdgeInsets.all(10)
          )
      ),
    ),
    SizedBox(width: 20.0,),
    new Flexible(
      child: new TextField(
          decoration: InputDecoration(
              contentPadding: EdgeInsets.all(10)
          )
      ),
    ),
    SizedBox(width: 20.0,),
    new Flexible(
      child: new TextField(
          decoration: InputDecoration(
              contentPadding: EdgeInsets.all(10)
          )
      ),
    ),
  ],
),

You could also use Padding around the TextField.

new Row(
  mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: <Widget>[
    new Flexible(
      child: Padding(
        padding: const EdgeInsets.all(20.0),
        child: new TextField(
            decoration: InputDecoration(
                contentPadding: EdgeInsets.all(10)
            )
        ),
      ),
    ),
    new Flexible(
      child: Padding(
        padding: const EdgeInsets.all(20.0),
        child: new TextField(
            decoration: InputDecoration(
                contentPadding: EdgeInsets.all(10)
            )
        ),
      ),
    ),
    new Flexible(
      child: Padding(
        padding: const EdgeInsets.all(20.0),
        child: new TextField(
            decoration: InputDecoration(
                contentPadding: EdgeInsets.all(10)
            )
        ),
      ),
    ),
  ],
),
like image 125
chemamolins Avatar answered Sep 28 '22 07:09

chemamolins