0

This is the expected screen and the container will collapse and expand based on the text displayed and should only occupy the space left out by placing other icons.

enter image description here

But see the flutter implemented screen. The icons are moved to the right on container expansion and shows overflowed pixel error.

enter image description here

My code

  Padding(
    padding: const EdgeInsets.symmetric(horizontal: 20),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
       IconButton(
        icon: const Icon(
          Icons.menu,
          color: Colors.black,
          size: 34,
        ),
        onPressed: () {},
      ),

      //container section
      GestureDetector(
        child: Container(
          margin: const EdgeInsets.only(left: 10, right: 10),
          decoration: BoxDecoration(
              color: Colors.red.shade100,
              borderRadius: BorderRadius.circular(40.0)),
          child: Padding(
            padding:
                const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
            child: Align(
              alignment: Alignment.centerLeft,
              child: Row(children: const <Widget>[
                Text(
                  "Content is here",
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                      color: Colors.black54,
                      fontSize: 19.0,
                      fontWeight: FontWeight.bold),
                ),
                Icon(
                  Icons.arrow_drop_down,
                  color: Colors.black,
                ),
              ]),
            ),
          ),
        ),
        onTap: () {
          //todo show bottom sheet dialog here.
        },
      ),

      const Spacer(), // I just added one line
      IconButton(
        icon: Image.asset('assets/images/ic_scan.png'),
        iconSize: 20,
        onPressed: () {},
      ),
      IconButton(
        icon: Image.asset('assets/images/ic_notification.png'),
        iconSize: 20,
        onPressed: () {},
      ),
      IconButton(
        icon: Image.asset('assets/images/ic_search.png'),
        iconSize: 20,
        onPressed: () {},
       ),
     ],
    ),
  );
1
  • are you using this on appBar? Also how you like to handle overflow, when there is not enough space on ui Commented Aug 28, 2022 at 11:18

1 Answer 1

1

Remove the spacer and add the dropdown in a flexible widget

Padding(
    padding: const EdgeInsets.symmetric(horizontal: 20),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
       IconButton(
        icon: const Icon(
          Icons.menu,
          color: Colors.black,
          size: 34,
        ),
        onPressed: () {},
      ),

  Flexible(//<-------Flexible
      child: GestureDetector(
        child: Container(
          margin: const EdgeInsets.only(left: 10, right: 10),
          decoration: BoxDecoration(
              color: Colors.red.shade100,
              borderRadius: BorderRadius.circular(40.0)),
          child: Padding(
            padding:
                const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
            child: Align(
              alignment: Alignment.centerLeft,
              child: Row(
            children: const <Widget>[
              Flexible(//<-------Flexible
                 child: Text(
                  "Content is here",
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                      color: Colors.black54,
                      fontSize: 19.0,
                      fontWeight: FontWeight.bold),
                ),
               ),
                Icon(
                  Icons.arrow_drop_down,
                  color: Colors.black,
                ),
              ]),
            ),
          ),
        ),
        onTap: () {
          //todo show bottom sheet dialog here.
        },
      ),
),
//Spacer() //<--------remove this
      IconButton(
        icon: Image.asset('assets/images/ic_scan.png'),
        iconSize: 20,
        onPressed: () {},
      ),
      IconButton(
        icon: Image.asset('assets/images/ic_notification.png'),
        iconSize: 20,
        onPressed: () {},
      ),
      IconButton(
        icon: Image.asset('assets/images/ic_search.png'),
        iconSize: 20,
        onPressed: () {},
       ),
     ],
    ),
  );
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks a lot for your answer!, I tried this and it worked. But the container always fit on the available space, not collapse when text content length is small. like :- Text( "Content", overflow: TextOverflow.ellipsis, style: TextStyle( color: Colors.black54, fontSize: 19.0, fontWeight: FontWeight.bold), ))
To the row add mainAxisSize: MainAxisSize.min
I tried, but did not work as expected
Remove the align widget too
worked!, but can't set container alignment to 'centerLeft'.It always shows in center

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.