I need to display the combining overline character (unicode U+0305) over some other characters, like '2' or 'x'.
https://www.fileformat.info/info/unicode/char/0305/index.htm
Is there a way to accomplish this in Dart?
Thanks in advance.
You can combine by placing the unicode right after the letter:
String overlined = 'O\u{0305}V\u{0305}E\u{0305}R\u{0305}';
print(overlined); // Output: O̅V̅E̅R̅
A more dynamic version (with simplistic logic) would be:
void main() {
String overlined = overline('I AM AN OVERLINED TEXT');
print(overlined); // Output: I̅ A̅M̅ A̅N̅ O̅V̅E̅R̅L̅I̅N̅E̅D̅ T̅E̅X̅T̅
}
String overline(String text) {
return text.split('').map((String char) {
if (char.trim().isEmpty)
return char;
else
return '$char\u{0305}';
}).join();
}
However, this is pretty much limited. A better approach would be using the style property of Flutter's Text to do so:
const Text(
'OVER',
style: TextStyle(decoration: TextDecoration.overline),
);
Related
As SVG format is not supported by flutter. I'm forced to use flutter_svg package which doesn't support .png.
So I'm looking for a solution which supports both SVG and other picture formats like .png,.jpg etc.
PS: the network url is mapped like example.com/media/id so there's no extention in the url.
You can use sample following methods
Widget getPicture(String url) {
var mimeType = getFileExtension(url);
if (mimeType == "svg") {
return SvgPicture.asset(
assetName,
color: Colors.red,
semanticsLabel: 'A red up arrow'
);
}
else {
return NetworkImage(...)
}
}
String getFileExtension(String fileName) {
return "." + fileName.split('.').last;
}
Hi guys I'm trying to remove or hide the last letter from List
Any possible ways?
Text(list[i].name,
style: GoogleFonts.poppins(
fontWeight: FontWeight.w400,
color:
list[i].isBook == "0"
? selectedTimingSlot[i] ? WHITE : BLACK
: Colors.grey.withOpacity(0.5),
fontSize: 15,
),
),
**Above code shows= "12:00 AM" I need to hide or remove "AM"**
Use substring method:
main() {
print("12:00 AM".substring(0,5));
}
Or with replaceAll method:
main() {
print("12:00 AM".replaceAll("AM","").replaceAll("PM",""));
}
with regular expression:
main() {
var regex = new RegExp(r'[a-zA-Z]');
print("02:00 AM".replaceAll(regex,""));
}
Ketan’s substring method is a terrible way of doing this, what about “9:00 PM”?
Edit: looks like his method worked perfectly!
Use regex and/or the following package:
https://pub.dev/packages/string_validator
The way I do it is with this extension
extension StringExtension on String {
String deleteLastChar({int toDelete = 1}) => substring(0, length - toDelete);
}
And you can use like
"12:00 AM".deleteLastChar(toDelete: 3) // Prints 12:00
Why toDelete: 3? Because you also want to remove the space between 12:00 and AM
In my flutter application I'm using qcf_bsml font, I have to generate the hex values to display the corresponding words in the font file. For that, I'm using this equation:
(64396 + Id >= 64434) ? 64429 + chapterId : 64396 + Id
I convert the result from above to hex value using this function:
calculatehex(){
final myInteger = (64396 + 1 >= 64434) ? 64429 + 1 : 64396 + 1; //Id is 1: result 64397
final hexString = myInteger.toRadixString(16);
final paddedString = hexString.padLeft(4, '0');
uppercaseString = paddedString.toUpperCase();
print(uppercaseString); //displays correct hex value in console :FB8D
}
The problem is I am only able to hardcode the hex value in text field to display the correct word. For example:
new Text('\u{FB8D}',textDirection: TextDirection.rtl,
style:TextStyle(fontSize:30.0, fontWeight: FontWeight.w100,fontFamily: 'QCF'),
textAlign:TextAlign.center ), // works fine
But if I use the variable name to display text, it displays the wrong word.
new Text(uppercaseString,textDirection: TextDirection.rtl,
style:TextStyle(fontSize:30.0, fontWeight: FontWeight.w100,fontFamily: 'QCF'),
textAlign:TextAlign.center ), // not showing correct word
I tried to concatenate the string like this, but still not working fine
new Text(r'\u{'+uppercaseString+'}',textDirection: TextDirection.rtl,
style:TextStyle(fontSize:30.0, fontWeight: FontWeight.w100,fontFamily: 'QCF'),
textAlign:TextAlign.center ),
Please help me understand why is it display the correct word with hardcoded value with '\u' but not with variable. Thank you
I solved it by using String.fromCharCode(int.parse()) & making following changes in the code:
uppercaseString = paddedString.toUpperCase();
finalhexString ='0x$uppercaseString';
then:
new Text(String.fromCharCode(int.parse(finalhexString)),textDirection: TextDirection.rtl,
style:TextStyle(fontSize:30.0, fontWeight: FontWeight.w100,fontFamily: 'QCF'),
textAlign:TextAlign.center ),
have a question about formatting the Rupee currency (Indian Rupee - INR).
For example, numbers here are represented as:
1
10
100
1,000
10,000
1,00,000
10,00,000
1,00,00,000
10,00,00,000
But not able to find any reference library where I can separate comma number in Indian formate.
You can use Intl package as follow:
var format = NumberFormat.currency(locale: 'HI');
print(format.format(100000000));//10,00,00,000.00
You can use Intl package as follow:
final indianRupeesFormat = NumberFormat.currency(
name: "INR",
locale: 'en_IN',
decimalDigits: 0, // change it to get decimal places
symbol: '₹ ',
);
Or,
You can format any number as you want:
final numberFormatter = NumberFormat(
"##,##,###",
"en_US", // local US
)
An Extension to format numbers into Indian currency format:
extension RupeesFormatter on int {
String inRupeesFormat() {
return indianRupeesFormat.format(this);
}
}
use it like this:
Text(
2000.inRupeesFormat(), // output: ₹ 2,000
),
amount.toLocaleString('en-IN', {currency: 'INR', style: 'currency'}) is best jquery function to get Indian thousand comma seperator Format
toLocaleString
var amount="9887977998";
//if amount symbol required
console.log(addCommaSeperatorForAmt(amount,true))
function addCommaSeperatorForAmt(amount, symbolRequired) {
var amountDigit = "";
if (!symbolRequired) {
amountDigit = Number(amount).toLocaleString('en-IN', {currency: 'INR', style: 'currency'}).replaceAll(/₹/g, "");
} else {
amountDigit = Number(amount).toLocaleString('en-IN', {currency: 'INR', style: 'currency'});
}
return amountDigit;
}
Find this Ref:https://www.w3schools.com/jsref/jsref_tolocalestring.asp
Use locale 'en_IN' for English Indian formatting and 'HI' for Hindi Indian formatting
var indiaFormat = NumberFormat.compactCurrency(locale: 'HI');
print(indiaFormat.format(1000000));//10 लाख
var indiaFormat = NumberFormat.compactCurrency(locale: 'en_IN');
print(indiaFormat.format(1000000));//10L
If you want to show amount with ₹ symbol then use the following code:
Text(
NumberFormat.currency(
symbol: '₹ ',
locale: "HI",
decimalDigits: 3,
).format(amount),
),
Don't forget to import the intl package.
I have added the plugin wordcount to count the number of words entered in my TinyMCE texteditor.
plugins: "wordcount",
wordcount_cleanregex: /[.(),;:!?%#$?\x27\x22_+=\\/\-]*/g
It is counting letters and numbers but when I am giving a special character , it is not counting them.
for e.g ----
Hi I am 18 year old (for this it is giving me count 6)
Hi I am ## year old (for this it is giving me count 5)
Any idea what I need to do. I tried to remove:
%#$ from wordcount_cleanregex , but it didn't work.
Your issue is not with the wordcount_cleanregex setting but rather with the wordcount_countregex setting:
https://www.tinymce.com/docs/plugins/wordcount/#wordcount_countregex
If you look at the default one you will see why its skipping the characters that it is. Here is the exact regex:
https://regex101.com/r/wL4fL1/1
If you tweak that regex you can get it to count your ## as a word.
Note: There is some core cleaning that is done within the wordcount plugin that is done regardless of your configuration settings. In TinyMCE 4.4.1 it looks like this:
if (tx) {
tx = tx.replace(/\.\.\./g, ' '); // convert ellipses to spaces
tx = tx.replace(/<.[^<>]*?>/g, ' ').replace(/ | /gi, ' '); // remove html tags and space chars
// deal with html entities
tx = tx.replace(/(\w+)(&#?[a-z0-9]+;)+(\w+)/i, "$1$3").replace(/&.+?;/g, ' ');
tx = tx.replace(cleanre, ''); // remove numbers and punctuation
var wordArray = tx.match(countre);
if (wordArray) {
tc = wordArray.length;
}
}
...so some core things are still stripped from your content regardless of what you put in the wordcount_cleanregex and wordcount_countregex. If you want to change this core behavior you will need to modify the plugin's source code.
here is my wordcount plugin which I am adding externally , The function getCount returns the number of words perfectly when I run this function seprately on my .aspx page as javascript function, but when I am running under this plugin it is only counting letters (it is not counting any number/special characters)
tinymce.PluginManager.add('wordcount', function(editor) {
function update() {
editor.theme.panel.find('#wordcount').text(['Words: {0}', getCount()]);
}
editor.on('init', function() {
var statusbar = editor.theme.panel && editor.theme.panel.find('#statusbar')[0];
if (statusbar) {
tinymce.util.Delay.setEditorTimeout(editor, function() {
statusbar.insert({
type: 'label',
name: 'wordcount',
text: ['Words: {0}', getCount()],
classes: 'wordcount',
disabled: editor.settings.readonly
}, 0);
editor.on('setcontent beforeaddundo', update);
editor.on('keyup', function(e) {
if (e.keyCode == 32) {
update();
}
});
}, 0);
}
});
getCount = function () {
var body = editor.getBody().innerHTML;
text1 = body.replace(/<[^>]+>/g, '');
s = text1.replace(/ /g, ' ');
s = s.replace(/(^\s*)|(\s*$)/gi, "");//exclude start and end white-space
s = s.replace(/[ ]{2,}/gi, " ");//2 or more space to 1
s = s.replace(/\n /, "\n"); // exclude newline with a start spacing
return s.split(' ').length;
};
});