帮助,当我在myMethod
小部件或onTap
小部件的GestureDetector
属性中调用InkWell
时,我遇到了only static members can be accessed in initializers
错误>
static String seat1Source = 'images/carSeatBlack.png';
_stater(){
setState(() {
if(seat1Source == 'images/carSeatBlack.png'){
seat1Source = 'images/carSeatGreen.png';
}else{
seat1Source = 'images/carSeatBlack.png';
}
});
}
var seat1 = new InkWell(
onTap: () => _stater(),
child: new Image.asset(
seat1Source,
height: 30,
width: 60,
)
);
答案 0 :(得分:1)
用这样的函数替换InkWell
变量
_buildButton(){return new InkWell(
onTap: () => _stater(),
child: new Image.asset(
seat1Source,
height: 30,
width: 60,
)
);}
答案 1 :(得分:0)
除了已经提到的方法外,另一种方法是将变量“ seat1”放入 进入“ Widget build(BuildContext context){}”函数中,因为我认为您正在尝试将其初始化为构造函数。