Weights to the fields in flutter

Advertisements

In Android studio we give the height or width zero and give it some weight. Is there any way we can do this in flutter ? if Yes then how ?

<EditText
            android:id="@+id/etInputOTP1"
            android:layout_width="0dp"
            android:layout_height="60dp"
            android:layout_weight="1"/>          //Like this

>Solution :

You can use the Expanded widget to give a child widget a specific weight when laying out a row or column.

To give a widget a weight of 2 in a row:

Row(
  children: [
    Expanded(
      child: Text('Widget 1'),
      flex: 2,
    ),
    Expanded(
      child: Text('Widget 2'),
      flex: 1,
    ),
  ],
)

Leave a Reply Cancel reply