Difference between single and double quotes in Flutter/Dart
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.
string dart

add a comment |
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.
string dart

add a comment |
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.
string dart

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.
string dart

string dart

asked Jan 3 at 0:28
SuragchSuragch
213k126718780
213k126718780
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Single and double quotes both work in Dart
final myString = 'hello';
is the same as
final myString = "hello";
Delimiters need to be escaped
Use a backslash to escape single quotes in a single quote string.
final myString = 'Bob's dog'; // Bob's dog
Same thing to escape double quotes in a double quote string.
final myString = "a "quoted" word"; // a "quoted" word
But no need to escape anything if the delimiter is different.
final myString = "Bob's dog"; // Bob's dog
final myString = 'a "quoted" word'; // a "quoted" word
Also no need to worry about the value passed into an interpolated string.
final value = '"quoted"'; // "quoted"
final myString = "a $value word"; // a "quoted" word
Prefer single quotes in Flutter
The Flutter style guide recommends using single quotes for everything
final myString = 'hello';
except for nested strings
print('Hello ${name.split(" ")[0]}');
or strings containing single quotes (optional)
final myString = "Bob's dog";
final myString = 'Bob's dog'; // ok
The Dart style guide appears to be silent on the issue.
1
The Dart style guide is indeed silent on the issue. A recommended style has been proposed and discussed many times, but there is no consensus that one style is universally better than another. Arguments for single quotes include that they are lighter on the eye and easier to type on a US keyboard. Arguments for double-quotes include that are easier to read because they stand out more, and you have more strings containing apostrophes than containing quotes.
– lrn
Jan 3 at 8:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014913%2fdifference-between-single-and-double-quotes-in-flutter-dart%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Single and double quotes both work in Dart
final myString = 'hello';
is the same as
final myString = "hello";
Delimiters need to be escaped
Use a backslash to escape single quotes in a single quote string.
final myString = 'Bob's dog'; // Bob's dog
Same thing to escape double quotes in a double quote string.
final myString = "a "quoted" word"; // a "quoted" word
But no need to escape anything if the delimiter is different.
final myString = "Bob's dog"; // Bob's dog
final myString = 'a "quoted" word'; // a "quoted" word
Also no need to worry about the value passed into an interpolated string.
final value = '"quoted"'; // "quoted"
final myString = "a $value word"; // a "quoted" word
Prefer single quotes in Flutter
The Flutter style guide recommends using single quotes for everything
final myString = 'hello';
except for nested strings
print('Hello ${name.split(" ")[0]}');
or strings containing single quotes (optional)
final myString = "Bob's dog";
final myString = 'Bob's dog'; // ok
The Dart style guide appears to be silent on the issue.
1
The Dart style guide is indeed silent on the issue. A recommended style has been proposed and discussed many times, but there is no consensus that one style is universally better than another. Arguments for single quotes include that they are lighter on the eye and easier to type on a US keyboard. Arguments for double-quotes include that are easier to read because they stand out more, and you have more strings containing apostrophes than containing quotes.
– lrn
Jan 3 at 8:02
add a comment |
Single and double quotes both work in Dart
final myString = 'hello';
is the same as
final myString = "hello";
Delimiters need to be escaped
Use a backslash to escape single quotes in a single quote string.
final myString = 'Bob's dog'; // Bob's dog
Same thing to escape double quotes in a double quote string.
final myString = "a "quoted" word"; // a "quoted" word
But no need to escape anything if the delimiter is different.
final myString = "Bob's dog"; // Bob's dog
final myString = 'a "quoted" word'; // a "quoted" word
Also no need to worry about the value passed into an interpolated string.
final value = '"quoted"'; // "quoted"
final myString = "a $value word"; // a "quoted" word
Prefer single quotes in Flutter
The Flutter style guide recommends using single quotes for everything
final myString = 'hello';
except for nested strings
print('Hello ${name.split(" ")[0]}');
or strings containing single quotes (optional)
final myString = "Bob's dog";
final myString = 'Bob's dog'; // ok
The Dart style guide appears to be silent on the issue.
1
The Dart style guide is indeed silent on the issue. A recommended style has been proposed and discussed many times, but there is no consensus that one style is universally better than another. Arguments for single quotes include that they are lighter on the eye and easier to type on a US keyboard. Arguments for double-quotes include that are easier to read because they stand out more, and you have more strings containing apostrophes than containing quotes.
– lrn
Jan 3 at 8:02
add a comment |
Single and double quotes both work in Dart
final myString = 'hello';
is the same as
final myString = "hello";
Delimiters need to be escaped
Use a backslash to escape single quotes in a single quote string.
final myString = 'Bob's dog'; // Bob's dog
Same thing to escape double quotes in a double quote string.
final myString = "a "quoted" word"; // a "quoted" word
But no need to escape anything if the delimiter is different.
final myString = "Bob's dog"; // Bob's dog
final myString = 'a "quoted" word'; // a "quoted" word
Also no need to worry about the value passed into an interpolated string.
final value = '"quoted"'; // "quoted"
final myString = "a $value word"; // a "quoted" word
Prefer single quotes in Flutter
The Flutter style guide recommends using single quotes for everything
final myString = 'hello';
except for nested strings
print('Hello ${name.split(" ")[0]}');
or strings containing single quotes (optional)
final myString = "Bob's dog";
final myString = 'Bob's dog'; // ok
The Dart style guide appears to be silent on the issue.
Single and double quotes both work in Dart
final myString = 'hello';
is the same as
final myString = "hello";
Delimiters need to be escaped
Use a backslash to escape single quotes in a single quote string.
final myString = 'Bob's dog'; // Bob's dog
Same thing to escape double quotes in a double quote string.
final myString = "a "quoted" word"; // a "quoted" word
But no need to escape anything if the delimiter is different.
final myString = "Bob's dog"; // Bob's dog
final myString = 'a "quoted" word'; // a "quoted" word
Also no need to worry about the value passed into an interpolated string.
final value = '"quoted"'; // "quoted"
final myString = "a $value word"; // a "quoted" word
Prefer single quotes in Flutter
The Flutter style guide recommends using single quotes for everything
final myString = 'hello';
except for nested strings
print('Hello ${name.split(" ")[0]}');
or strings containing single quotes (optional)
final myString = "Bob's dog";
final myString = 'Bob's dog'; // ok
The Dart style guide appears to be silent on the issue.
answered Jan 3 at 0:28
SuragchSuragch
213k126718780
213k126718780
1
The Dart style guide is indeed silent on the issue. A recommended style has been proposed and discussed many times, but there is no consensus that one style is universally better than another. Arguments for single quotes include that they are lighter on the eye and easier to type on a US keyboard. Arguments for double-quotes include that are easier to read because they stand out more, and you have more strings containing apostrophes than containing quotes.
– lrn
Jan 3 at 8:02
add a comment |
1
The Dart style guide is indeed silent on the issue. A recommended style has been proposed and discussed many times, but there is no consensus that one style is universally better than another. Arguments for single quotes include that they are lighter on the eye and easier to type on a US keyboard. Arguments for double-quotes include that are easier to read because they stand out more, and you have more strings containing apostrophes than containing quotes.
– lrn
Jan 3 at 8:02
1
1
The Dart style guide is indeed silent on the issue. A recommended style has been proposed and discussed many times, but there is no consensus that one style is universally better than another. Arguments for single quotes include that they are lighter on the eye and easier to type on a US keyboard. Arguments for double-quotes include that are easier to read because they stand out more, and you have more strings containing apostrophes than containing quotes.
– lrn
Jan 3 at 8:02
The Dart style guide is indeed silent on the issue. A recommended style has been proposed and discussed many times, but there is no consensus that one style is universally better than another. Arguments for single quotes include that they are lighter on the eye and easier to type on a US keyboard. Arguments for double-quotes include that are easier to read because they stand out more, and you have more strings containing apostrophes than containing quotes.
– lrn
Jan 3 at 8:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014913%2fdifference-between-single-and-double-quotes-in-flutter-dart%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown