Reputation: 99
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 = "";
}
Upvotes: 1
Views: 932
Reputation: 4763
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 {
// ...
}
Upvotes: 1