Reputation:
I need to use this String
value. However, I cannot seem use the dollar sign "$".
Text('! @ # $ & * ~', style: TextStyle(color: Colors.grey))
Upvotes: 17
Views: 30874
Reputation: 107
The dollar is a special symbol and we use it for using variables inside the quotation marks.
String currency="ruppee";
Text('Indian currency is ${currency}');
so if we want to save the dollar symbol in string type we need to add /
like this
String symbol = "\$";
Now we can use it as a string.
Upvotes: 4
Reputation: 611
If you have an amount inside a variable and you want to display it with the dollar sign, do this.
void main() {
double amount = 49.99;
print('\$ ${amount}');
}
Output: $ 49.99
Upvotes: 2
Reputation: 247
simply WriteText("\$200",style:TextStyle(fontSize:))
Upvotes: 4
Reputation: 2786
check below code for $ sign
`String dollarSign = String.fromCharCodes(new Runes('\u0024'));
print(dollarSign):`
Upvotes: 0
Reputation: 44056
Besides using a backslash in front of the dollar sign, you can also use a "raw string":
r'! @ # $ & * ~'
The "r" prefix indicates that dollar is no longer a special character.
Upvotes: 18
Reputation: 15741
Dollar is a special character, you need to banalize them with a \
void main(){
String s = "! @ # \$ & * ~";
print('$s');
}
Upvotes: 24
Reputation: 126654
The reason this is not working for you is because the dollar sign $
is used for template literals, which can be used to "interpolate the value of Dart expressions within strings".
When only evaluating identifiers, just a dollar sign followed by the variable name is enough: 'foo: $foo'
However, curly braces can be added to evaluate whole expressions: 'foo * bar: ${foo * bar}'
Having said that, you will need to escape the dollar sign using a backslash: '50\$'
For your example: Text('! @ # \$ & * ~', style: TextStyle(color: Colors.grey))
Upvotes: 4