Skip to content
Open
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions lib/notion/general/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class Property {
MultiSelectProp multi = MultiSelectProp.fromJson(json,
subfield: contentIsList ? null : 'options');
return multi;
} else if (type == PropertiesTypes.Number) {
NumberProp number = NumberProp.fromJson(json);
return number;
} else {
return Property();
}
Expand Down Expand Up @@ -279,3 +282,31 @@ class MultiSelectOption {
static List<MultiSelectOption> fromListJson(List<dynamic> options) =>
options.map((e) => MultiSelectOption.fromJson(e)).toList();
}

/// A representation of a number property for any Notion object.
class NumberProp extends Property {
num? value;

@override
final PropertiesTypes type = PropertiesTypes.Number;

NumberProp(this.value);

@override
Map<String, dynamic> toJson() {
Map<String, dynamic> json = {'type': this.strType};

if (this.id != null) {
json['id'] = this.id;
}

json[this.strType] = this.value;

return json;
}

NumberProp.fromJson(Map<String, dynamic> json)
: this.value = json['number'],
super(id: json['id']);
}

3 changes: 2 additions & 1 deletion test/property_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ void main() {
expect(json, contains('Details'));
expect(json['Details']!.isRichText, true);
expect(json, contains('Quantity'));
expect(json['Quantity']!.isNone, true);
expect(json['Quantity']!.strType, 'number');
expect(json['Quantity']!.value, 1234);
});

test('Create json from Property inherited class', () {
Expand Down