[英]Dart: How to access a class attribute of an object inside another class? (Nested Class)
I have these two classes MyTask, MyGroup.我有这两个类MyTask,MyGroup。 how can i access MyTask attributes in a list of MyGroup?如何访问 MyGroup 列表中的 MyTask 属性? Please help.请帮忙。 I want to access individual MyTask items in the list of class.我想访问 class 列表中的各个 MyTask 项目。 For Instance I create an object of MyGroup as ABC.例如,我将 MyGroup 的 object 创建为 ABC。 Now I want to set the value for currentTask of ABC.现在我想设置 ABC 的 currentTask 的值。 What should I do to access and set taskName,dueTime etc.我应该怎么做才能访问和设置 taskName、dueTime 等。
class MyTask {
String taskName;
Timestamp dueTime;
String member;
bool completed;
//constructor
MyTask({this.taskName, this.dueTime, this.member, this.completed});
}
class MyGroup {
String groupId;
String groupName;
String groupAdmin;
List<String> groupMembers;
Timestamp groupCreated;
List<MyTask> currentTask;
MyGroup({
this.groupId,
this.groupName,
this.groupAdmin,
this.groupMembers,
this.groupCreated,
this.currentTask,
});
}
MyGroup ABC=MyGroup(groupId: 'xyz',currentTask:[____________]);
What to put in the blank?空白处填什么?
the currentTask
is a List of Objects , If you want to give it a primitive value, you must assign objects of the same Type to it currentTask
是一个对象列表,如果你想给它一个原始值,你必须给它分配相同类型的对象
like this:像这样:
MyGroup ABC=MyGroup(groupId: 'xyz',currentTask:[MyTask(taskName:'taskName1',dueTime:timestampObject1,member:'1',completed:true), MyTask(taskName:'taskName2',dueTime:timestampObject2,member:'2',completed:false)]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.