I was using the following code to delete the contents of a Firestore table via Dart code:
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/supabase/supabase.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
// Set your action name, define your arguments and return parameter,
// and then add the boilerplate code using the green button on the right!
import 'package:cloud_firestore/cloud_firestore.dart';
Future<void> deleteCollection(String collectionPath) async {
debugPrint('DELETE COLLECTION I GET HERE');
final collection = FirebaseFirestore.instance.collection(collectionPath);
debugPrint('COLLECTION: $collection');
final snapshots = await collection.get();
debugPrint('SNAPSHOTS: $snapshots');
for (var doc in snapshots.docs) {
debugPrint('DOC IS: $doc');
String docReference = doc.reference;
debugPrint('Doc reference: $docReference');
await doc.reference.delete();
debugPrint('Deleted doc I get here');
}
}
Everything was working fine until today, where the following error are thrown:
dart_sdk.js:12007 Uncaught (in promise) Error
at Object.createErrorWithStack (dart_sdk.js:12007:12)
at Error._throw (dart_sdk.js:13480:18)
at Error.throwWithStackTrace (dart_sdk.js:13477:18)
at async._AsyncCallbackEntry.new.callback (dart_sdk.js:47537:18)
at Object._microtaskLoop (dart_sdk.js:47394:13)
at _startMicrotaskLoop (dart_sdk.js:47400:13)
at dart_sdk.js:43200:9
POST https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel?VER=8&database=projects%2Fprojectname%2Fdatabases%2F(default)&gsessionid=p-Q9wXAl33dnyBpFpR7rzArEPT0hhHetYwMDZ6ipKhM&SID=fdIBs7XFmR44XmeuCqGNeA&RID=70105&TYPE=terminate&zx=hpb16eatrlh5 400 (Bad Request)
Any ideas what is going on and how to fix the issue?