@@ -5,50 +5,54 @@ abstract class ParseBase {
55 Map _objectData = Map <String , dynamic >();
66
77 /// Returns [String] objectId
8- String get objectId => _objectData[ 'objectId' ] ;
9- set objectId (String objectId) => _objectData[ objectId] ;
8+ String get objectId => get < String >( OBJECT_ID ) ;
9+ set objectId (String objectId) => set < String >( OBJECT_ID , objectId) ;
1010
1111 /// Returns [DateTime] createdAt
12- DateTime get createdAt => stringToDateTime (_objectData['createdAt' ]);
13- set createdAt (DateTime createdAt) =>
14- _objectData['createdAt' ] = dateTimeToString (createdAt);
12+ DateTime get createdAt => stringToDateTime (get <String >(CREATED_AT ));
13+ set createdAt (DateTime createdAt) => set <String >(CREATED_AT , dateTimeToString (createdAt));
1514
1615 /// Returns [DateTime] updatedAt
17- DateTime get updatedAt => stringToDateTime (_objectData['updatedAt' ]);
18- set updatedAt (DateTime updatedAt) =>
19- _objectData['updatedAt' ] = dateTimeToString (updatedAt);
16+ DateTime get updatedAt => stringToDateTime (get <String >(UPDATED_AT ));
17+ set updatedAt (DateTime updatedAt) => set <String >(UPDATED_AT , dateTimeToString (updatedAt));
2018
2119 /// Converts object to [String] in JSON format
22- @protected
23- toJson () => JsonEncoder ().convert (getObjectData ());
20+ @protected String toJson () {
21+ return JsonEncoder ().convert (getObjectData ());
22+ }
2423
2524 /// Creates a copy of this class
2625 @protected
27- copy () => JsonDecoder ().convert (fromJson ( getObjectData ()));
26+ copy () => fromJson ( JsonDecoder ().convert (toJson ()));
2827
2928 /// Sets all the objects variables
3029 @protected
31- setObjectData (Map objectData) => _objectData = objectData;
30+ setObjectData (Map objectData) {
31+ _objectData = objectData;
32+ }
3233
3334 /// Returns the objects variables
3435 @protected
35- getObjectData () => _objectData;
36+ getObjectData () {
37+ return _objectData;
38+ }
3639
3740 /// Saves in storage
3841 @protected
3942 saveInStorage (String key) async {
4043 await ParseCoreData ().getStore ().setString (key, toJson ());
4144 }
4245
43- @protected
44- fromJson (Map objectData) {
45- if (_objectData == null ) _objectData = Map ();
46- _objectData.addAll (objectData);
47- }
46+ /// Needs overriding to create deep copy affect
47+ @override
48+ fromJson (Map objectData) {}
4849
49- /// Create a new variable for this object, [bool] forceUpdate is always true,
50- /// if unsure as to whether an item is needed or not, set to false
51- set (String key, dynamic value, {bool forceUpdate: true }) {
50+ /// Sets type [T] from objectData
51+ ///
52+ /// To set an int, call setType<int> and an int will be saved
53+ /// [bool] forceUpdate is always true, if unsure as to whether an item is
54+ /// needed or not, set to false
55+ set <T >(String key, T value, {bool forceUpdate: true }) {
5256 if (value != null ) {
5357 if (getObjectData ().containsKey (key)) {
5458 if (forceUpdate) getObjectData ()[key] = value;
@@ -58,10 +62,18 @@ abstract class ParseBase {
5862 }
5963 }
6064
61- /// Returns a variable from the objectData
62- get (String key, {dynamic defaultValue, bool fromServer}) {
65+ /// Gets type [T] from objectData
66+ ///
67+ /// Returns null or [defaultValue] if provided. To get an int, call
68+ /// getType<int> and an int will be returned, null, or a defaultValue if
69+ /// provided
70+ get <T >(String key, {T defaultValue}) {
6371 if (getObjectData ().containsKey (key)) {
64- return getObjectData ()[key];
72+ if (T != null && getObjectData ()[key] is T ) {
73+ return getObjectData ()[key] as T ;
74+ } else {
75+ return getObjectData ()[key];
76+ }
6577 } else {
6678 return defaultValue;
6779 }
@@ -72,7 +84,8 @@ abstract class ParseBase {
7284 /// Replicates Android SDK pin process and saves object to storage
7385 pin () async {
7486 if (objectId != null ) {
75- await ParseCoreData ().getStore ().setString (objectId, toJson ());
87+ var itemToSave = toJson ();
88+ await ParseCoreData ().getStore ().setString (objectId, itemToSave);
7689 return true ;
7790 } else {
7891 return false ;
@@ -84,8 +97,9 @@ abstract class ParseBase {
8497 /// Replicates Android SDK pin process and saves object to storage
8598 unpin () async {
8699 if (objectId != null ) {
87- var itemToSave = await ParseCoreData ().getStore ().setString (objectId, null );
88- return true ;
100+ var itemToSave = await ParseCoreData ().getStore ().setString (
101+ objectId, null );
102+ if (itemToSave) return true ;
89103 } else {
90104 return false ;
91105 }
@@ -94,9 +108,9 @@ abstract class ParseBase {
94108 /// Saves item to simple key pair value storage
95109 ///
96110 /// Replicates Android SDK pin process and saves object to storage
97- fromPin () async {
111+ fromPin (String objectId) {
98112 if (objectId != null ) {
99- var itemFromStore = await ParseCoreData ().getStore ().getString (objectId);
113+ var itemFromStore = ParseCoreData ().getStore ().getString (objectId);
100114
101115 if (itemFromStore != null ) {
102116 Map <String , dynamic > itemFromStoreMap = JsonDecoder ().convert (
0 commit comments