1

I am new to flutter . How can we have ArrayList of object in model class flutter .

Following below is the model class I have . but I need to have a list of objects in the model.

class MonitorModel {
  MonitorModel(this.id, this.unitName, this.customerName, this.location,
      this.dateTime, this.totalRunHour, this.lastDayRunHour);
  var id = "";
  var unitName = "";
  var customerName = "";
  var location = "";
  var anotherList<ModelList> = ArrayList()
  var dateTime = "";
  var totalRunHour = "";
  var lastDayRunHour = "";
}
1
  • That is the way i do it: List<ModelList> anotherList = List<ModelList>(); Commented Jan 24, 2021 at 14:06

1 Answer 1

1

Try this out

class MonitorModel {
  MonitorModel(this.id, this.unitName, this.customerName, this.location, this.anotherModelList, this.dateTime, this.totalRunHour, this.lastDayRunHour);
  var id = "";
  var unitName = "";
  var customerName = "";
  var location = "";
  List<AnotherModel> anotherModelList = []; // HERE
  var dateTime = "";
  var totalRunHour = "";
  var lastDayRunHour = "";
}

The other model

class AnotherModel {
  // ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.