@@ -86,7 +86,8 @@ class ParseObject extends ParseBase implements ParseCloneable {
86
86
/// Creates a new object and saves it online
87
87
///
88
88
/// Prefer using [save] over [create]
89
- Future <ParseResponse > create ({bool allowCustomObjectId = false }) async {
89
+ Future <ParseResponse > create (
90
+ {bool allowCustomObjectId = false , dynamic context}) async {
90
91
try {
91
92
final Uri url = getSanitisedUri (_client, _path);
92
93
final String body = json.encode (toJson (
@@ -96,8 +97,17 @@ class ParseObject extends ParseBase implements ParseCloneable {
96
97
97
98
_saveChanges ();
98
99
99
- final ParseNetworkResponse result =
100
- await _client.post (url.toString (), data: body);
100
+ final Map <String , String > headers = {
101
+ keyHeaderContentType: keyHeaderContentTypeJson,
102
+ };
103
+
104
+ if (context != null ) {
105
+ headers
106
+ .addAll ({keyHeaderCloudContext: json.encode (parseEncode (context))});
107
+ }
108
+
109
+ final ParseNetworkResponse result = await _client.post (url.toString (),
110
+ data: body, options: ParseNetworkOptions (headers: headers));
101
111
102
112
final response = handleResponse <ParseObject >(
103
113
this , result, ParseApiRQ .create, _debug, parseClassName);
@@ -120,7 +130,7 @@ class ParseObject extends ParseBase implements ParseCloneable {
120
130
/// The object should hold an [objectId] in order to update it
121
131
///
122
132
/// Prefer using [save] over [update]
123
- Future <ParseResponse > update () async {
133
+ Future <ParseResponse > update ({ dynamic context} ) async {
124
134
assert (
125
135
objectId != null && (objectId? .isNotEmpty ?? false ),
126
136
"Can't update a parse object while the objectId property is null or empty" ,
@@ -133,9 +143,14 @@ class ParseObject extends ParseBase implements ParseCloneable {
133
143
_saveChanges ();
134
144
135
145
final Map <String , String > headers = {
136
- keyHeaderContentType: keyHeaderContentTypeJson
146
+ keyHeaderContentType: keyHeaderContentTypeJson,
137
147
};
138
148
149
+ if (context != null ) {
150
+ headers
151
+ .addAll ({keyHeaderCloudContext: json.encode (parseEncode (context))});
152
+ }
153
+
139
154
final ParseNetworkResponse result = await _client.put (url.toString (),
140
155
data: body, options: ParseNetworkOptions (headers: headers));
141
156
@@ -185,14 +200,14 @@ class ParseObject extends ParseBase implements ParseCloneable {
185
200
/// Its safe to call this function aging if an error occurred while saving.
186
201
///
187
202
/// Prefer using [save] over [update] and [create]
188
- Future <ParseResponse > save () async {
203
+ Future <ParseResponse > save ({ dynamic context} ) async {
189
204
final ParseResponse childrenResponse = await _saveChildren (this );
190
205
if (childrenResponse.success) {
191
206
ParseResponse ? response;
192
207
if (objectId == null ) {
193
- response = await create ();
208
+ response = await create (context : context );
194
209
} else if (_isDirty (false )) {
195
- response = await update ();
210
+ response = await update (context : context );
196
211
}
197
212
198
213
if (response != null ) {
0 commit comments