Flutter Can';t在文本小部件中显示变量值(颤振)
我有以下代码:Flutter Can';t在文本小部件中显示变量值(颤振),flutter,dart,Flutter,Dart,我有以下代码: _places.forEach((element) { final String name = element.name; print(element); places.add(Card( child: InkWell( splashColor: Colors.blue.withAlpha(30), onTap: () { print('Card tapped.'); },
_places.forEach((element) {
final String name = element.name;
print(element);
places.add(Card(
child: InkWell(
splashColor: Colors.blue.withAlpha(30),
onTap: () {
print('Card tapped.');
},
child: const SizedBox(
width: 375,
height: 100,
child: Padding(
padding: EdgeInsets.all(15.00),
child: Text(
name
)
)))));
});
我遇到的问题是变量name
在Text
中使用时出错
错误:不是常量表达式。
请尝试从大小框中删除常量。SizedBox期望数据为常量,但变量text可以在运行时更改const用于编译时值为常量的情况。完美。非常感谢。一经允许,我就接受这个答案