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:
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:
List<String> list = ['a', 'b', 'c'];
If the two strings are intended to be a single concatenated string, then either manually merge the strings:
List<String> list = ['ab', 'c'];
Or use the +
operator to concatenate the strings:
List<String> list = ['a' + 'b', 'c'];
Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.