Pending vsync Event while looping through a list

I have been working on a service industry app that allows user to book rooms in a hotel, order foods etc. online. After the user has selected the rooms he wants to book, and the dates for it, he needs to make a payment(Using Online Banking and stuff). Right now I am using the virtual RazorPay simulator for the payment part.

Since there is a Future attached with the payment, if the Payment is successful, it directs the app to a new Page. In the new page I have a code to update all the selected rooms to be “Not Available” in the Firebase. Here is the code:

Widget _updateRoomStatus() {

return ScopedModelDescendant<MainModel>(
    builder: (BuildContext context, Widget child, MainModel model) {
    Widget content = Center(child: Text("Processing"));
    List<int> roomIndex = widget.model.productsRoomIds; //Retrieves the List of rooms that the user has just booked ----------------    Position X

        roomIndex.forEach((element) => (element, false)//This function updates the passed parameter in the firebase and false means unavailable

  if (!model.isHouseLoading)  //Position Z
    content = Center(child: Text('Payement Done'));
    content = Center(child: CircularProgressIndicator());

  return content;

The strange thing is compiler reaches position x, completely skips Y loop, then executes z and thereafter. The error shown is only this line :
Already have a pending vsync event. There should only be one at a time.

And the problem is not in the updateRoom function. The compiler doesnt even enter the loop. I have looked everywhere, havent found a solution. For any help I would be grateful.

Okay so this is just a guess and don;t ask me how if this works because I really don’t know :stuck_out_tongue: but I have faced issues with the forEach function in the past. It behaves weirdly and unexpectedly.
Try replacing it with a for loop.

for(int i =0; i< roomIndex.length; i++) {
// code

I also noticed that your function call looks incorrect, have you cut the name to place the code here or something? Please check that as well.