Sudhi
Sudhi

Reputation: 229

List of Class Objects operation in Dart

Have an issue in the below chunk of code.

class Events
{
 // some member variables
}


class SVList
{ 
  String name;
  int contentLen;
  List<Events> listEvents;  

  SVList()
  {
    this.name = "";
    this.contentLen = 0;
    this.listEvents = new List<Events>();
  }
}

class GList
{
  List<SVList> listSVList;

  GList(int Num)
  {
   this.listSVList = new List<SvList>(num);   
  } 
}


 function f1 ()
 {
   //array of class objects 
   GList gList = new GList(num);
 }

Not able to find "listEvents" member after GList constructor is called. Am I missing anything here.

Referencing glist.listSVList[index] --> do not find member variable 'listEvents'. Any pointers appreciated.

To elaborate , no member variable with 'glist.listSVList[index].listEvents' is found.

Upvotes: 3

Views: 28450

Answers (2)

Noah Velasco
Noah Velasco

Reputation: 69

Lists in Dart can now be stated as

List<Object> array = []

Upvotes: 3

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657691

you have a typo here:

this.listSVList = new List<SvList>(num);  // <== SVList not SvList

function seems wrong here

function f1 () { ... }

in this case you use function as a return type

another typo:

GList(int Num) // <== Num (uppercase)
{
  this.listSVList = new List<SvList>(num);   // <== num (lowercase)
} 

this code worked:

class Events {
  // some member variables
}

class SVList {
  String name;
  int contentLen;
  List<Events> listEvents;

  SVList() {
    this.name = "";
    this.contentLen = 0;
    this.listEvents = new List<Events>();
  }
}

class GList {
  List<SVList> listSVList;

  GList(int num) {
    this.listSVList = new List<SVList>(num);
  }
}


main() {
  //array of class objects
  GList gList = new GList(5);
  gList.listSVList[0] = new SVList();
  gList.listSVList[0].listEvents.add(new Events());
  print(gList.listSVList[0].listEvents.length);
}

What editor are you using?
DartEditor showed all errors immediately after I pasted your code.

Upvotes: 3

Related Questions