@@ -149,10 +149,10 @@ class FirestoreAPIProvider extends APIProvider with LiveAPIProvider {
149
149
} else if (result is DocumentReference ) {
150
150
// Handle DocumentReference for 'add' operations
151
151
body = {'id' : result.id, 'path' : result.path};
152
- } else if (result == null ) {
152
+ } else if (result is DocumentSnapshot ) {
153
153
// Handle void results for 'set', 'update', and 'delete' operations
154
- body = {'message ' : 'Operation completed successfully' };
155
- } else {
154
+ body = {'document ' : getDocument (result) };
155
+ } else if (result == null ) {
156
156
// Fallback for unexpected types, you might not need this, but it's here just in case
157
157
body = {'message' : 'Unknown response type' , 'details' : result.toString ()};
158
158
}
@@ -167,15 +167,17 @@ class FirestoreAPIProvider extends APIProvider with LiveAPIProvider {
167
167
168
168
List <Map <String , dynamic >> getDocuments (QuerySnapshot snapshot) {
169
169
return snapshot.docs.map ((doc) {
170
- // Create a new map from the document data
171
- Map <String , dynamic > data =
172
- convertFirestoreTypes (doc.data () as Map <String , dynamic >);
173
- // Add the document ID under a reserved/special key
174
- data['_documentId' ] = doc.id;
175
- return data;
170
+ return getDocument (doc);
176
171
}).toList ();
177
172
}
178
-
173
+ Map <String , dynamic > getDocument (DocumentSnapshot doc) {
174
+ // Create a new map from the document data
175
+ Map <String , dynamic > data =
176
+ convertFirestoreTypes (doc.data () as Map <String , dynamic >);
177
+ // Add the document ID under a reserved/special key
178
+ data['_documentId' ] = doc.id;
179
+ return data;
180
+ }
179
181
Map <String , dynamic > convertFirestoreTypes (Map <String , dynamic > input) {
180
182
Map <String , dynamic > convert (Map <String , dynamic > map) {
181
183
final Map <String , dynamic > newMap = {};
@@ -214,7 +216,9 @@ class FirestoreAPIProvider extends APIProvider with LiveAPIProvider {
214
216
return item; // Return the item unchanged if it's not a Map, GeoPoint, or Timestamp
215
217
}
216
218
}).toList ();
217
- } else {
219
+ } else if (value is DocumentSnapshot ){
220
+ newMap[key] = getDocument (value);
221
+ } else {
218
222
// For all other types, just copy the value
219
223
newMap[key] = value;
220
224
}
0 commit comments