1

What's the best way to make this row responsive? One of the problems, I running into is if the team name have a lot of characters then there is an overflow pixel error. See screenshot

Screenshot overflow

Also see code below

child: Row(
                //mainAxisSize: MainAxisSize.max,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const SizedBox(
                    child: Padding(
                      padding: EdgeInsets.all(10.0),
                      child: Text(
                        'Bosnia and Herzegovina',
                        style: TextStyle(
                          fontFamily: 'Poppins',
                        ),
                      ),
                    ),
                  ),
                  SizedBox(
                    child: Image.network(
                      'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Flag_of_Bosnia_and_Herzegovina.svg/1920px-Flag_of_Bosnia_and_Herzegovina.svg.png',
                      height: 50,
                      fit: BoxFit.cover,
                    ),
                  ),
                  Card(
                    child: Container(
                      width: 70,
                      color: Colors.amber,
                      child: const Padding(
                          padding: EdgeInsets.all(10.0),
                          child: Text(
                            "4:0",
                            textAlign: TextAlign.center,
                          )),
                    ),
                  ),
                  SizedBox(
                    child: Image.network(
                      'https://upload.wikimedia.org/wikipedia/commons/thumb/c/cb/Flag_of_the_Czech_Republic.svg/1920px-Flag_of_the_Czech_Republic.svg.png',
                      height: 50,
                      fit: BoxFit.cover,
                    ),
                  ),
                  const SizedBox(
                    child: Padding(
                      padding: EdgeInsets.all(10.0),
                      child: Text(
                        'Czech Republic',
                        style: TextStyle(
                          fontFamily: 'Poppins',
                        ),
                      ),
                    ),
                  )
                ],
              ),

1 Answer 1

1

use the Expanded Widget as children of the row, so they only take the available space:

Row(
      //mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        const Expanded(
          child: SizedBox(
            child: Padding(
              padding: EdgeInsets.all(10.0),
              child: Text(
                'Bosnia and Herzegovina',
                style: TextStyle(
                  fontFamily: 'Poppins',
                ),
              ),
            ),
          ),
        ),
        Expanded(
          child: SizedBox(
            child: Image.network(
              'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Flag_of_Bosnia_and_Herzegovina.svg/1920px-Flag_of_Bosnia_and_Herzegovina.svg.png',
              height: 50,
              fit: BoxFit.cover,
            ),
          ),
        ),
        Expanded(
          child: Card(
            child: Container(
              width: 70,
              color: Colors.amber,
              child: const Padding(
                  padding: EdgeInsets.all(10.0),
                  child: Text(
                    "4:0",
                    textAlign: TextAlign.center,
                  )),
            ),
          ),
        ),
        Expanded(
          child: SizedBox(
            child: Image.network(
              'https://upload.wikimedia.org/wikipedia/commons/thumb/c/cb/Flag_of_the_Czech_Republic.svg/1920px-Flag_of_the_Czech_Republic.svg.png',
              height: 50,
              fit: BoxFit.cover,
            ),
          ),
        ),
        const Expanded(
          child: SizedBox(
            child: Padding(
              padding: EdgeInsets.all(10.0),
              child: Text(
                'Czech Republic',
                style: TextStyle(
                  fontFamily: 'Poppins',
                ),
              ),
            ),
          ),
        )
      ],
    ),

the result :

enter image description here

you can add a row inside a column and set the flex of the Expanded Widgets:

Column(

      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Row(

        children: [
          Expanded(
            flex: 2,
            child: SizedBox(
              child: Image.network(
                'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Flag_of_Bosnia_and_Herzegovina.svg/1920px-Flag_of_Bosnia_and_Herzegovina.svg.png',
                height: 50,
              ),
            ),
          ),
          Expanded(
            flex: 1,
            child: Card(
              child: Container(
                width: 70,
                color: Colors.amber,
                child: const Padding(
                    padding: EdgeInsets.all(10.0),
                    child: Text(
                      "4:0",
                      textAlign: TextAlign.center,
                    )),
              ),
            ),
          ),
          Expanded(
            flex: 2,
            child: SizedBox(
              child: Image.network(
                'https://upload.wikimedia.org/wikipedia/commons/thumb/c/cb/Flag_of_the_Czech_Republic.svg/1920px-Flag_of_the_Czech_Republic.svg.png',
                height: 50,
              ),
            ),
          ),

        ],
      ),
        Row(
          children: [
            const Expanded(
              flex: 2,
              child: SizedBox(
                child: Padding(
                  padding: EdgeInsets.all(10.0),
                  child: Text(
                    'Bosnia and Herzegovina',
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      fontFamily: 'Poppins',
                    ),
                  ),
                ),
              ),
            ),
            Expanded(
              flex: 1,
                child: Container()
            ),
            const Expanded(
              flex: 2,
              child: SizedBox(
                child: Padding(
                  padding: EdgeInsets.all(10.0),
                  child: Text(
                    'Czech Republic',
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      fontFamily: 'Poppins',
                    ),
                  ),
                ),
              ),
            )
          ],
        )
    ]
    ),

the result:

enter image description here enter image description here

1
  • Thanks for the details definitely help, and add me to right direction.
    – neuryzonso
    Sep 19, 2021 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.