Flutter text overflow with trailing container in Row widget - flutter

In below code I'm getting Text Overflow, but what I need is, if text is to large it should fade in before the view text.
ExpansionTile(
leading: Wrap(
spacing: DynamicSize.Azwidth(30),
children: [
Icon(
Icons.menu_rounded,
color: Color(0xFFE0E0E0),
),
SvgPicture.asset('images/fire.svg'),
],
),
title: Text(
'Foam Rolling',
style: TextStyle(
fontSize: DynamicSize.Azheight(16),
fontWeight: FontWeight.w500,
fontFamily: 'DMSans',
color: Color(0xFF193669),
),
),
children: [
Padding(
padding: EdgeInsets.only(
left: DynamicSize.Azwidth(97), right: DynamicSize.Azwidth(24)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child: Row(
children: [
SvgPicture.asset('images/bullet.svg'),
SizedBox(width: DynamicSize.Azwidth(16)),
Text(
'Foam Rolling Front Hip !!!!!!!!!!!!!!!!!!',
overflow: TextOverflow.fade,
maxLines: 1,
softWrap: false,
),
],
),
),
GestureDetector(
onTap: () {},
child: Row(
children: [
Text('View'),
Icon(
Icons.arrow_forward_ios_rounded,
size: DynamicSize.Azheight(13),
),
],
),
)
],
),
)
],
);
The Output of above code is :
Their is a container widget after exclamation in the text. I even tried wrapping the text widget that overflows with Expanded widget as well as Flexible widget. But the text as well as the bullet point before the text gets invisible.

Wrap inner row with Row and Text with Flexible widget.
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Row(
children: [
Flexible(
child: Text(
'Foam Rolling Front Hip !!!!!!!!!sdssssssssssssssss!!!!!!!!!',
overflow: TextOverflow.fade,
maxLines: 1,
softWrap: true,
),
),
],
),
),

Related

how to format widgets so they are on opposite ends but also within the alignment of the other widgets

I have been trying to find a way to keep two text widgets apart but the problem was that if I used Spacer() or mainAxisAlignment: MainAxisAlignment.spaceBetween the text goes outside the alignment of the other widgets
desired layout vs current layout
child: Scaffold(
backgroundColor: Colors.transparent,
body: Container(
child: Column(children: [
Text(
'Notes Made',
textAlign: TextAlign.left,
style: const TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
),
Accordion(
color: 0xffE69AF2,
title: receiptData.getVisitType(),
content: receiptData.getVisitDesc(),
),
Accordion(
color: 0xff9AF2AE,
title: 'Doctor\'s Notes',
content: receiptData.getDoctorNotes(),
),
Text(
'Receipt',
textAlign: TextAlign.left,
style: const TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child: Text(
'consultation fee:',
),
),
Container(
child: Text(
receiptData.getCFees().toString(),
),
),
],
),
RatingBar.builder(
initialRating: receiptData.getRating(),
ignoreGestures: true,
minRating: 1,
direction: Axis.horizontal,
allowHalfRating: true,
itemCount: 5,
itemPadding: EdgeInsets.symmetric(horizontal: 4.0),
itemBuilder: (context, _) => Icon(
Icons.star,
color: Colors.amber,
),
onRatingUpdate: (rating) {
print(receiptData.getRating());
},
),
]),
),
You could try wrapping each text widget in a container and setting the width of each container to a specific value.
Container(
width: 50.0, // container width
child: Text(
'Text 1',
),
),
Container(
width: 50.0,
child: Text(
'Text 2',
),
),
Additionally you could try wrapping both text widgets in a Row widget and set the mainAxisSize property to MainAxisSize.min. This will force the row to shrink-wrap the text widgets, allowing you to control the space between them by setting the mainAxisAlignment property to MainAxisAlignment.spaceBetween
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Text 1'),
Text('Text 2'),
],
),

Why using Expanded make my text disappear?

So I'm trying to edit some of my co-worker code to make it responsive, because it show many overflow on different screen size. The initial code is using Text wrapped with sized box with fixed size and I wanted to change it to wrapped with expanded so it will take space it needed and will not overflow, but the text disappear when I use expanded ? why is that ? how should I make my text responsive.
Here's my normal code:
Row(children: [
Row(
children: [
Icon(
Icons.groups,
color: accentColor,
),
SizedBox(width: 15),
SizedBox(
width: 190,
child: Text(
'imSolver',
style: primaryColor600Style.copyWith(
fontSize: fontSize16),
).tr(),
),
],
),
]),
Changed it into using expanded:
Row(children: [
Row(
children: [
Icon(
Icons.groups,
color: accentColor,
),
SizedBox(width: 15),
Expanded(
child: Container(
child: Text(
'imSolver',
style: primaryColor600Style.copyWith(
fontSize: fontSize16),
).tr(),
),
),
],
),
]),
The parent Row of the Expanded (wrapping the Container) must have a finite with. You can just wrap it in an Expanded like so:
Row(children: [
Expanded(
child: Row(
children: [
Icon(
Icons.groups,
color: accentColor,
),
SizedBox(width: 15),
Expanded(
child: Container(
child: Text(
'imSolver',
style: primaryColor600Style.copyWith(
fontSize: fontSize16),
).tr(),
),
),
],
),),
]),
Use Flexible instead of Expanded and do provide mainAxisSize to the Row Widget.
Row(children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.groups,
color: Colors.green,
),
SizedBox(width: 15),
Flexible(
child: Text(
'imSolver',
)
),
],
),
]),

