flutterfirebasedart

Error: Dart exception from converted Future. Use the properties 'error' to fetch the boxed error and 'stack' to recover the stack trace


I found this error when running a firebase transaction in my flutter app:

 Error: Dart exception from converted Future. Use the properties 'error' to fetch the boxed error and 'stack' to recover the stack trace

A typical transaction as below:

 await _firestore.runTransaction<bool>(
    (transaction) async {
       ...   // things went here.
    }
 )

Solution

  • Short answer: add a try-catch block inside the async function.

    Journey: After some tinkering, I realised that the error was because the async function in the runTransaction() raised an error from it without being properly handled by using try-catch block.

    After I added a try-catch block, the problem was solved.

    await _firestore.runTransaction<bool>(
        (transaction) async {
           try {
               ...   // things went here.
           } catch (e) {
               ...   // error-handling
           }
        }
     )