是否可以在Dart / Flutter中制作对象数组

时间:2019-11-29 17:14:07

标签: flutter dart

您好,我想知道是否可以在dart / flutter中制作对象数组。

class Student {
int math;
}

Student[] studentArray = new 
Student[7];

studentArray [0] =新的Student();

1 个答案:

答案 0 :(得分:0)

void main() {
  List persons = [User("foo"), User("bar")]; //non-empty on create


  List users = []; //blank initially
  for (int i = 0; i < 5; i++) {
    users.add("User $i");
  }

//print using iterator
  for (var u in users) {
    print(u);
  }

  /*
   * first element can be accessed using users[0] or users.first
   * last element can be accessed using users.last
   * */
}

class User {
  String name;
  User(this.name);
}