So I want to take out the first letter in the username, that's inside users, for every single list view.builder cell!
My problem is that I can't find any good way to serialize son that has a list of objects inside it and it has become a real problem!
For example we will have a listview with all the projects like this one, then display the names of the members inside every cell. Like in this case: The name will be: "test med teacher chat", and the members will be: "hugo", and "studentone"!
This is what I am thinking but the letter being the first letter of every users username!
JSON:
[
{
"id": 81,
"users": [
{
"username": "hugo",
"fullname": "Hugo Johnsson"
},
{
"username": "studentone",
"fullname": "Student One"
}
],
"title": "test med teacher chat",
"description": "This project does not have a description.",
"subject": "No subject",
"deadline": "2019-01-06",
"days_left": "98 days ago",
"overview_requests": [
{
"id": 28,
"user": {
"username": "hugo",
"fullname": "Hugo Johnsson"
},
"group": 81
}
]
},
FUTURE:
Future<List<Project>> _getProjects() async {
var data = await http.get(
"http://studieplaneraren.pythonanywhere.com/api/projects/${UserLog().Username}/?format=json");
var jsonData = json.decode(data.body); //an array of json objects
List<Project> allProjects = [];
for (var JData in jsonData) {
Project project = Project(
JData["id"],
JData["title"],
JData["description"],
JData["deadline"],
JData["subject"],
JData["days_left"],
JData["users"]);
allProjects.add(project);
}
return allProjects;
}
DEFINING:
class Project {
final int id;
final String title;
final String description;
final String deadline;
final String subject;
final String days_left;
final List users;
Project(
this.id,
this.title,
this.description,
this.deadline,
this.subject,
this.days_left,
this.users
);
}