Search code examples
dartflutter-layoutflutter-dependenciesflutter-animationdart-null-safety

How to Combine Two Seperate List in To List of Object


How to convert two Seperate list into List of Object in Fluter,dart

class Task {

String name;
bool isDone
Task({this.name,this.isDone = false});

}

How To Convert this two List in to List as below mention

List<String> taskname = ['buy  milk','go to school','go to gym'];
List<bool> taskname = [true,false,true];

i want to Convert like this

List<Task>  taskList = [

Task(name: 'buy milk',isDone : true),
Task(name: 'go to school',isDone : false),
Task(name: 'buy milk',isDone : true),

];

Solution

  • Try:

    var taskList = [for (var i = 0; i < taskname.length; i++) 
      Task(name: taskname[i], isDone: taskdone[i])
    ];