dart – How to make the Child Widget of a Column expand to the maximum width of the parent(Column)?

Question:

Form(
    child: Column(
    children: <Widget>[
    CustomTextFormField("E-mail"),
    CustomTextFormField('Senha'),
       Expanded(
          child: FittedBox(
            fit: BoxFit.fitWidth,
            child: RaisedButton(
              onPressed: () {},
              color: Colors.redAccent,
              child: Text(
                'Entrar',
                style: TextStyle(color: Colors.white),
              ),
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(50)),
            ),
          ),
        )
      ],
    ))

This is my code, when I use Expanded the Widget just disappears. I'm following the exact example I found in the Flutter documentation

What am I doing wrong??

Answer:

Using Expanded on the Column child should be enough, however you can always try to add as a column property: crossAxisAlignment: CrossAxisAlignment.stretch to make all the children of this column occupy the full width.

The SizedBox here with BoxFit.fitWidth is not necessary to achieve this end, in fact it is ambiguous not bringing anything new.

Scroll to Top