I’m using below code to update a document but getting an unknown error. I have searched through internet and did not find any explanations of this error.
<code>final db = FirebaseFirestore.instance;
String pdtRefId;
await db
.collection('product')
.where('pid', isEqualTo: pid)
.get()
.then((QuerySnapshot<Map<String, dynamic>> value) async {
print('nSuccessfully retrieved ordered product');
pdtRefId = value.docs.first.id;
print('npdtRefId = $pdtRefId');
if (pdtRefId.isNotEmpty) {
try {
print('Condition met to update, trying now!'); // --> PRINT STATEMENTS IN CONSOLE TILL HERE
await db.collection('product').doc(pdtRefId).update({"inProd": inProd}); // --> CODE STUCKS HERE
print('nUpdate done!!!');
ref.invalidate(
FetchProductsProvider(productId: null, clientId: null, inProd: true));
print('nInvalidated product provider with inProd: true, awaiting updated view');
await future;
} on FirebaseException catch (error) {
Utils.showSnackBar(error.message);
}
}
});
</code>
<code>final db = FirebaseFirestore.instance;
String pdtRefId;
await db
.collection('product')
.where('pid', isEqualTo: pid)
.get()
.then((QuerySnapshot<Map<String, dynamic>> value) async {
print('nSuccessfully retrieved ordered product');
pdtRefId = value.docs.first.id;
print('npdtRefId = $pdtRefId');
if (pdtRefId.isNotEmpty) {
try {
print('Condition met to update, trying now!'); // --> PRINT STATEMENTS IN CONSOLE TILL HERE
await db.collection('product').doc(pdtRefId).update({"inProd": inProd}); // --> CODE STUCKS HERE
print('nUpdate done!!!');
ref.invalidate(
FetchProductsProvider(productId: null, clientId: null, inProd: true));
print('nInvalidated product provider with inProd: true, awaiting updated view');
await future;
} on FirebaseException catch (error) {
Utils.showSnackBar(error.message);
}
}
});
</code>
final db = FirebaseFirestore.instance;
String pdtRefId;
await db
.collection('product')
.where('pid', isEqualTo: pid)
.get()
.then((QuerySnapshot<Map<String, dynamic>> value) async {
print('nSuccessfully retrieved ordered product');
pdtRefId = value.docs.first.id;
print('npdtRefId = $pdtRefId');
if (pdtRefId.isNotEmpty) {
try {
print('Condition met to update, trying now!'); // --> PRINT STATEMENTS IN CONSOLE TILL HERE
await db.collection('product').doc(pdtRefId).update({"inProd": inProd}); // --> CODE STUCKS HERE
print('nUpdate done!!!');
ref.invalidate(
FetchProductsProvider(productId: null, clientId: null, inProd: true));
print('nInvalidated product provider with inProd: true, awaiting updated view');
await future;
} on FirebaseException catch (error) {
Utils.showSnackBar(error.message);
}
}
});
When I run await db.collection('product').doc(pdtRefId).update({"inProd": inProd});
with hardcoded values separately, below error is shown in console.
<code>Error
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 329:10 createErrorWithStack
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 265:28 _throw
dart-sdk/lib/core/errors.dart 120:5 throwWithStackTrace
dart-sdk/lib/async/zone.dart 1386:11 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7 <fn>
</code>
<code>Error
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 329:10 createErrorWithStack
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 265:28 _throw
dart-sdk/lib/core/errors.dart 120:5 throwWithStackTrace
dart-sdk/lib/async/zone.dart 1386:11 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7 <fn>
</code>
Error
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 329:10 createErrorWithStack
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 265:28 _throw
dart-sdk/lib/core/errors.dart 120:5 throwWithStackTrace
dart-sdk/lib/async/zone.dart 1386:11 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7 <fn>