Skip to content

Adding null safety #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 65 additions & 76 deletions lib/models/note.dart
Original file line number Diff line number Diff line change
@@ -1,78 +1,67 @@

class Note {

int _id;
String _title;
String _description;
String _date;
int _priority;

Note(this._title, this._date, this._priority, [this._description]);

Note.withId(this._id, this._title, this._date, this._priority, [this._description]);

int get id => _id;

String get title => _title;

String get description => _description;

int get priority => _priority;

String get date => _date;

set title(String newTitle) {
if (newTitle.length <= 255) {
this._title = newTitle;
}
}

set description(String newDescription) {
if (newDescription.length <= 255) {
this._description = newDescription;
}
}

set priority(int newPriority) {
if (newPriority >= 1 && newPriority <= 2) {
this._priority = newPriority;
}
}

set date(String newDate) {
this._date = newDate;
}

// Convert a Note object into a Map object
Map<String, dynamic> toMap() {

var map = Map<String, dynamic>();
if (id != null) {
map['id'] = _id;
}
map['title'] = _title;
map['description'] = _description;
map['priority'] = _priority;
map['date'] = _date;

return map;
}

// Extract a Note object from a Map object
Note.fromMapObject(Map<String, dynamic> map) {
this._id = map['id'];
this._title = map['title'];
this._description = map['description'];
this._priority = map['priority'];
this._date = map['date'];
}
int? _id;
String? _title;
String? _description;
String? _date;
int? _priority;

// default constructor
Note(this._title, this._date, this._priority, [this._description]);

// Named constructor with ID
Note.withId(this._id, this._title, this._date, this._priority,
[this._description]);

// getters
int? get id => _id;
String? get title => _title;
String? get description => _description;
String? get date => _date;
int? get priority => _priority;

// setters
set title(String? newTitle) {
if (newTitle!.length <= 255) {
this._title = newTitle;
}
}

set description(String? newDescription) {
if (newDescription!.length <= 255) {
this._description = newDescription;
}
}

set priority(int? newPriority) {
if (newPriority! >= 1 && newPriority <= 2) {
this._priority = newPriority;
}
}

set date(String? newDate) {
this._date = newDate;
}

// Convert a Note object into a map object
Map<String, dynamic> toMap() {
var map = Map<String, dynamic>();
if (id != null) {
map['id'] = _id;
}
map['title'] = _title;
map['description'] = _description;
map['priority'] = _priority;
map['date'] = _date;

return map;
}

// Extract a note object from a map object
Note.fromMapObject(Map<String, dynamic> map) {
this._id = map["id"];
this._title = map["title"];
this._description = map["description"];
this._priority = map["priority"];
this._date = map["date"];
}
}