简体   繁体   中英

How do I use an enum as a return value in Flutter?

I can't find an answer to this in my searches. How do I return an enum as the result of a function? It feels like a stupid question that I just can't figure out.

enum getCardObjectType(val object) {
    if(val is wantedObjectType)
      return CardType.Link;
  }

Use CardType as return type.

The fact that CardType is an enum doesn't change the syntax here, the type is just CardType.

An example of an Enum is:

enum CardType {
    link,
    option2
}

your function should be something like this:

CardType getCardObjectType(val object) {
    if(val is wantedObjectType)
      return CardType.Link;
}

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