Action loop perform what is supposed to do then the hole action stop and does not continue

Hello,

i have created an action for a button that include a loop, to copy past data from a page variable (list) to a firebase document (list).

the loop is copying the list correctly and updating the documents, but the action after the loop are not beings performed in the test/run mode.

i have checked it is not an infinite loop

Regards

see code :

// Generated code for this Button Widget...
Padding(
  padding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 20),
  child: FFButtonWidget(
    onPressed: () async {
      var _shouldSetState = false;
      var confirmDialogResponse = await showDialog<bool>(
            context: context,
            builder: (alertDialogContext) {
              return AlertDialog(
                title: Text('Confirm Order'),
                content: Text('Do you approve to create this order'),
                actions: [
                  TextButton(
                    onPressed: () => Navigator.pop(alertDialogContext, false),
                    child: Text('Cancel'),
                  ),
                  TextButton(
                    onPressed: () => Navigator.pop(alertDialogContext, true),
                    child: Text('Confirm'),
                  ),
                ],
              );
            },
          ) ??
          false;
      if (confirmDialogResponse) {
        var ordersRecordReference = OrdersRecord.collection.doc();
        await ordersRecordReference.set(createOrdersRecordData(
          orderNumber: _model.orderRef?.toString(),
          createdAt: getCurrentTimestamp,
          totalPrice: _model.total,
          client: _model.clientValue,
          clientEmail: createOrderClientsRecordList
              .sortedList((e) => e.displayName)
              .where((e) => e.displayName == _model.clientValue)
              .toList()
              .first
              .email,
        ));
        _model.orderCreation = OrdersRecord.getDocumentFromData(
            createOrdersRecordData(
              orderNumber: _model.orderRef?.toString(),
              createdAt: getCurrentTimestamp,
              totalPrice: _model.total,
              client: _model.clientValue,
              clientEmail: createOrderClientsRecordList
                  .sortedList((e) => e.displayName)
                  .where((e) => e.displayName == _model.clientValue)
                  .toList()
                  .first
                  .email,
            ),
            ordersRecordReference);
        _shouldSetState = true;
        while (_model.indextable <=
            valueOrDefault<int>(
              _model.order.length,
              0,
            )) {
          await _model.orderCreation!.reference.update({
            ...mapToFirestore(
              {
                'List_of_Article': FieldValue.arrayUnion([
                  getArticleFirestoreData(
                    updateArticleStruct(
                      _model.order[_model.indextable],
                      clearUnsetFields: false,
                    ),
                    true,
                  )
                ]),
              },
            ),
          });
          await _model.venderUID!.update({
            ...mapToFirestore(
              {
                'List_of_article': FieldValue.arrayUnion([
                  getArticleFirestoreData(
                    updateArticleStruct(
                      _model.order[_model.indextable],
                      clearUnsetFields: false,
                    ),
                    true,
                  )
                ]),
              },
            ),
          });
          _model.indextable = _model.indextable + 1;
        }
        await currentUserReference!.update({
          ...mapToFirestore(
            {
              'Last_order_Number': FieldValue.increment(1),
            },
          ),
        });
        context.pushNamed('Homepage');
      } else {
        if (_shouldSetState) setState(() {});
        return;
      }
      if (_shouldSetState) setState(() {});
    },
    text: 'Create the order',
    options: FFButtonOptions(
      height: 40,
      padding: EdgeInsetsDirectional.fromSTEB(24, 0, 24, 0),
      iconPadding: EdgeInsetsDirectional.fromSTEB(0, 0, 0, 0),
      color: FlutterFlowTheme.of(context).primary,
      textStyle: FlutterFlowTheme.of(context).titleSmall.override(
            fontFamily: 'Inter',
            color: Colors.white,
          ),
      elevation: 3,
      borderSide: BorderSide(
        color: Colors.transparent,
        width: 1,
      ),
      borderRadius: BorderRadius.circular(8),
    ),
  ),
)
2
7 replies