diff --git a/lib/notion/general/property.dart b/lib/notion/general/property.dart index e1cb3f5..fb18fa1 100644 --- a/lib/notion/general/property.dart +++ b/lib/notion/general/property.dart @@ -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(); } @@ -279,3 +282,31 @@ class MultiSelectOption { static List fromListJson(List 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 toJson() { + Map json = {'type': this.strType}; + + if (this.id != null) { + json['id'] = this.id; + } + + json[this.strType] = this.value; + + return json; + } + + NumberProp.fromJson(Map json) + : this.value = json['number'], + super(id: json['id']); +} + diff --git a/test/property_test.dart b/test/property_test.dart index e69b69e..7630944 100644 --- a/test/property_test.dart +++ b/test/property_test.dart @@ -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', () {