Group Group Group Group Group Group Group Group Group

Whatis the meaning of the double question mark when we are getting data from the future builder


Someone to explain to me the logic behind the double question marks when we are getting data from our future to build the grid view.

@sheldoni the double question marks operator means if null

So if snapshot.data is null, return an empty list.

A more complete answer is that the recipes parameter gets snapshot.data. However, the ?? signifies that if snapshot.data is null, use whatever follows the ?? … in this case a null list … [ ]

1 Like

okay, one more question that is a little bit irrelevant. When we are building the list for our posts, i can think of how i will display the data types defines(“profileImageUrl”, “comment”, “foodPictureUrl”,“timestamp”) but how will i use the post id, i fail to see it’s usefulness?

You will use it in later chapters, when you’ll store data locally via sqlite.

1 Like

@sheldoni the post id is not used in this chapter, but here’s an example of when the post id would be useful.

Let say you have a list of posts similar to Facebook. You can edit or delete your post. You can use the postId as the widget’s Key. The key is important to preserve state when moving in your widget tree. For example when you delete a post, which post will you delete or without knowing the key?

@sheldoni … in all my other programming projects going back to the 1970’s, I always made it a practice to put in some sort of unique ID in any system I built … even if I didn’t need one at the time. Because, invariably, I found I needed one. If there wasn’t one at the beginning of the project, I would be tempted to try to figure out work-arounds to not having one … work-arounds that were never quite right. So, it’s just better to build them into every single data structure.

Later on in this course, I suspect we’ll use the uuid package to generate unique IDs.

2 Likes