如何纠正这个问题以满足 Flutter 中的 Lint 消息?

问题描述 投票:0回答:1

我收到以下 lint

Text("The color is " + item['color'])

“使用插值来组合字符串和值。(文档)尝试使用字符串插值来构建复合字符串。”

以下是代码在我的 ListView / ListTile 中的使用方式。我怎样才能重写得更好,没有任何提示。

child: ListView.separated(
            itemCount: dataList.length,
            itemBuilder: (ctx, index) {
              final item = dataList[index];
              return ListTile(
                title: item['value'] == ''
                    ? 
                    Text(
                            "The color is " + item['color'])
                       
flutter flutter-listview
1个回答
0
投票

你可以使用

Text("The color is ${item['color']}")

而不是

Text("The color is " + item['color'])
© www.soinside.com 2019 - 2024. All rights reserved.