dart - Named parameter with underscore in Dart class
问题描述
From the Dart language tour you can do this:
class Person {
final _name;
const Person(this._name);
}
How can I get a named parameter like this:
class Person {
final _name;
const Person({@required this._name});
}
So the usage will be:
const Person(name: 'SD')
I still want a const
constructor. Is this possible?
解决方案
You can, but not with the this.variable
syntax
const Person({ String name}) : _name = name;
推荐阅读
- python - 如何让嵌套交叉验证在多个内核上运行?
- c# - 如何在 Jenkins 中使用自定义贴标机?
- php - URL 中的双斜杠在 $_SERVER['REQUEST_URI'] 中自动转换为单斜杠
- android - 如何在 libgdx 中显示具有多个屏幕的插页式广告?
- haskell - 在 preorder 和 inorder 之后用两个列表重建二叉树
- c++ - 为返回的对象移动构造函数会破坏 C++98 代码?
- c++ - 调用基本构造函数时遇到问题 - 读取访问冲突
- xcode - 找不到 Firebase/Firebase.h 文件
- python-3.x - 初始化子字典理解的子字典
- java - 导航抽屉上的 Backpressed 退出对话框 BackPressed 不起作用