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
Related
i am using import { makeStyles } from '#mui/styles'
This is my theme typography config
enter image description here
This is file, i want to combine these 3 attributes into 1 line of code.enter image description here
Sorry that my English is not good, so it may cause misunderstandings for everyone. Looking forward to support
i want to combine these 3 attributes into 1 line of code
const a =
{
fontSize: theme.typography.text12Medium16.fontSize;
lineHeight: theme.typography.text12Medium16.lineHeight;
fontWeight: theme.typography.text12Medium16.fontWeight;
}
this is what you are passing to MuiDataGrid-main
and this is your text12Mediul16 object :
const text12Mediul16 =
{
fontSize: '12px',
lineHeight: '16px',
fontWeight: FONT_MEDIUM
}
and since :
theme.typography.text12Medium16.fontSize = '12px'
theme.typography.text12Medium16.lineHeight = '16px'
theme.typography.text12Medium16.fontWeight = FONT_MEDIUM
then a = text12Mediul16 so you can replace it like this :
'& .MuiDataGrid-main: theme.typography.text12Medium16'
and if your object contains other properties apart from fontSize, fontWeight and lineHeight that are not shown in your code example, then you can't do better than you did
I defined editorStyleMap and use them
const editorStyleMap = { Choose: { color: '#4880f0' }, Black: { color: '#000000' } }
then I get the array of inlineStyleRanges
const messageBlocks=convertToRaw(editorState.getCurrentContent()).blocks[0].inlineStyleRanges;
i console every item of the array and the result is below,
item's style can be 'Choose' or 'Black'
{offset: 3, length: 3, style: 'Choose'} {offset: 6, length: 5, style:
'Black'} {offset: 11, length: 3, style: 'Choose'} {offset: 14, length:
1, style: 'Black'}
but when i want to use if to judge the type of style
if(item.style==='Choose')
terminal reports an error
'This condition will always return 'false' since the types
'DraftInlineStyleType' and '"Choose"' have no overlap.'
it seems that styleType only can be default type like 'BOLD' and 'ITALIC'.
i don't know why??? if you could help me, i would be grateful:)
i use a strange way to solve the problem.
just use String() method to convert item.style to string type, and the string can be anything you define
if(String(item.style)==='Choose')
The terminal does not report an error
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 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),
);