How to make line through text animation in flutter - 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

Related

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 🤑"))

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

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

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,
),
)),

Update flutter font with a function

I want to update the displaying font in flutter using a function.I've tried with following method but it won't update.I can't find the problem.
Function
_fontselect(String ){
if (_character==1) {
return "Font";
} else{
return "Font2";
}
}
context
Center(child: Text(text,
textAlign: TextAlign.center,
style: TextStyle(
fontFamily:_fontselect(String),
fontWeight: FontWeight.bold,
fontSize: 28.0,
color: Colors.red)
),
),
Use Ternary Operator within the fontFamily itself.
Center(child: Text(text,
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: _character==1 ? "Font" : "Font2",
fontWeight: FontWeight.bold,
fontSize: 28.0,
color: Colors.red)
),
),
Your function needs a String variable to use inside of the function.
_fontselect(String character){
if (character==1) {
return "Font";
} else{
return "Font2";
}
}
Also it looks like character is an int but you are sending a String over to the function you should call the function with an int if this makes more sense.

Dart - How to a change the color of my raisedButton after clicking in dart?

so i've been struggling to change the color of my button from green to red for my flutter app. Most of the online resources are confusing me. This is my following code.
new RaisedButton(key:null, onPressed:buttonPressed,
color: Colors.green,
child:
new Text(
"10:00 A.M. - 11:00 A.M.",
style: new TextStyle(fontSize:15.0,
color: const Color(0xFF000000),
fontWeight: FontWeight.w200,
fontFamily: "Roboto"),
)
),void buttonPressed(){
}
I want to click it and it turn green, or even better. Click it, so it turns gray. Then click another button that states "confirm", and it would make all the grey buttons that have been clicked red. Regardless, I'm just trying to understand how to make the button change color after being clicked.
Basically, what you need to do is,
Make RaisedButton color a class-level variable instead of constant as you have now.
Initialize that variable to some color value in initState method.
In the onPressed handler of RaisedButton, do the following:
Change that variable to some color value of your liking.
Trigger Repaint (so that the new color gets painted) i.e. call setState method.
Last but not least, you'll need to have all the code above part of a stateful widget.
Hopefully, it's clear enough, let us know if you'd need some code sample as well.
bool turnToRed = false;
bool colorIsGreen = true;
RaisedButton(key:null, onPressed: (){
setState((){
colorIsGreen = !colorIsGreen;
});
},
color: colorIsGreen ? Colors.green :turnToRed ? Colors.red : Colors.grey,
child:
new Text(
"10:00 A.M. - 11:00 A.M.",
style: new TextStyle(fontSize:15.0,
color: const Color(0xFF000000),
fontWeight: FontWeight.w200,
fontFamily: "Roboto"),
)
),
RaisedButton(key:null, onPressed: (){
setState((){
turnToRed = !turnToRed;
});
},
color: Colors.red
child:
new Text(
"Confirm",
style: new TextStyle(fontSize:15.0,
color: const Color(0xFF000000),
fontWeight: FontWeight.w200,
fontFamily: "Roboto"),
)
),