我正在尝试理解flutter_gallery中的
我在这个提交中看到了一个破坏性的变化。
我只能使用以下类似的代码才能使其编译通过:
我理解异常的含义,但不知道是否有办法将变量传递给Text()。
这是VSCode中异常弹出窗口(在红框中):
这是Samsung S7手机上的异常:
在Stackoverflow上搜索显示this,看起来与我的问题无关。
List
example。我的方法是通过重构成(我的项目)来简化“`”代码。我在这个提交中看到了一个破坏性的变化。
I/flutter (14712): 'file:///Users/hong/Flutter/github/flutter_gallery_material_list/lib/main.dart': error: line 54:
I/flutter (14712): expression is not a valid compile-time constant
I/flutter (14712): const Text t = const Text(text);
源代码起始行为53:
MergeSemantics _mergeSemanticsOf(String text, _MaterialListType listType) {
const Text t = const Text(text);
//const Text t = const Text('we want a variable here');
return new MergeSemantics(
child: new ListTile(
dense: true,
title: t,
trailing: new Radio<_MaterialListType>(
value: listType,
groupValue: _itemType,
onChanged: changeItemType,
)),
);
}
我只能使用以下类似的代码才能使其编译通过:
const Text t = const Text('我们想要一个变量在这里');
。我理解异常的含义,但不知道是否有办法将变量传递给Text()。
这是VSCode中异常弹出窗口(在红框中):
![enter image description here](https://istack.dev59.com/XzPQO.webp)
![enter image description here](https://istack.dev59.com/Vnjs5.webp)
Text t = new Text(text);
来解决问题。提交记录在这里。 - XoXo