【问题标题】:Can Dart function accept scoped arguments?Dart 函数可以接受范围参数吗?
【发布时间】:2019-08-05 08:38:22
【问题描述】:

Dart 可以接受带有提示和作用域参数的参数吗?

示例:

types PostType = {
  "HOT": 1,
  "NEW": 2,
  "TRENDING": 3
}


function getPost(PostType type){
 if(type == PostType.TRENDING) {
    // do something
 }
 // some code
}

Posts posts = getPost(PostType.TRENDING);

以上代码getPost() 只接受 PostType 值。 有可能吗?

【问题讨论】:

  • 是的。我邀请你read this
  • @JulienLachal vscode IDE 智能感知可以建议这些值吗?你能用上面的例子给我看看合适的例子吗?谢谢
  • 什么时候建议值?我没有使用 VSCode,但在输入 PostType. 之后,我想它会为您提供枚举中的类型。
  • @JulienLachal 啊是的,它叫ENUM!谢谢!

标签: flutter dart


【解决方案1】:

正如@JulientLachal 所说,它被称为枚举!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 2014-01-13
    相关资源
    最近更新 更多