I need to show ... if text-overflow and on click need to show the full text. So I use PopupMenuButton It's all working fine but the issue is it's showing just 3 alphabets and showing ... then I know width is short but before I use this text it's showing almost 10 words I think there is some padding or something I have enough width to show more text but it's not showing
Container(
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Container(
width: Width *
0.225,
child:
Align(
alignment:
Alignment.topLeft,
child: PopupMenuButton<
String>(
icon:
Container(
child: Text(datashowThis[index]['data'][i]['serviceName'] != null ? datashowThis[index]['data'][i]['serviceName'] : '',
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
maxLines: 1,
softWrap: false,
style: TextStyle(color: textGreyColor, fontSize: 12, fontFamily: 'SegoeUI-SemiBold')),
),
onSelected:
(choice) {},
itemBuilder:
(BuildContext context) {
return [
'${datashowThis[index]['data'][i]['serviceName']}'
].map((String
choice) {
return PopupMenuItem<String>(
value: choice,
child: Container(width: 100, child: Text(choice, style: TextStyle(color: kPrimaryColor, fontFamily: 'SegoeUI'))),
);
}).toList();
},
),
),
),
Container(
width: Width *
0.16,
child:
Center(
child: Text(
datashowThis[index]['data'][i]['hourBooked_Productivity']
.toString(),
textAlign: TextAlign
.center,
style: TextStyle(
color: textGreyColor,
fontSize: 12,
fontFamily: 'SegoeUI-SemiBold')),
),
),
Container(
width: Width *
0.16,
child:
Center(
child: Text(
datashowThis[index]['data'][i]['hourScheduled_Productivity']
.toString(),
textAlign: TextAlign
.center,
style: TextStyle(
color: textGreyColor,
fontSize: 12,
fontFamily: 'SegoeUI-SemiBold')),
),
),
Container(
width:
Width *
0.2,
child:
Center(
child: Text(
datashowThis[index]['data'][i]['appointmentsBooked_Productivity']
.toString(),
textAlign: TextAlign
.center,
style: TextStyle(
color: textGreyColor,
fontSize: 12,
fontFamily: 'SegoeUI-SemiBold')),
),
),
Container(
width: Width *
0.15,
child:
Center(
child: Text(
datashowThis[index]['data'][i]['bookedPercentange_Productivity']
.toString(),
textAlign: TextAlign
.center,
style: TextStyle(
color: textGreyColor,
fontSize: 12,
fontFamily: 'SegoeUI-SemiBold')),
),
),
],
),
);
You can see issue on image
The issue is you are putting other widget where icon widget is expected. So it's default icon width is taken.
Solution:
Use child instead of 'icon' in PopUpMenuButton widget.
Here is example:
Container(
width: ProjectResource.screenWidth * 0.4,
color: AppColors.blueColor,
child: Align(
alignment: Alignment.topLeft,
child: PopupMenuButton<String>(
child: Container(
color: AppColors.greenColor,
child: Text('Data here sa as a a a as asas a',
textAlign: TextAlign.left,
style: TextStyle(
color: AppColors.whiteColor,
fontSize: 12,
)),
),
onSelected: (choice) {},
itemBuilder: (BuildContext context) {
return ['Data here'].map((String choice) {
return PopupMenuItem<String>(
value: choice,
child: Container(
width: ProjectResource.screenWidth * 0.225,
child: Text(choice,
style: TextStyle(color: AppColors.greenColor))),
);
}).toList();
},
),
),
)
So you can use any width and height of PopUpMenuButton child.
Thanks.
I am working on flutter layouts and i am trying to get the last container to be placed exactly like bottom navigation bar, in my body used columns to set widgets and in second last widget is list view. i want list view to fill the bottom screen until last container which is acting as bottom bar.
But my last container has a lot of space at the bottom how to fix that.
class _MyPersondataState extends State<Persondata> {
double height;
double width;
final Color lightbluecolor = Color(0xFF3AB5FF);
List<int> getListItems(){
List<int> numberlist = List(10);
numberlist[0] = 5700;
numberlist[1] = 1200;
numberlist[2] = 970;
numberlist[3] = 1840;
numberlist[4] = 2520;
numberlist[5] = 5700;
numberlist[6] = 6200;
numberlist[7] = 4970;
numberlist[8] = 6840;
numberlist[9] = 7520;
var items = numberlist;
return items;
}
Widget getListView(){
var listitems = getListItems();
var listView = ListView.builder(
itemCount: listitems.length,
itemBuilder: (context, index){
return ListTile(
title: Text('Gross Salary'),
trailing: Text(listitems[index].toString()),
);
}
);
return listView;
}
#override
Widget build(BuildContext context) {
width = MediaQuery.of(context).size.width;
height = MediaQuery.of(context).size.height;
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(''),
),
body: Container(
margin: EdgeInsets.only(left:15.0,right: 15.0),
color: Colors.white,
width: width,
alignment: Alignment.bottomCenter,
child: Column(
children: <Widget>[
Text(
'What a loss carryforward is',
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 16.0,
fontFamily: 'Roboto',
fontWeight: FontWeight.w700,
color: Colors.black,
),
),
SizedBox(height: 8),
Flexible(
child: new Text(
'If your costs exceeded your salary, then you will have loss for this tax year.'
' You can carry this loss.'
' This will reduce next year’s tax\n\n. '
'*How do i do that?*\n\n'
' In order to make use of this, you must send a tax return to office.'
' You do not have to worry.'
' You will then receive acknowledgement from the office.\n\n'
,
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
height: 1.2,
fontSize: 14.0,
fontFamily: 'Roboto',
fontWeight: FontWeight.w400,
),
),
),
SizedBox(height: 20),
Align(
alignment: Alignment.centerLeft,
child: Text(
'Your Taxes in detail',
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 16.0,
fontFamily: 'Roboto',
fontWeight: FontWeight.w700,
color: Colors.black,
),
),
),
SizedBox(height: 20),
Align(
alignment: Alignment.centerLeft,
child: Text(
'Your income',
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 15.0,
fontFamily: 'Roboto',
fontWeight: FontWeight.w700,
color: Colors.black,
),
),
),
SizedBox(height: 6,),
Expanded(
child: getListView(),),
Align(
alignment: FractionalOffset.bottomCenter,
child: Container(
color:Colors.amber,
margin: EdgeInsets.only(left:2.0,right: 2.0,bottom: 1.0, top: 24.0),
child: new Row(
children: <Widget>[
Column(
children: <Widget>[
Text(
"REFUND :",
textDirection: TextDirection.ltr,
textAlign: TextAlign.left,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 15.0,
fontFamily: 'Roboto',
fontWeight: FontWeight.w700,
color: Colors.black,
),
),
Text(
"0,00"+"$",
textDirection: TextDirection.ltr,
textAlign: TextAlign.left,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 20.0,
fontFamily: 'Roboto',
fontWeight: FontWeight.w700,
color: Colors.black,
),
),
],
),
Spacer(),
MaterialButton(
shape: RoundedRectangleBorder(borderRadius:BorderRadius.circular(12.0) ),
height: 50,
onPressed: (){
// Navigator.push(context, MaterialPageRoute(builder: (context)=>Persondata()));
print("cilcked");
},
child: Text(
"Submit",
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 15.0,
fontFamily: 'Roboto',
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
color: lightbluecolor ,
),
],
),
),
),
],
),
),
// This trailing comma makes auto-formatting nicer for build methods.
);
}
}
this is pic where is shpwing white space.
Give the last Container desired height and finally wrap your listView in Expanded.
Expanded(
child: ListView(
children: <Widget>[]
),
),
child: Containter(
height: x,
), //last one
),
Give the listview desired height by wrapping it inside a container and finally wrap your last container in Expanded. Here's an example!
Container(
height: x,
child: ListView(
children: <Widget>[]
),
),
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: Containter(), //last one
),
),
I'm trying to create a line in which center text has a maximum size, and if the text content is too large, it fits in size.
I insert the TextOverflow.ellipsis property to shorten the text and inserting the triple points ... but it is not working.
main.dart
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new MaterialApp(
home: new HomePage(),
);
}
}
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) => new Scaffold(
appBar: new AppBar(
backgroundColor: new Color(0xFF26C6DA),
),
body: new ListView (
children: <Widget>[
new Card(
child: new Container(
padding: new EdgeInsets.symmetric(horizontal: 16.0, vertical: 18.0),
child: new Row(
children: <Widget>[
new Container(
padding: new EdgeInsets.only(right: 24.0),
child: new CircleAvatar(
backgroundColor: new Color(0xFFF5F5F5),
radius: 16.0,
)
),
new Container(
padding: new EdgeInsets.only(right: 13.0),
child: new Text(
'Text lar...',
overflow: TextOverflow.ellipsis,
style: new TextStyle(
fontSize: 13.0,
fontFamily: 'Roboto',
color: new Color(0xFF212121),
fontWeight: FontWeight.bold,
),
),
),
new Container(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
new Row(
children: <Widget>[
new Text(
'Bill ',
style: new TextStyle(
fontSize: 12.0,
fontFamily: 'Roboto',
color: new Color(0xFF9E9E9E)
),
),
new Text(
'\$ -999.999.999,95',
style: new TextStyle(
fontSize: 14.0,
fontFamily: 'Roboto',
color: new Color(0xFF212121)
),
),
],
),
new Row(
children: <Widget>[
new Text(
'Limit ',
style: new TextStyle(
fontSize: 12.0,
fontFamily: 'Roboto',
color: new Color(0xFF9E9E9E)
),
),
new Text(
'R\$ 900.000.000,95',
style: new TextStyle(
fontSize: 14.0,
fontFamily: 'Roboto',
color: new Color(0xFF9E9E9E)
),
),
],
),
]
)
)
],
),
)
),
]
)
);
}
result:
expected:
You should wrap your Container 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.
Flexible(
child: new Container(
padding: new EdgeInsets.only(right: 13.0),
child: new Text(
'Text largeeeeeeeeeeeeeeeeeeeeeee',
overflow: TextOverflow.ellipsis,
style: new TextStyle(
fontSize: 13.0,
fontFamily: 'Roboto',
color: new Color(0xFF212121),
fontWeight: FontWeight.bold,
),
),
),
),
Using Ellipsis
Text(
"This is a long text",
overflow: TextOverflow.ellipsis,
),
Using Fade
Text(
"This is a long text",
overflow: TextOverflow.fade,
maxLines: 1,
softWrap: false,
),
Using Clip
Text(
"This is a long text",
overflow: TextOverflow.clip,
maxLines: 1,
softWrap: false,
),
Note:
If you are using Text inside a Row, you can put above Text inside Expanded like:
Expanded(
child: AboveText(),
)
First, wrap your Row or Column in Expanded widget
Then
Text(
'your long text here',
overflow: TextOverflow.fade,
maxLines: 1,
softWrap: false,
style: Theme.of(context).textTheme.body1,
)
1. clip
Clip the overflowing text to fit its container.
SizedBox(
width: 120.0,
child: Text(
"Enter Long Text",
maxLines: 1,
overflow: TextOverflow.clip,
softWrap: false,
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 20.0),
),
),
Output:
2.fade
Fade the overflowing text to transparent.
SizedBox(
width: 120.0,
child: Text(
"Enter Long Text",
maxLines: 1,
overflow: TextOverflow.fade,
softWrap: false,
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 20.0),
),
),
Output:
3.ellipsis
Use an ellipsis to indicate that the text has overflowed.
SizedBox(
width: 120.0,
child: Text(
"Enter Long Text",
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: false,
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 20.0),
),
),
Output:
4.visible
Render overflowing text outside of its container.
SizedBox(
width: 120.0,
child: Text(
"Enter Long Text",
maxLines: 1,
overflow: TextOverflow.visible,
softWrap: false,
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 20.0),
),
),
Output:
Please Blog: https://medium.com/flutterworld/flutter-text-wrapping-ellipsis-4fa70b19d316
You can use this code snipped to show text with ellipsis
Text(
"Introduction to Very very very long text",
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: false,
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
),
You can do it like that
Expanded(
child: Text(
'Text',
overflow: TextOverflow.ellipsis,
maxLines: 1
)
)
One way to fix an overflow of a Text Widget within a row if for example a chat message can be one really long line. You can create a Container and a BoxConstraint with a maxWidth in it.
Container(
constraints: BoxConstraints(maxWidth: 200),
child: Text(
(chatName == null) ? " ": chatName,
style: TextStyle(
fontWeight: FontWeight.w400,
color: Colors.black87,
fontSize: 17.0),
)
),
You can do that by First wrapping your Column inside Flexible or Expanded and then use Text as usual and it will get wrapped up automatically.
Container(
child: Row(
children: [
Flexible(
child: Column(
children: [
Text("This text is so long and long and long and long and long and that's why it is not wrapping to next line.")
]
),
)
],
),
),
SizedBox(
width: 200.0,
child: Text('PRODUCERS CAVITY FIGHTER 50X140g',
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.body2))
Just wrap in inside a widget that can take a specific width for it to work or it will assume the width of the parent container.
I went through such a problem several times using rows within columns. Here's a good way to fix it:
return Column(
children: [
Row(
children: const [
Icon(Icons.close, color: Colors.red), // an example icon
// use the flexible widget above the padding
Flexible(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
child: Text(
"Exemple of text",
overflow: TextOverflow.ellipsis, // I used ellipsis, but it works with others (fade, clip, etc.)
maxLines: 1,
),
),
),
],
)
],
);
Notice that I put the Flexible above the padding, because when the text grew, the padding also broke the screen. It would be useless to put it only in Text. Hope this helps.
Wrapping whose child elements are in a row or column, please wrap your column or row is new Flexible();
https://github.com/flutter/flutter/issues/4128
Depending on your situation, I think this is the best approach below.
final maxWidth = MediaQuery.of(context).size.width * 0.4;
Container(
textAlign: TextAlign.center,
child: Text('This is long text',
constraints: BoxConstraints(maxWidth: maxWidth),
),
Use an ellipsis to indicate that the text has overflowed.
SizedBox(
width: 120.0,
child: Text(
"Enter Long Text",
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: false,
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 20.0),
),
),
If you simply place text as a child(ren) of a column, this is the easiest way to have text automatically wrap. Assuming you don't have anything more complicated going on. In those cases, I would think you would create your container sized as you see fit and put another column inside and then your text. This seems to work nicely. Containers want to shrink to the size of its contents, and this seems to naturally conflict with wrapping, which requires more effort.
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('This long text will wrap very nicely if there isn\'t room beyond the column\'s total width and if you have enough vertical space available to wrap into.',
style: TextStyle(fontSize: 16, color: primaryColor),
textAlign: TextAlign.center,),
],
),
SizedBox(
width: width-100,
child: Text(
"YOUR LONG TEXT HERE...",
maxLines: 3,
overflow: TextOverflow.clip,
softWrap: true,
style: TextStyle(
fontWeight:FontWeight.bold,
),
),
),
Wrap the Container with Expanded()
Expanded (child: Container(
padding: new EdgeInsets.only(right: 24.0),
child: new CircleAvatar(
backgroundColor: new Color(0xFFF5F5F5),
radius: 16.0,
)
),
new Container(
padding: new EdgeInsets.only(right: 13.0),
child: new Text(
'Text lar...',
overflow: TextOverflow.ellipsis,
style: new TextStyle(
fontSize: 13.0,
fontFamily: 'Roboto',
color: new Color(0xFF212121),
fontWeight: FontWeight.bold,
),
),
),
In Column We make text ellipsis by wraping column with flexibale widget,
Container(
height: SizeConfig.blockSizeVertical * 20,
width: SizeConfig.blockSizeHorizontal * 88,
child: Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
PicClipper(
height: 50,
width: 50,
circularRadius: 30,
circularImage: imageUrl[index]),
SizedBox(
width: SizeConfig.blockSizeHorizontal * 3,
),
const Text(
fontSize: 12,
fontWeight: FontWeight.normal,
text:
'Lorem ipsum dolor sit amet,consectetur adipiscing elit.Lorem ipsum dolor sit amet,consectetur adipiscing elit.',
fontStyle: FontStyle.normal,
textColor: AppColors.blackTextColor,
overflow: TextOverflow.ellipsis,
fontFamily: "Poppins",
maxLine: 3,
textAlign: TextAlign.start,
),
],
),
),
),
If you are facing the problem inside a Row a widget, try to wrap the Text widget with Expanded
Row(
children: [
Text('first'),
Expanded(
child: Text('a really long message...'),
)
]
)
I think the parent Container needs to be given a maxWidth of the proper size. It looks like the Text box will fill whatever space it is given above.
Text inside Row
1. Preference of text in Column 1 > Column 2
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"This is very very long text in column 1 of Row",
style: TextStyle(
overflow: TextOverflow.ellipsis, backgroundColor: Colors.green),
),
Flexible(
child: Text("This is very very long text in column 2 of Row",
style: TextStyle(
overflow: TextOverflow.ellipsis,
backgroundColor: Colors.yellow)),
)
],
)
2. Preference of text in Column 2 > Column 1
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Flexible(
child: Text(
"This is very very long text in column 1 of Row",
style: TextStyle(overflow: TextOverflow.ellipsis, backgroundColor: Colors.green),
),
),
Text("This is very very long text in column 2 of Row",
style: TextStyle(overflow: TextOverflow.ellipsis, backgroundColor: Colors.yellow))
],
)
3. Same Preference
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Flexible(
child: Text(
"This is very very long text in column 1 of Row",
style: TextStyle(
overflow: TextOverflow.ellipsis, backgroundColor: Colors.green),
),
),
Flexible(
child: Text("This is very very long text in column 2 of Row",
style: TextStyle(
overflow: TextOverflow.ellipsis,
backgroundColor: Colors.yellow)),
)
],
)
Text inside Column
define the maxLine attribute.
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"This is very very very very very very very very very very very very very very very very very long text in Row 1 of Column",
maxLines: 2,
style: TextStyle(
backgroundColor: Colors.green, overflow: TextOverflow.ellipsis),
),
Text("This is very very long text in Row 2 of Column",
style: TextStyle(
overflow: TextOverflow.ellipsis,
backgroundColor: Colors.yellow))
],
)
Note: If your requirement is to show the entrie content without overflow but not messing with the constraints, remove the overflow attribute but keep the Flexible as is:
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Flexible(
child: Text(
"This is very very long text in column 1 of Row",
style: TextStyle(backgroundColor: Colors.green),
),
),
Flexible(
child: Text("This is very very long text in column 2 of Row",
style: TextStyle(
overflow: TextOverflow.ellipsis,
backgroundColor: Colors.yellow)),
)
],
)
In Row We make text ellipsis to go second line by wraping firstly Text with Container and than wrap container with flexible widget
Container(
height: SizeConfig.blockSizeVertical * 10,
width: SizeConfig.blockSizeHorizontal * 88,
child: Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
PicClipper(height: 50, width:50, circularRadius: 30, circularImage:imageUrl[index]),
SizedBox(
width:
SizeConfig.blockSizeHorizontal * 3,
),
Flexible(
child: Container(
child: const
AppText
(
fontSize: 12,
fontWeight: FontWeight.normal,
text:
'Lorem ipsum dolor sit amet,consectetur adipiscing elit.Lorem ipsum dolor sit amet,consectetur adipiscing elit.',
fontStyle: FontStyle.normal,
textColor: AppColors.blackTextColor,
textOverflow: TextOverflow.ellipsis,
fontFamily: "Poppins",
maxLine: 3,
textAlign: TextAlign.start,
),
),
),
],
),
),
There is a very simple class TextOneLine from package assorted_layout_widgets.
Just put your text in that class.
For example:
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SvgPicture.asset(
loadAsset(SVG_CALL_GREEN),
width: 23,
height: 23,
fit: BoxFit.fill,
),
SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextOneLine(
widget.firstText,
style: findTextStyle(widget.firstTextStyle),
textAlign: TextAlign.left,
),
SizedBox(height: 4),
TextOneLine(
widget.secondText,
style: findTextStyle(widget.secondTextStyle),
textAlign: TextAlign.left,
),
],
),
),
Icon(
Icons.arrow_forward_ios,
color: Styles.iOSArrowRight,
)
],
)
Try:
Expanded(
child: Container(
child: Text('OVER FLOW TEST TEXTTTT',
overflow: TextOverflow.fade)),
),
This will show OVER FLOW. If there is an overflow, it will be handled.