I have a listTile title with a long text .
I whoud like the title to show as must text as possible , in one single line ...
If I use softWrap: true, overflow: TextOverflow.ellipsis, the text is cut after 4 caracter´s
like : exampl....
if I don´t use softWrap: true, overflow: TextOverflow.ellipsis, the text is shown in 3 or 4 lines
I tryied using FittedBox , but the text get´s really small .. unreadable ....
Any ideias how to get this ?
title: Text(
inc.descricao,
style: TextStyle(
color: Colors.white,
fontFamily: "Roboto",
fontSize: 16,
),
softWrap: true,
overflow: TextOverflow.ellipsis,
),
thank You Roque
Use layout Flexible/Container with text overflow:
Flexible(
child: Container(
child: Text(
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 13.0,),
),
),
),
Actually, overflow: TextOverflow.ellipsis should work.
My guess is Text widget container making the Text widget shorter
Try wrapping Text widget in Container with maximum width
Container(
width: double.infinity,
child: Text(
'reaaaaaly long text, like reaaaaaaaaaaaaaly long',
overflow: TextOverflow.ellipsis,
),
You can use text property Overflow.elipsis.
ListTile(
shape: RoundedRectangleBorder(
minLeadingWidth: 0,
title: Text(
"Hello Overflow",
style: const TextStyle(
fontFamily: 'Open Sans',
fontSize: 15,
color: Color(0xff23233c),
letterSpacing: -0.44999999999999996,
fontWeight: FontWeight.w500,
),
softWrap: true,
overflow: TextOverflow.ellipsis,
),
)
Related
I have the following code:
AutoSizeText.rich(
TextSpan(children: [
const TextSpan(
text: "\$",
style: TextStyle(
color: Colors.white,
fontSize: 45,
height: 1.0,
letterSpacing: .0,
fontWeight: FontWeight.w600,
),
),
TextSpan(
text: widget.budget.truncate().toString(),
style: const TextStyle(
color: Colors.white,
fontSize: 90,
),
),
TextSpan(
text: ".${widget.budget.toStringAsFixed(2).split(".")[1]}",
style: const TextStyle(
color: Colors.white,
fontSize: 45,
),
),
]),
style: GoogleFonts.manrope(
fontSize: 45,
letterSpacing: -4.5,
height: 1.0,
fontWeight: FontWeight.w600,
textStyle: const TextStyle(
leadingDistribution: TextLeadingDistribution.even,
)),
textAlign: TextAlign.center,
maxLines: 1,
);
The code results in this (I also tried with Text.rich instead of AutoSizeText but the result is the same):
In the image, I have wrapped the text in a red container to check its bounding box.
I am implementing this element following a design I made in Figma:
Similatly, in this image the red frame has an autolayout applied with all padding set to 0, in a way that simulates wrapping the text in a Container.
The text looks the same in both the design and the Flutter implementation, but the Flutter one is shifted upwards, which on big text sizes is really noticeable. I figured it might have something to do with the vertical alignment of the text but I could not find any way to fix it.
Is this an expected behaviour or am I doing something wrong?
How to control TextOverFlow if don't know the const width of the box.
I know about
Text(
'some Text',
overflow: TextOverflow.ellipsis,
)
but is there any way to wrap widgets like expanded or flexible?
FittedBox(
fit: setToWidth ? BoxFit.contain : BoxFit.none,
child: Text(
displayText,
maxLines: 2,
textAlign: textAlign,
style: setToWidth
? TextStyle(
fontWeight: fontWeight,
color: textColor,
fontFamily: AppFonts.circularStd,
)
: TextStyle(
fontWeight: fontWeight,
color: textColor,
fontFamily: AppFonts.circularStd,
fontSize: textSize),
),
);
Try with this
You can try AutoSizeText instead.
https://pub.dev/packages/auto_size_text
Note: it'll increase your overall app size as it requires external dependencies. But it'll give you some extra features such as maxLines and minLines. I will suggest read more about it.
Container(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 60),
child: Text(
// subCategoryName,
"This is a very Long Text takes more space",
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
.headline3
.copyWith(color: Colors.white, fontSize: 32),
),
),
),
Look this Picture
I need this line to be a maximum of two lines and shrink the size like a FittedBox (with BoxFit.fitWidth) if the text gets even longer
When I used the FittedBox it looking like this. But I need to take it up to 2 lines if needed.. Any solution is appreciated
Got it working by the reply of Sam Chan.
I used the AutoSizeText Package
If you don't want to add an pakage, here is workaround. You can check the length of the text and based on that you can handle it.
// declare a widget
Widget titleTextWidget = Text(
title,
style: TextStyle(
fontWeight: FontWeight.w600,
),
maxLines: 2,
textAlign: TextAlign.center,
);
// use condition to render it.
title.length > 45
? FittedBox(
child: titleTextWidget,
)
: titleTextWidget,
I have this UI :UI
And the text is showing this yellow bar, even when I set the maxlines to 3..
I put them in a container and its still like this!
child: Container(
height: 150,
width: 200,
child: Column(children: [
Text(
allRecipes[index].name,
style: TextStyle(color: Colors.black54,
fontSize: 20,),
),
Text(
allRecipes[index].about,
softWrap: true,
maxLines: 3,
style: TextStyle(
fontSize: 14,)
),
Also, I need help from you so I can make more space between the food cards??
Its because your Container Height.
try to increase this and check,
your Container height is 150
increase this 200 or 250. as per your design requirement.
Container(
height: 250,//like this
width: 200,
child: Column(children: [
Text(
allRecipes[index].name,
style: TextStyle(color: Colors.black54,
fontSize: 20,),
),
Text(
allRecipes[index].about,
softWrap: true,
maxLines: 3,
style: TextStyle(
fontSize: 14,)
),
]
)
Sometimes, the text widget does a line break, and sometimes don't. I tried to add overflow and maxline but it doesn't work.
This is the code:
Text(
ArticleData().articleBank[index].articleTitle,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.black,
),
),
This is what, I will try to build:
You can use FittedBox class.
Scales and positions its child within itself according to fit. The fit and alignment arguments must not be null.
FittedBox(
Key key,
fit: BoxFit.none,
alignment: Alignment.center,
child: Text(
ArticleData().articleBank[index].articleTitle,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.black,
),
),
)