White space in text - Flutter

When using Unicode text in flutter there seems to be a lot of whitespace in each character which makes it hard to align. In the code and picture below, I'm trying to get the 35m sit on the cross arrows with no space in between. I'm also trying to get the three stars at the start to center align vertically with the word starburst and then center align the (35m and arrows), starburst, and thee stars all to center align with each other vertically.
Scaffold(
body: SafeArea(
child: Column(
children: [
Row(
children: [
Text(
'\u{2605}' * 3,
style: TextStyle(
fontSize: 18.0,
),
),
Text(
'Starburst',
style: TextStyle(
fontSize: 28.0,
),
),
Column(
children: [
Text(
'35m',
style: TextStyle(
fontSize: 18.0,
),
),
Text(
'\u{2194}',
style: TextStyle(fontSize: 35.0),
),
],
)
],
),
],
),
),
);
Make Row crossAxisAlignment property to CrossAxisAlignment.center
Row(
crossAxisAlignment: CrossAxisAlignment.center
children: [....
And
Make Column mainAxisAlignment propert to
MainAxisAlignment.center
Column(
mainAxisAlignment: MainAxisAlignment.center
children: [...
You can use Stack instead of Column and align the Text as per your UI specifications:
Output Using Column:
Output Using Stack:
Full code:
return Scaffold(
body: SafeArea(
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'\u{2605}' * 3,
style: TextStyle(
fontSize: 18.0,
),
),
Text(
'Starburst',
style: TextStyle(
fontSize: 28.0,
),
),
// SizedBox(width: 5.0),
Container(
width: 50.0,
child: Center(
child: Stack(
children: [
Positioned(
top: 4,
child: Text(
'35m',
style: TextStyle(
fontSize: 18.0,
),
),
),
Text(
'\u{2194}',
style: TextStyle(fontSize: 40.0),
),
],
),
),
),
],
),
],
),
),
);
You might have to tweak Stack widget's children a bit, but I hope this answer gives the idea.

how to auto expand when text is too long in Row in flutter

Now I am using this code to show text in flutter, this is my code:
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 8.0),
child: Text(
item.subName,
softWrap: true,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
],
),
sometimes the text item.subName is too long, how to make it auto expand or render in new line when the text overflow? I have tried to add this but still not work:
softWrap: true,
This is the error:
Try this
new Container(
child: Row(
children: <Widget>[
Flexible(
child: new Text("sample text"))
],
));
Row(
children: <Widget>[
Expanded(
child: new Text("your text"))
],
)
Widget build(BuildContext context){
final size = MediaQuery.of(context).size;
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: size.width * 0.4, // Choose a number that works for you
child: Text(
item.subName,
softWrap: true,
overflow: TextOverflow.clip,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
],
),

having problem displaying divider in my layout

i am trying to add a horizontal divider to my current layout but for some reason the divider is not appearing.
below is my code i tried
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
flex: 1,
child: Column(children: <Widget>[
Text('Total Outstanding', textAlign: TextAlign.center,),
Padding(
padding: EdgeInsets.all(3.0),
child: Text('\$345.55',textAlign: TextAlign.center, style: TextStyle(color: Colors.green,)),
),
])),
VerticalDivider( width: 0.0, indent: 0.0, color: black),
Expanded(
flex: 1,
child: Column(children: [
Text('Total Received', textAlign: TextAlign.center,),
Padding(
padding: EdgeInsets.all(3.0),
child: Text('\$1806.50',textAlign: TextAlign.center, style: TextStyle(color: Colors.green)),
),
],
)
),Divider(color: Colors.black54),
],
);
i am expecting Divider(color: Colors.black54), in my code will draw the divider. see the picture below. the red line i drew should be where the divider should appear. can someone help me modify my code so that the horizontal divider can appear where the red line is? also there should be some padding on the start of the screen and the end of the screen. thanks in advance
Column(
children: <Widget>[
SizedBox(
height: 56,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Total Outstanding',
textAlign: TextAlign.center,
),
Padding(
padding: EdgeInsets.all(3.0),
child: Text('\$345.55',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.green,
)),
),
],
),
),
VerticalDivider(width: 1.0, color: Colors.black),
Expanded(
flex: 1,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Total Received',
textAlign: TextAlign.center,
),
Padding(
padding: EdgeInsets.all(3.0),
child: Text('\$1806.50', textAlign: TextAlign.center, style: TextStyle(color: Colors.green)),
),
],
),
),
],
),
),
SizedBox(height: 12),
Container(height: 2, color: Colors.black54),
],
),