I know that single and double quotes have at least some level of equivelence in Dart. For example,
var myString = "Hello world"; // double quotes
and
var myString = 'Hello world'; // single quotes
have no programmatic difference to my knowledge.
I keep seeing them used seemingly interchangeably in various examples and in some documentation. I'm wondering if there is a subtle difference that I am missing or if there is a recommended style to follow, especially in Flutter.
This is a Q&A self answer after reading the Flutter and Dart style guides.
Best Answer
Single and double quotes both work in Dart
is the same as
Delimiters need to be escaped
Use a
\
backslash to escape single quotes in a single quote string.Same thing to escape double quotes in a double quote string.
But no need to escape anything if the delimiter is different.
Also no need to worry about the value passed into an interpolated string.
Prefer single quotes in Flutter
The Flutter style guide recommends using single quotes for everything
except for nested strings
or strings containing single quotes (optional)
The Dart style guide appears to be silent on the issue.