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 to make a Row take the full width of it's parent in Flutter?

I want to create this peace of UI

enter image description here

The problem is in the Red Row that contains the Title and the Date. I want this Row to take the full width of it’ parent widget so I can add a space between these two Text widgets…and that is what I’v done so far.

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

Container(
      color: Colors.yellow,
      margin: const EdgeInsets.symmetric(vertical: 6),
      child: Container(
        color: Colors.green,
        child: Row(
          children: [
            Container(
              decoration: BoxDecoration(
                border: Border.all(width: 1, color: AppColors.tertiary),
                borderRadius: BorderRadius.circular(240),
              ),
              child: Image.asset(image, width: 48, height: 48),
            ),
            const SizedBox(width: 6),
            Container(
              color: Colors.blue,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    color: Colors.red,
                    child: Row(
                      mainAxisSize: MainAxisSize.max,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          title,
                          style: Theme.of(context).textTheme.subtitle1?.copyWith(color: Theme.of(context).colorScheme.primary),
                        ),
                        Text(
                          date,
                          style: Theme.of(context).textTheme.bodyText2?.copyWith(color: AppColors.tertiary),
                        ),
                      ],
                    ),
                  ),
                  const SizedBox(height: 3),
                  Text(
                    value.toString(),
                    style: Theme.of(context).textTheme.bodyText2?.copyWith(color: AppColors.tertiary),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );

I tried to wrap this Row with a Extended widget and and a SizedBox.expand() but it did not work.

>Solution :

You need wrap your Container that contain Column with Expanded widget:

Row(
    children: [
      Container(
        decoration: BoxDecoration(
          border: Border.all(width: 1, color: Colors.black),
          borderRadius: BorderRadius.circular(240),
        ),
        child: Image.asset(image, width: 48, height: 48),
      ),
      const SizedBox(width: 6),
      Expanded( //<---- add this
        child: Container(
          color: Colors.blue,
          child: Column(
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