Home > Back-end >  Unable to set special characters in a variable value in a class in flutter dart
Unable to set special characters in a variable value in a class in flutter dart

Time:12-20

I am unable to set a string with special characters. It is working fine if I only set a string.

I have written this line:

static var var1 = "s$kncsfiu(AKdhjkhj^sjffhj&jh%";

But it is showing this error: enter image description here

Any clues how can I set this variable value in Dart flutter?

CodePudding user response:

$ is used in strings for when you want to insert the value of a variable directly into your string. If you want to write $ in your string, you need to escape it like:

static var var1 = "s\$kncsfiu(AKdhjkhj^sjffhj&jh%";

Or do it with marking your string as a "raw" string which disable features like the $ variable replacement:

static var var1 = r"s$kncsfiu(AKdhjkhj^sjffhj&jh%";

For more information, please read the following section in the Dart Language Tour: https://dart.dev/guides/language/language-tour#strings

CodePudding user response:

Dollar sign is a special one in dart.

See this for an answer: How to add dollar sign $ to strings in Dart?

  •  Tags:  
  • dart
  • Related