Thompson
Thompson

Reputation: 2000

Unable to set special characters in a variable value in a class in flutter dart

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?

Upvotes: 1

Views: 486

Answers (1)

julemand101
julemand101

Reputation: 31219

$ 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

Upvotes: 2

Related Questions