Flutter : text with TextAlign justify is cutting off inside a word - flutter

inside the body of my current page, I just have a simple ListView containing the following text widget :
new Text(
"By signing up you confirm that you have read and agree to the :",
textAlign: TextAlign.justify,
textScaleFactor: 1.0,
style: TextStyle(
fontSize: 14.0,
fontFamily: 'Montserrat',
fontStyle: FontStyle.normal,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
softWrap: true,
),
I would like my text to wrap, but its breaking in the middle of the word "agree", you can see a screen of the result below (the text under the signup button) :
[EDIT]
I even tried to simplify my code by removing almost every non mandatory properties like following :
It render exatly the same
So please, where am I wrong ?
Thanks for your help.
Michel

Related

How to properly "override" some property from TextStyle

I have my own style:
final myStyle = GoogleFonts.roboto(
height: 1.2,
color: Colors.black54,
fontWeight: FontWeight.w300,
fontSize: 16
);
I want to use it later in two TextWidget, but with different FontWeight property, so I thought about using copyWith method like this:
Text(
"myText",
style: myStyle.copyWith(fontWeight:FontWeight.w400 ),
),
But it's not working. Text is not bolded (by FontWeight.w400)
Default value of fonts is w400 already so it will look as it is not working but it is, so I suggest you to try a different FontWeight so you can see the difference. By the way you are overriding it properly already.

How to make line through text animation in flutter

I'm developing a todo app. and in that app when a task is done, then the lineThrough field will enable.
but it is very boring cos there is no effect on it. so I want to make the line through effect as animation.
how do I do that
here is an example.
here is my code
Text.rich(
TextSpan(text: task.title),
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontFamily: 'Helvatica_lite',
decoration: task.isDone == true
? TextDecoration.lineThrough
: TextDecoration.none,
fontWeight: FontWeight.bold,
fontSize: 15,
color: task.isDone == true ? Colors.grey : Colors.black),
);
how do I make the line through animation in flutter???
You can achieve this with the line through effect. This video explains the process quite well: https://www.youtube.com/watch?v=ItlNXTVB6bw

How to diplay a hexadecimal emoji in flutter

I would like to display the emoji 🤑 while only having the hexadecimal value of it.
var line = "testing is forever 🤑";
Text(
"${line}",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Color(0xFF008080)),
),
Try below code hope its helpful to you. Refer Unicode Charecter here
Text(
'\u{1F602}',
style: TextStyle(
fontSize: 25,
),
),
Your Result screen->
Or in VS Code Pressed Window + . and open the emoji picker box choose your wanted emoji and select it
Text(
'🤑',
style: TextStyle(
fontSize: 30,
),
),
Your result screen->
I was able to fix this by using the HtmlCharacterEntities and the HtmlUnescape
HtmlUnescape().convert(HtmlCharacterEntities.decode("testing is forever 🤑"))

Formatting text in flutter

I am styling text but am not able to get what I want like -:
I want this text below
look like this -:
how do I do it can anyone help?
If you want each word on a new line
String text = "Lorem ipsum dolor sit amet";
Text(
text.replaceAll(" ", "\n"),
),
text.replaceAll(" ", "\n") will replace all space with \n(new line)
You can use \n (optn + shift + 7) to make a new line inside you're String.
Container(
child: Center(
child: Text('Hello \nWorld',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.bold,
letterSpacing: 0.7
)
),
),
),
Use textAlign to make your text align in the center (default is align left).
Its seem like by your comment you have a dynamic data. Since your question is not very clear, I will give you sample example to handle dynamic Data.
List a = ['Hello World', 'Hello', 'World'];
ListView(
children: a.map((e) {
if (e == "Hello") {
return Text(
e,
textAlign: TextAlign.end,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
);
} else if (e == "World") {
return Text(
e,
textAlign: TextAlign.end,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
);
} else {
return Text(
e,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
);
}
}).toList()),
Code Explanation
1). I have declare a Random List of String.
2). Then I used List View to handle dynamic list.
3). I put iteration and use a Text widget and put some style according to my Requirment.
you can put condition by yourself what you needed.
You can use \n to make a new line
Code:
Center(
child: Text('Hello Guys, Thanks \nfor visiting our website \nFlutter Examples.com',
style: TextStyle(fontSize: 22),
textAlign: TextAlign.center)
)

How to capitalize text in Flutter

I tried to find how capitalize text in Flutter, but I couldn't find it.
My code:
Center(
heightFactor: 2,
child: Text(
'Strengthening the bond of owners and pets, more than ever...',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
color: Colors.cyanAccent[700],
wordSpacing: 8,
),
)),
I dont know if there is a way to do it through the Text widget, but you can use string.toUppercase() to capitalize the word:
Center(
heightFactor: 2,
child: Text(
'Strengthening the bond of owners and pets, more than ever...'.toUpperCase(),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
color: Colors.cyanAccent[700],
wordSpacing: 8,
),
)),
To capitalize and to uppercase are different:
Capitalize: "Strengthing..."
Uppercase: "STRENGTHING..."
Capitalize
To capitalize a string in all locales:
import 'package:intl/intl.dart';
toBeginningOfSentenceCase('strengthening...');
To capitalize a string for en-US like locales:
String text = 'strengthening...';
text = text[0].toUpperCase() + text.substring(1).toLowerCase();
You can also have the virtual keyboard automatically switch to uppercase on the start of a sentence:
TextField(
textCapitalization: TextCapitalization.sentences
)
https://api.flutter.dev/flutter/services/TextCapitalization.html
Uppercase
To uppercase a string:
'strengthening...'.toUpperCase()
You can also have the virtual keyboard automatically switch to uppercase on each character
TextField(
textCapitalization: TextCapitalization.characters
)
https://api.flutter.dev/flutter/services/TextCapitalization.html
Better way to capitalize text
// copy this code to somewhere in your dart file
// also you can write/add methods to below code to support your strings to modify i.e. `toCapitalize()` or `yourStringModifyingMethod`.
extension StringCasingExtension on String {
String toCapitalize() => length > 0 ? ${this[0].toUpperCase()}${substring(1).toLowerCase()}' : '';
// String yourStringModifyingMethod() => write your logic here to modify the string as per your need;
}
Here is how you can use it
var word = 'this is capital'.toCapitalized(); // 'This is capital'
Well, you could use this package to capitalize the content in the Text widget:
https://pub.dev/packages/text_tools.
//This will put the letter in position 15 in UpperCase, will print 'Strengthening The bond of owners and pets, more than ever...'
Center(
heightFactor: 2,
child: Text(
TextTools.toUppercaseAnyLetter(text: 'Strengthening the bond of owners and pets, more than ever...', position: 15),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
color: Colors.cyanAccent[700],
wordSpacing: 8,
),
)),