text overflowed in flutter - flutter

Column(
crossAxisAlignment: CrossAxisAlignment.start,
children:const [
Padding(
padding: EdgeInsets.only(top: 30, bottom: 5.0),
child: Text(
"Data#data",
style: TextStyle(color: Colors.white),
),
),
Text(
"title",
style: TextStyle(fontSize: 18),
),
Text(
'datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadata',
overflow: TextOverflow.ellipsis,
),
],
),

Expanded(
child: Text(
'datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadata',
overflow: TextOverflow.ellipsis,
),)

Your column is inside a row widget and inside your column you use a long string so for telling column how much space should take you need wrap your column with Expanded widget:
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Padding(
padding: EdgeInsets.only(top: 30, bottom: 5.0),
child: Text(
"Data#data",
style: TextStyle(color: Colors.white),
),
),
Text(
"title",
style: TextStyle(fontSize: 18),
),
Text(
'datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadatadata',
overflow: TextOverflow.ellipsis,
),
],
),
),

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

you can encapsulate the text with the expanded widget and add the maxlines attribute
Expanded(child:
Text("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
maxLines:3,
overflow:TextOverflow.ellipsis ))
see the video.

Related

Flutter: Row with flexible and spacer not working

I am building a widget to look like Tweets. At the moment, the header is the following row:
Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Flexible(
flex: 3,
child: Container(
margin: const EdgeInsets.only(right: 5.0),
child: Text(
poster.name,
style: Theme.of(context)
.textTheme
.headline4!
.copyWith(fontWeight: FontWeight.bold, fontSize: 14),
),
),
),
Expanded(
flex: 14,
child: Text(
'${poster.handle} · ${timeago.format(wave.createdAt)}',
style:
Theme.of(context).textTheme.headline5!.copyWith(fontSize: 12),
overflow: TextOverflow.ellipsis,
),
),
Spacer(),
if (showPopup)
WaveTilePopup(
poster: poster, wave: wave, user: user, onDeleted: onDeleted),
],
),
Which look like this:
When i increase the flex property of the name text, it will fix the formatting on the name, however shorter names will result in the PopUp being away from the right alignment, which is where I want it to be in a consistent manner:
Any ideas?
Thanks!
Instead of all hard-coded flex, you can just wrap your more button with expanded and align widget like this:
Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Container(
margin: const EdgeInsets.only(right: 5.0),
child: Text(
poster.name,
style: Theme.of(context)
.textTheme
.headline4!
.copyWith(fontWeight: FontWeight.bold, fontSize: 14),
),
),
Text(
'${poster.handle} · ${timeago.format(wave.createdAt)}',
style: Theme.of(context)
.textTheme
.headline5!
.copyWith(fontSize: 12),
overflow: TextOverflow.ellipsis,
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: showPopup
? WaveTilePopup(
poster: poster,
wave: wave,
user: user,
onDeleted: onDeleted)
: SizedBox(),
),
),
],
),

How to hide a Row widget within a Column widget in Flutter

I have the following code which displays a Column within an Alert. The Row displays a break value in minutes. If the variable (break1, break2 etc) is 0, I don't want to display that Row. How do I do this? Thanks.
content: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
flex: 38,
child: Text(
'Break 1:',
style: TextStyle(color: kBodyText, fontSize: 16),
),
),
Expanded(
flex: 62,
child: Text(
'$break1 minutes',
style: TextStyle(color: kBodyText, fontSize: 16),
),
),
],
),
Row(
children: <Widget>[
Expanded(
flex: 38,
child: Text(
'Break 2:',
style: TextStyle(color: kBodyText, fontSize: 16),
),
),
Expanded(
flex: 62,
child: Text(
'$break2 minutes',
style: TextStyle(color: kBodyText, fontSize: 16),
),
),
],
),
],
),
Wrap your Row inside Visibility Widget and set visible to true or false as per requirement.
Visibility(
visible:
!state.getListApiCalled ? true : false,
child: Padding(
padding: EdgeInsets.all(
ResponsiveFlutter.of(context).hp(6)),
child: CircularProgressIndicator(
strokeWidth: 5,
)),
),
Use Visibility.
visible:false is used to hide specific widget.
So the code looked like this:
Visibility(visible:false, child:Row());

Is my TextOverflow.ellipsis causing my text to be moved to the right?

