Skip to main content

no_adjacent_strings_in_list

Don't use adjacent strings in a list literal.

Description

#

The analyzer produces this diagnostic when two string literals are adjacent in a list literal. Adjacent strings in Dart are concatenated together to form a single string, but the intent might be for each string to be a separate element in the list.

Example

#

The following code produces this diagnostic because the strings 'a' and 'b' are adjacent:

dart
List<String> list = ['a' 'b', 'c'];

Common fixes

#

If the two strings are intended to be separate elements of the list, then add a comma between them:

dart
List<String> list = ['a', 'b', 'c'];

If the two strings are intended to be a single concatenated string, then either manually merge the strings:

dart
List<String> list = ['ab', 'c'];

Or use the + operator to concatenate the strings:

dart
List<String> list = ['a' + 'b', 'c'];