Force remained text onto next line - flutter

I want to make textWidget1 wrap its remained text to the next line in a row.
like below :
how can I achieve this?
Using Wrap make the entire textWidget1to next line.

you may use triple quotes like in the following example:
Container(
child: Text(
'''Text1
Text2
''',
maxLines: 3,
style: TextStyle(
fontSize: 16.0, fontWeight: FontWeight.bold, color: Colors.white),
),
);
Run the above code on DartPad.
Hope I could help you.
Luis

You can wrap your Text inside a Container and the container wrapped by Flexible.

I solved my problem by drawing them.

Related

Is there a way to use overflow.ellipsis to show part of a text with dots using flutter? [duplicate]

This question already has answers here:
Flutter text ellipsis deleting last word
(3 answers)
Closed last month.
Here is my code:
Expanded(
child: Text(
"Ambattur Industrial Estate",
style: const TextStyle(
fontSize: 15,
fontWeight:
FontWeight.bold,
color: Colors.black,
// height: 1.5,
),
overflow: TextOverflow
.ellipsis,
),
),
My output is " Ambattur ... " with some space in the right.
But I need this " Ambattur Ind... " .
Is there a way to achieve this ?
It's a well known issue of flutter. You can read this discussion on https://github.com/flutter/flutter/issues/18761
The comments there have some suggested workarounds, but they are far from ideal in my opinion.
I would suggest to use TextOverflow.fade instead. It's maybe uglier but at least cuts of the word at the right spot.

Text underline display line above text instead of below

As showing the given image After applying underline decoration text style to the text it shows line above text instead of below in flutter 2.2.
TextButton(
onPressed: () {},
child: Text(
getLocalValue(context, txtTermsNConditions),
style: TextStyle(
fontSize: 12.sp,
fontWeight: fwMedium,
color: Color(clrPrimary),
decoration: TextDecoration.underline),
),
)
style: TextStyle(decoration: TextDecoration.overline) will do the trick see this link for more information.
You can do with a shortcut just use a Stack and place both Text and a Divider Widget in it and gave then position according to your Requirements that's all.
That was a problem with fonts I have used, using another font it has been resolved.

how to make the text go to the next line in flutter

I am trying to build a cv app that i can present my information. but when i write a long text it can not go to next line auto and i tried other solution but it does not work. here the code
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Flexible(
child: Text(
'longgggggggggggggggggggggggggggggggggggggg text',
overflow: TextOverflow.ellipsis,
softWrap: false,
style: TextStyle(
color: Colors.white,
fontFamily: 'NotoSans',
fontSize: 15,
),
),
),
),
here is the image
here is the image
Simply use \n inside the text.
You have to usesoftWrap: true, instead of softWrap: false, this will make the text go to the next line whenthere is no more space.
Just make sure the container where the text is, lets it go to the next line, if the height of the container is fixed it'll get the overflow error but on the vertical axis
Another simple way to do it is make a container and customize it a bit like you want for example you want border or not its up-to you. Add padding to it so the text inside the container will adjust itself automatically it wont go out of the container.

What's the best way to add space between mapped items in a column

So I have created a simple list using the map function and I want to add some space between each of the items, currently I have used a Column as a wrapper and then added Sized box to create space between each item.
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: hobbies
.map((hobby) => (Column(children: [
Text(hobby,
style: TextStyle(
color: Colors.amberAccent[200],
fontSize: 16,
fontWeight: FontWeight.w600,
)),
SizedBox(
height: 5,
)
])))
.toList(),
),
But it does not seem right to add columns inside a column and additionally the column are getting generated for nothing more than the purpose of wrapping the two items, I want to know if there is a better way to achieve the same results, Thanks.
There are many ways like using spaceBetween property, adding SizeBox, and providing Padding and margin. One of the simplest is using padding in your case. like
(hobby)=> Padding(
padding: const EdgeInsets.only(top:5.0) //or use bottom only,
child: Text(hobby,
style: TextStyle(
color: Colors.amberAccent[200],
fontSize: 16,
fontWeight: FontWeight.w600,
)),
)
You can use mainAxisAlignment of MainAxisAlignment.spaceBetween OR MainAxisAlignment.spaceAround OR MainAxisAlignment.spaceEvenly on the Column for spacing.
On another note Column inside another Column is perfectly fine.
You can also use Wrap widget which can get a direction and then act like a Column or Row. The Wrap widget has spacing property you can read more about it here: https://api.flutter.dev/flutter/widgets/Wrap-class.html
You can pick either of the 3 options. Let me know if you need anything else :)
Instead of mapping, you could use fold (Docs: https://api.dart.dev/stable/2.12.2/dart-core/Iterable/fold.html)
Example:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: hobbies
.fold([], (arr, hobby) => [
...arr,
Text(hobby,
style: TextStyle(
color: Colors.amberAccent[200],
fontSize: 16,
fontWeight: FontWeight.w600,
)),
SizedBox(
height: 5,
)
]),
),
This way you'll avoid nested columns, but still be able to use the SizedBox if that's exactly what you need.
Please consider you could wrap the text in a Padding too, instead of separating with SizedBox, and this would allow you to use map again.

Set spacing between two lines of text

I am trying to set spacing between two lines of text, but am not able to. Right now, the two lines are rendering after each other, but i want a bit of spacing between that i can adjust. I have tried using the Spacer widget but this makes the spacing too large. Is there a better way to do this?
Expanded(
child: Column(
children: <Widget>[
Text("We're finding your pizza.",
style: theme.textTheme.body1.copyWith(fontSize: 18)),
Text(
"We'll send you a notification.",
textAlign: TextAlign.center,
style: theme.textTheme.body1.copyWith(fontSize: 18)),
],
),
),
You can also set a specific padding between text lines by setting the height property in the TextStyle. With this you set the height for each line.
Text(
"Let's make\nsome pancakes",
style: TextStyle(
height: 1.2, //SETTING THIS CAN SOLVE YOUR PROBLEM
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.w300,
),
textAlign: TextAlign.center,
),
In fact, we can confirm from the docs that:
For most fonts, setting height to 1.0 is not the same as omitting or setting height to null because the fontSize sets the height of the EM-square, which is different than the font provided metrics for line height.
For more info: https://api.flutter.dev/flutter/painting/TextStyle/height.html
I posted this same answer at Flutter how do I remove unwanted padding from Text widget? to get the opposite result but it works the same way.
Spacer will take up all the available spaces left, and you may not need this. So you can simply use SizedBox widget.
Text("One"),
SizedBox(height: 20), // use this
Text("Two"),
you can simply use the SizedBox widget or Container widget with padding.
SizedBox(height: 15.0)
or
Container(
padding: const EdgeInsets.all(15.0))