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'];
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。