createAndSendResult method

  1. @override
void createAndSendResult()
override

This method should be implemented in all the Widgets which are producing an RPResult object.

Implementation

@override
void createAndSendResult() {
  // Transforming the consent document from the string values in the objects
  // to the translation the users were presented with
  List<RPConsentSection> translatedConsentSections = [];
  RPLocalizations? locale = RPLocalizations.of(context);
  for (RPConsentSection section in widget.step.consentDocument.sections) {
    List<RPDataTypeSection> translatedDataTypeSections = [];
    if ([
          RPConsentSectionType.UserDataCollection,
          RPConsentSectionType.PassiveDataCollection
        ].contains(section.type) &&
        section.dataTypes != null) {
      for (RPDataTypeSection dataTypeSection in section.dataTypes!) {
        translatedDataTypeSections.add(
          RPDataTypeSection(
            dataName: locale?.translate(dataTypeSection.dataName) ??
                dataTypeSection.dataName,
            dataInformation:
                locale?.translate(dataTypeSection.dataInformation) ??
                    dataTypeSection.dataInformation,
          ),
        );
      }
    }
    translatedConsentSections.add(RPConsentSection(
      title: locale?.translate(section.title) ?? section.title,
      summary: section.summary != null
          ? locale?.translate(section.summary!) ?? section.summary
          : null,
      content: section.content != null
          ? locale?.translate(section.content!) ?? section.content
          : null,
      type: section.type,
      dataTypes: (translatedDataTypeSections.isNotEmpty)
          ? translatedDataTypeSections
          : null,
    ));
  }
  RPConsentDocument translatedConsentDocument = RPConsentDocument(
      title: locale?.translate(widget.step.consentDocument.title) ??
          widget.step.consentDocument.title,
      sections: translatedConsentSections);

  for (RPConsentSignature signature
      in widget.step.consentDocument.signatures) {
    translatedConsentDocument.addSignature(signature);
  }

  // Creating the result object
  consentSignatureResult = RPConsentSignatureResult(
      identifier: widget.step.identifier,
      consentDocument: translatedConsentDocument,
      signature: signatureResult)
    ..endDate = DateTime.now();

  blocTask.sendStepResult(consentSignatureResult!);
}