flutter
List Data Structures
void main() {
//print(_showDateFormat());
var oneTask = new Task("A", _genId());
_addToMap(oneTask);
_addToList(oneTask);
oneTask = new Task("B", _genId());
_addToMap(oneTask);
_addToList(oneTask);
for (final oneTask in taskList) {
print(oneTask.name);
}
// int foundIndex = taskList.indexWhere((taskItem) {
// taskItem.name.startsWith('B');
// });
print("Index found at .. ");
print(_findInList("A").id);
// details.forEach((k, v) {
// print(k);
// print(v.name);
// });
}
class Task {
String name;
int id;
Task(this.name, this.id);
}
// DateTime stuff
_showDateFormat() {
var currDt = DateTime.now();
// var newDt = DateFormat.yMMMEd().format(currDt);
// return newDt;
}
// List stuff -------------------------
var taskList = new List<Task>();
_addToList(Task task) {
taskList.add(task);
}
Task _findInList(String query) {
return taskList.singleWhere((taskItem) => taskItem.name == query);
}
_removeFromList(int id) {
taskList.removeWhere((item) => item.id == id);
}
// Map stuff -------------------------
var details = new Map<int, Task>();
int _genId() {
return new DateTime.now().millisecondsSinceEpoch;
}
_addToMap(Task task) {
details[task.id] = task;
}
Was this helpful?
Similar Posts