I'm displaying text in a ListView.Builder and if some of the text is too long I'm using the overflow: TextOverflow.ellipsis property of the Text widget to ensure it doesn't cause an overflow error. Well when text is too long, it uses the TextOverflow correctly, but it also shifts the text to the right. I want to keep the text all aligned. Could this be caused by the TextOverflow or is this a layout issue?
This is an image of one of the pieces of text that had ellipsis used on it due to it being too long. As you can see it is shifted to the right. This only occurs when an ellipsis is used though. If the Text doesn't need an ellipsis it doesn't get shifted to the right.
This is the code that renders this entire page. The bit that I's being moved to the right is where the the text displays mileage[index].trippurpose I've included the entire code incase it is a layout issue that I keep overlooking.
Container(
height: 60,
child: Row(
children: <Widget>[
Expanded(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(left: 5, top: 13),
child: Text(mileage[index].tripdate,
style: TextStyle(
fontSize: 14, color: Colors.black),
textAlign: TextAlign.left),
),
],
),),
Expanded(
flex: 3,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(top: 13, left: 10),
child: Text(mileage[index].trippurpose,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Colors.black,
fontFamily: 'Montserrat'),
overflow: TextOverflow.ellipsis,
softWrap: true,
textAlign: TextAlign.center),),
Padding(
padding: EdgeInsets.only(left: 10),
child: Row(
children: [Text(
'${mileage[index].tripfrom} - ',
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black,
fontStyle: FontStyle.italic),
),
Padding(
padding: EdgeInsets.only(),
child:Text(
mileage[index].tripto,
overflow: TextOverflow.ellipsis,
softWrap: false,
style: TextStyle(
color: Colors.black,
fontStyle: FontStyle.italic
),
),
),
],
),
),
],
),),
Expanded(
flex: 1,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding:
EdgeInsets.only(top: 13, right: 10),
child: Container(
child: Text(
mileage[index].triptotalmiles,
style: TextStyle(
fontSize: 16,
color: Colors.black),
textAlign: TextAlign.right),
),
),
],
),)
],
))
Here is a sample code, you can use to create design as per your code.
Container(
child: Row(
children: [
Flexible(
flex: 1,
child: Text(
'THIS IS A TEST TEXT',
overflow: TextOverflow.ellipsis,
),
),
Flexible(
flex: 3,
fit: FlexFit.tight,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'THIS IS A TEST TEXT',
overflow: TextOverflow.ellipsis,
),
Text(
'THIS IS A TEST TEXT',
overflow: TextOverflow.ellipsis,
),
],
),
),
Flexible(
flex: 1,
child: Text(
'THIS IS A TEST TEXT',
overflow: TextOverflow.ellipsis,
),
),
],
),
)
Note :- You are applying wrong logics to your code. flex is best fit with Flexible widget. Also check FlexFit.tight.

Text overflowing and cannot be controlled

I've got an issue where text inside a Column inside a Row overflows the other things in the Row. This is what it looks like when the description is short.
But if the description gets longer it overflows and hides the settings button:
I've tried using the overflow: TextOverflow.ellipsis, and TextOverflow.clip properties in the Text widget, this does nothing.tried to change the Column and Row to Wrap widgets
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(
userData.profilePic ?? kBackupProfilePic),
radius: 40.0,
),
SizedBox(width: 20.0),
Column(
children: <Widget>[
SizedBox(height: 20.0),
Text(
userData.name ?? "Cannot find name",
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 20.0,
),
),
SizedBox(height: 5.0),
Text(
userData.description ??
"Cannot find description",
overflow: TextOverflow.ellipsis,
maxLines: 5,
style: TextStyle(),
),
],
),
SizedBox(width: 40.0),
IconButton(
icon: Image.asset('assets/cogwheel.png'),
iconSize: 50,
onPressed: () {
openSettings();
},
),
],
),
I've tried placing the the Row in a Container with a Flexible, but that causes red screen Flutter error.
When I replace the Row and Columns with Wrap widgets I get:
child: Wrap(
direction: Axis.horizontal,
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(
userData.profilePic ?? kBackupProfilePic),
radius: 40.0,
),
SizedBox(width: 20.0),
Wrap(
direction: Axis.vertical,
children: <Widget>[
SizedBox(height: 20.0),
Text(
userData.name ?? "Cannot find name",
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 20.0,
),
),
SizedBox(height: 5.0),
Text(
//"brobbi",
userData.description ??
"Cannot find description",
overflow: TextOverflow.clip,
maxLines: 5,
style: TextStyle(),
),
],
),
SizedBox(width: 40.0),
IconButton(
icon: Image.asset('assets/cogwheel.png'),
iconSize: 50,
onPressed: () {
PopupLayout(top: topMarginPopupLayout).showPopup(
context, SettingsScreen(), 'Cibus Settings');
},
),
],
),
This cannot be too hard. I just want my text to linebreak or cut if it's so long that it'll cause overflows.
For TextOverflow to the framework should know where is the current widget's bounds are. Inside Column widget framework cant determine cross axis (horizontal) bounds.
To make ellipsis work you have to wrap that text widget inside an Expanded widget with a parent Row. or wrapping your Column inside Expanded would do fine.
Row(children:[
//Circle Avatar here
Expanded( // Wrap Expanded here
child:Column(
children: <Widget>[
SizedBox(height: 20.0),
Text(
"Cannot find name",
overflow: TextOverflow.ellipsis,
maxLines:1,
style: TextStyle(
fontSize: 20.0,
),
),
SizedBox(height: 5.0),
Text(
"Cannot find description",
overflow: TextOverflow.ellipsis,
maxLines: 5,
style: TextStyle(),
),
],
),
),
])

Wrapping text in column

I'm building an expenses app, and have:
As you can see, I have a text overflow problem. I want that text to trim with ellipses, but I'm not sure how to do it. Currently I have:
Widget buildCardLeft() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text(
this.transaction.title,
style: TextStyle(fontSize: 24),
overflow: TextOverflow.ellipsis,
),
),
SizedBox(
height: 8,
),
Text(
dateFormat.format(this.transaction.date),
style: TextStyle(color: Colors.grey),
)
],
);
What's the correct way to get this text to truncate?
you can say like:
Text(
this.transaction.title.replaceRange(25, this.transaction.title.length, "...",
style: TextStyle(fontSize: 24),
overflow: TextOverflow.ellipsis,
)
Solved with Flexible:
Widget buildCardLeft() {
return Container(
child: Flexible(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
this.transaction.title,
style: TextStyle(fontSize: 24),
overflow: TextOverflow.ellipsis,
),
SizedBox(
height: 8,
),
Text(
dateFormat.format(this.transaction.date),
style: TextStyle(color: Colors.grey),
)
],
),
),
);
}