How do you show a dollar sign $ in Flutter?

8,353 views
Skip to first unread message

Niyazi Toros

unread,
May 29, 2018, 7:32:21 AM5/29/18
to Flutter Dev
How do you show a dollar sign $ in Flutter?

I have a currency section in my app and I need to show user a dollar sign $. How do I do that?

"\$ Dollar: " is not working....

Any help please?

Mikkel Ravn

unread,
May 29, 2018, 8:11:06 AM5/29/18
to niyazi...@gmail.com, Flutter Dev
\$ is the correct escape sequence for a dollar sign. If you don't need interpolation in your string you can also use a raw string literal by prefixing with r. For example:

    int amount = 42;
    ...
    Column(children: <Widget>[
      Text('here is a dollar amount: \$$amount'),
      Text(r'here is a dollar sign: $'),
    ]))

Shows

   here is a dollar amount: $42
   here is a dollar sign: $

on screen. If that does not work for you, there is likely some other error at play. Please include more of your code in that case.

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Mikkel Nygaard Ravn
Software Engineer

Niyazi Toros

unread,
May 29, 2018, 8:37:25 AM5/29/18
to Flutter Dev
Thanks for reply.

In my internationalization load I had 3 json file as shown below:

the appBar title works well.
title: new Text(
  trans(context, "main.appTitle"),
style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.w500),
),

the currency part is not working and giving me error.
children: <Widget>[
_buildAction(
trans(context, "main.dollar"),
trans(context, "main.currency.buy"),
stgBuy,
trans(context, "main.currency.sell"),
stgSell,
Colors.red,
blueGradient,
new AssetImage("assets/images/dollar.png")),


ERROR IS:
E/flutter (10721): FormatException: Unrecognized string escape (at line 6, character 28)
E/flutter (10721):   "main.dollar": "\$ Dollar",



The json files..............


en.json

{

  "main.sterling": "£ Sterling",

  "main.euro": "€ Euro",

  "main.dollar": "\$ Dollar",

  "main.currency.buy": "Buy: ",

  "main.currency.sell": "Sell: ",

}


tr.json

{

  "main.sterling": "£ Sterling",

  "main.euro": "€ Euro",

  "main.dollar": "\$ Dollar",

  "main.currency.buy": "Alış: ",

  "main.currency.sell": "Satış: ",

}



ru.json

{

  "main.sterling": "£ Sterling",

  "main.euro": "€ Euro",

  "main.dollar": "\$ Dollar",

  "main.currency.buy": "купить: ",

  "main.currency.sell": "продавать: ",

}

Mikkel Ravn

unread,
May 29, 2018, 8:56:06 AM5/29/18
to niyazi...@gmail.com, Flutter Dev
You should not escape $ in JSON, only in Dart.

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niyazi Toros

unread,
May 29, 2018, 9:08:35 AM5/29/18
to Flutter Dev
Thanks Mikkel, is working :)

Kind Regards
Reply all
Reply to author
Forward
0 new messages