TabData is a blueprint (or template) that defines how we store information about tabs, bookmarks, and history items.
Every tab, bookmark, or history item in your app is stored as a TabData object containing this information.
These are the pieces of information each TabData object holds:
? after a type (like int? or String?) means the value can be null (empty/missing).
The constructor is like a factory that builds TabData objects.
: lastAccessed = lastAccessed ?? DateTime.now() means:
??), use the current time (DateTime.now())."
When we get data from the browser API, it comes as JSON (a text format).
The fromJson method converts that JSON into a TabData object.
This is just text - we can't use it directly!
This is a proper object we can work with!
Different browser APIs send dates with different field names. Our fromJson method is smart enough to handle all of them!
The ?? operator means: "if null (missing), use this default value instead"
json['title'] ?? 'Untitled'
→ If no title, use "Untitled"
json['url'] ?? ''
→ If no URL, use empty string
json['favicon'] ?? json['favIconUrl'] ?? ''
→ Try 'favicon', then 'favIconUrl', then empty
json['isPinned'] ?? false
→ If not specified, assume not pinned
json['type'] ?? 'tab'
→ If no type, assume it's a tab
Each property has a specific type (String, bool, DateTime). This prevents errors like putting a number where text should be.
The ?? operators and multiple date field checks ensure the app doesn't crash if data is missing or in a different format.
Works with different browser APIs (Chrome, Firefox, Edge) because it handles different field names and formats.
All tab/bookmark/history data is in one place, making it easy to work with throughout the app.
Instead of messy JSON strings everywhere, we have clean objects: tab.title, tab.url, etc.
Creating TabData objects is fast, and we can easily create lists of them: List<TabData>.
Every tab, bookmark, and history item you see in the app is a TabData object.
Without TabData, we'd just have messy JSON strings everywhere!