[英]Flutter dart, after IF statement can use object methods
Anyone can explain, why after IF statement can can not use object methods?谁能解释一下,为什么在 IF 语句后不能使用 object 方法?
if(state is CurrentPlayerState){
state.getPermanentStatsByTitle(); <- The method 'getPermanentStatsByTitle' isn't defined for the type 'PlayerState'.
}
PlayerState - is abstract and really not contain the method. PlayerState - 是抽象的,实际上不包含方法。 But CurrentPlayerState has the method.但是CurrentPlayerState有方法。
Try casting it:尝试投射它:
if(state is CurrentPlayerState){
(state as CurrentPlayerState).getPermanentStatsByTitle();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.