我有以下代码:
class _StandardCardState extends State<StandardCard> {
@override
Widget build(BuildContext context) {
return Container(
child: Card(
margin: EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0.0),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
children: <Widget>[
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Row(
children: <Widget>[
Text(
'L*: ',
style: TextStyle(
fontSize: 18.0, color: Colors.grey[600]),
),
Text(
widget.standard.L.toString(),
style: TextStyle(
fontSize: 18.0, color: Colors.grey[600]),
),
],
),
SizedBox(height: 6.0),
Row(
children: <Widget>[
//some children
],
),
SizedBox(height: 6.0),
Row(
children: <Widget>[
//some children
],
),
],
),
),
PopupMenuButton<WhyFarther>(
onSelected: (WhyFarther result) {
setState(() {
var _selection = result;
});
},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<WhyFarther>>[
const PopupMenuItem<WhyFarther>(
value: WhyFarther.harder,
child: Text(
'Working a lot harder',
style: TextStyle(fontSize: 18.0, color: Colors.grey[600]),
),
),
const PopupMenuItem<WhyFarther>(
value: WhyFarther.smarter,
child: Text(
'Being a lot smarter',
style: TextStyle(fontSize: 18.0, color: Colors.grey[600]),
),
),
const PopupMenuItem<WhyFarther>(
value: WhyFarther.selfStarter,
child: Text(
'Being a self-starter',
style: TextStyle(fontSize: 18.0, color: Colors.grey[600]),
),
),
const PopupMenuItem<WhyFarther>(
value: WhyFarther.tradingCharter,
child: Text(
'Placed in charge of trading charter',
style: TextStyle(fontSize: 18.0, color: Colors.grey[600]),
),
),
],
)
],
),
),
),
);
}
}
,然后ListView.builder
仍通过另一个函数调用
。当我尝试使用色板更改popupMenuItem中的文本样式时,出现错误“无效的常量值”。
为什么上面的文本小部件没有抛出此错误?以及如何避免这种情况,然后如何在PopupMenuButtons中使用色板?
答案 0 :(得分:0)
我只需要在PopupMenuItem之前删除“ const” ...有时在复制编码有很大帮助的情况下阅读。