简体   繁体   中英

Flutter dart, after IF statement can use object methods

Anyone can explain, why after IF statement can can not use object methods?

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. But CurrentPlayerState has the method.

Try casting it:

if(state is CurrentPlayerState){
  (state as CurrentPlayerState).getPermanentStatsByTitle();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM