0

I have a Text widget inside Column which is inside Padding. And this Padding is children of Row which is the child of another Padding.

So the structure would be: Container > Padding > Row > Padding > Column > Text.

I tried to handle text overflow, but all of the overflow do not work. I tried to put the Container inside Expanded widget, but the view totally gone instead.

Here is my code :

Container(
      decoration: constHomeBoxDecorationStyle,
      child: Padding(
        padding: const EdgeInsets.symmetric(
          vertical: 8.0,
          horizontal: 16.0,
        ),
        child: Row(
          children: [
            SvgPicture.asset(
              "assets/images/avatar.svg",
              width: 48.0,
              height: 48.0,
            ),
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    name,
                    style: TextStyle(
                      fontSize: 32.0,
                      fontWeight: FontWeight.w700,
                    ),
                  ),
                  Text(
                    name,
                    overflow: TextOverflow.clip,
                    maxLines: 1,
                    softWrap: false,
                    style: TextStyle(
                      fontSize: 24.0,
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );

In the same page, I tried to build another Text Widget to test the overflow.

The structure is like this: SingleChildScrollView > Column > Padding > Column > Text.

This one works perfectly fine (with same Text widget code from above.

Any idea why the first one does not work?

Edit: Add screenshot and output (A RenderFlex overflowed by 301 pixels on the right.) Exception :

The specific RenderFlex in question is: RenderFlex#ece9d relayoutBoundary=up18 OVERFLOWING
════════════════════════════════════════════════════════════════════════════════
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 301 pixels on the right.
The relevant error-causing widget was:
Row
lib
like a ListView.
The specific RenderFlex in question is: RenderFlex#ece9d relayoutBoundary=up18 OVERFLOWING:
  creator: Row ← Padding ← DecoratedBox ← Container ← Column ← Padding ← Column ← Padding ←
    _SingleChildViewport ← IgnorePointer-[GlobalKey#603bc] ← Semantics ← _PointerListener ← ⋯
  parentData: offset=Offset(16.0, 8.0) (can use size)
  constraints: BoxConstraints(0.0<=w<=296.7, 0.0<=h<=Infinity)
  size: Size(296.7, 72.0)
  direction: horizontal
  mainAxisAlignment: start
  mainAxisSize: max
  crossAxisAlignment: center
  textDirection: ltr
  verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════

enter image description here

Edit 2: The Answer (based on Piyush Dubey's answer)

Container(
      decoration: constHomeBoxDecorationStyle,
      padding: EdgeInsets.symmetric(vertical: 8.0),
      child: ListTile(
        leading: SvgPicture.asset(
          "assets/images/avatar.svg",
          width: 48.0,
          height: 48.0,
        ),
        title: Text(
          name,
          maxLines: 1,
          style: TextStyle(
            fontSize: 28.0,
            fontWeight: FontWeight.w700,
          ),
        ),
        subtitle: Text(
          password,
          style: TextStyle(
            fontSize: 20.0,
          ),
        ),
      ),
    )
5
  • Actually Text widget wrap themselves as the biggest parent, In the first case the Row widget has the max width/ Flutter assume that row has max width but row has limitation of context which makes it to overflow Commented Dec 5, 2020 at 17:04
  • So do you have any workaround with that? Expanded and Flexible do not work too Commented Dec 5, 2020 at 17:11
  • Can you post your end output in that case we can help with the accurate widget tree Commented Dec 5, 2020 at 17:13
  • done sir, output and the screenshot added Commented Dec 5, 2020 at 17:26
  • use ListTile Widget instead. It will be much efficient and easy for you to achieve Commented Dec 5, 2020 at 17:29

2 Answers 2

1

You can use ListTile widget to achieve that,

         ListTile(
            leading: Icon(Icons.add),
            title: Text('GFG title',textScaleFactor: 1.5,),
            trailing: Icon(Icons.done),
            subtitle: Text('This is subtitle'),
            selected: true,
            onTap: () {
              setState(() {
                txt='List Tile pressed';
              });
            },
          ),
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the help sir, i tried this code (of course change it a bit) and it works
Great. Keep going👍
1

You have to use Expanded widget as the parent of the Padding widget in the Row widget as shown below:

Container(
  decoration: constHomeBoxDecorationStyle,
    padding: const EdgeInsets.symmetric( // <----- REMOVED PADDING WIDGET AS CONTAINER ALREADY HAS PADDING PROPERTY
      vertical: 8.0,
      horizontal: 16.0,
    ),
    child: Row(
      children: [
        SvgPicture.asset(
          "assets/images/avatar.svg",
          width: 48.0,
          height: 48.0,
        ),
        Expanded(child: Padding( // <---------- HERE
          padding: const EdgeInsets.symmetric(horizontal: 16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                name,
                style: TextStyle(
                  fontSize: 32.0,
                  fontWeight: FontWeight.w700,
                ),
              ),
              Text(
                name,
                overflow: TextOverflow.clip,
                maxLines: 1,
                softWrap: false,
                style: TextStyle(
                  fontSize: 24.0,
                ),
              ),
            ],
          ),
        ),),
      ],
    ),
);

Also, there is no need to create Padding widget as the child of your Container widget as Container already has padding property.

2 Comments

i havent tried it yet but thank you for helping
No problem. Just try it & let me know if you are stuck. I will help you.

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.