'why my circularProgressIndicator having strange behavior when async function called?

Im calling a function to get data from Excel file and upload it to my Firestore as following

            floatingActionButton: FloatingActionButton(onPressed: () async {

            Utils.showLoading(context);

            await FireStoreServices.bulkUploadFromExcelToFireStore(
                collectionName: 'test',
                fileName: 'test',
                sheetName: 'test');
            Navigator.pop(context);

          }),

the problem is my Progress loading indicator not working as expected in this case (not spinning only shows and freeze until the function complete after that its popped) loading indicator not spinning

i tried to replace the awaited function 'bulkUploadFromExcelToFireStore' with Future.delayed and it worked as expected

  await Future.delayed(const Duration(seconds: 3), () {});

loading indicator spinning and working as expected

what might be the problem ?

here is the code of bulkUploadFromExcelToFireStore function

  static Future bulkUploadFromExcelToFireStore(
  {required String fileName,
  required String sheetName,
  required String collectionName}) async {
try {
  final rowsData = await Utils.readExcelFileData(
      excelFilePath: fileName, sheetName: sheetName);
  rowsData.removeAt(0);
  
  for (var row in rowsData) {
    firebaseFirestore.collection(collectionName).doc(row[0]).set(data, SetOptions(merge: true));
  }
} catch (e) {
  print('Cached ERROR MESSAGE = = = = ${e.toString()}');
}


Solution 1:[1]

I added some validations inside your function to check for possible failures.

It would also be interesting to validate a failure warning and terminate the Progression Indication initialization.

static Future<String> bulkUploadFromExcelToFireStore({required String fileName, required String sheetName,required String collectionName}) async {
 try {
  final rowsData = await Utils.readExcelFileData(excelFilePath: fileName, sheetName: sheetName);
  rowsData.removeAt(0);
    
  if(rowsData.length == 0) {
   return "No Items!";
  } else {
   for (var row in rowsData) {
    firebaseFirestore?.collection(collectionName)?.doc(row[0])?.set(data, SetOptions(merge: true));
   }
    
   return "Item allocated!";
  }
 } catch (e) {
  return e.toString();
 }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jose Augusto de Aquino