可以在扑波中添加元素添加元素
如何将元素添加到我的列表
decklist
中?
decklist.add(first);
在红色的红色下,注释: “构造函数的名称必须匹配封闭类的名称。”
import 'dart:ui';
class _GamingCard{
int ?value1;
int ?value2;
String ?name;
String ?type;
Image ?image;
_GamingCard(this.value1,this.value2,this.name,this.type,this.name);
}
class _DeckofCards{
List<_GamingCard> ?deckList = List<_GamingCard>.empty(growable: true);
_GamingCard first = _GamingCard(1,10,'ace','heart',null);
_GamingCard second = _GamingCard(1,10,'ace','cross',null);
deckList.add(first);
}
how can I add the element first
to my List deckList
?
deckList.add(first);
is under lighted red with the note:
"The name of a constructor must match the name of the enclosing class."
import 'dart:ui';
class _GamingCard{
int ?value1;
int ?value2;
String ?name;
String ?type;
Image ?image;
_GamingCard(this.value1,this.value2,this.name,this.type,this.name);
}
class _DeckofCards{
List<_GamingCard> ?deckList = List<_GamingCard>.empty(growable: true);
_GamingCard first = _GamingCard(1,10,'ace','heart',null);
_GamingCard second = _GamingCard(1,10,'ace','cross',null);
deckList.add(first);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
交战来自零安全性。如果您想首先插入数据,则可以使用构造函数或提供内部列表。
像
它可以
list
在飞镖上另外一件事,在您的
_GamingCard
构造函数上,您没有包括图像
参数,也最好为此使用命名构造函数。有关 laster-constructor
The warring is coming from null-safety. If you like to insert data firstly, you can use constructor or provide inside list.
It can be like
Or just add while declaring list
More about
List
on dartOne more thing, on your
_GamingCard
constructor, you didn't includeimage
params, also It would be better to use named constructor for this.More about using-constructors