5

So I tried to put a text after an icon, so i use Row. But when I input the long text it does overflow the SizedBox. so i add TextOverflow, but the Textoverflow didn't work

Here's the code :

Row(
children: [
  Icon(
    Icons.location_on,
    size: 2.h,
    color: Color(0xFFE32346),
  ),
  Padding(
      padding: EdgeInsets.only(left: 1.h),
      child: Text(
        Address,
        overflow: TextOverflow.ellipsis,
        maxLines: 1,
        style: TextStyle(
            color: Colors.black,
            fontSize: 16.sp,
            fontFamily: 'Poppins'
        ),
      )
  ),
]),
4
  • if you row is inside any container? Commented Mar 23, 2022 at 3:53
  • @Manishyadav The row is Inside a Column Commented Mar 23, 2022 at 4:03
  • what are you trying to archive for largetext? Commented Mar 23, 2022 at 4:06
  • @YeasinSheikh im trying to put icons before text, and the overflow did not work inside the row Commented Mar 23, 2022 at 4:09

4 Answers 4

14

this is the example . please use Expanded in this use case

like this way

 Row(children: [
              Icon(
                Icons.location_on,
                size: 20,
                color: Color(0xFFE32346),
              ),
              Expanded(
                  child: Text(
                 '     qqqqqqqqqqqqqq qqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq',
                overflow: TextOverflow.ellipsis,
                maxLines: 1,
                style: TextStyle(
                    color: Colors.black, fontSize: 16, fontFamily: 'Poppins'),
              )),
            ]),

the output will be

enter image description here

Sign up to request clarification or add additional context in comments.

8 Comments

why padding and screen utils are removed?
don 't remove screen utile , i am not using that plugin ,so i removed and
@nagendranag so you can still use padding but inside the Expanded
just inspect padding widget...... , you will get the answer ,and just inspect the expanded widget
@Macchiato I know we can add padding inside the Expanded ......I am just asking why that padding was removed ...to know if there are any specific reasons?
|
1

Try this,

You should wrap your code inside Container ant than in a Flexible to let your Row know that it's ok for the Container to be narrower than its intrinsic width. Expanded will also work.

or

 Row(
 children: [
          Expanded(
       Icon()
           ),
        Expanded(
          Text()
           )

            
        ]),

2 Comments

Let me know if it works
You mention wrapping the code in a Container, but the code sample doesn't show any Container. Please fix the formatting too.
0

You have to use the ConstrainedBox is a built-in widget in flutter SDK. Its function is to add size constraints to its child widgets,Wrap your text with ConstrainedBox and set widthconstraints

Please refer the following link

https://api.flutter.dev/flutter/widgets/ConstrainedBox-class.html

Comments

-1

For row case, you can wrap Padding with Expanded. Or you can use SizedBox for spacing and wrap Text with Expanded to get available space.

Row(
 children: [
  Icon(..),
  // SizedBox(width: x),// if you dont use padding
  Expanded(
    child: Padding( 
        padding: const EdgeInsets.only(..)
        child:  Text( Address,
      overflow: TextOverflow.ellipsis,
      maxLines: 1,
    ),
  ),
]),

Comments

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.