getWarningAndErrors method

  1. @override
EditorWarningAndErrorsEntity getWarningAndErrors(
  1. ID nodeID,
  2. BuildContext context
)
inherited

Implementation

@override
EditorWarningAndErrorsEntity getWarningAndErrors(
  ID nodeID,
  BuildContext context,
) {
  EditorWarningAndErrorsEntity nodeWarningAndErrors =
      EditorWarningAndErrorsEntity.clear();
  for (final e in getAttributes.entries) {
    if (e.value is WarnableClass) {
      final warnable = e.value as WarnableClass;
      final warningAndErrors = warnable.getWarningAndErrors(nodeID, context);
      final onlyRequiredWarnings = warningAndErrors.warnings
          .map((w) {
            /// If the warning is not a MissingValueWarningEntity, return it
            if (w is MissingValueWarningEntity) {
              if (type == NType.image) {
                return MissingValueWarningEntity(
                  nodeID: nodeID,
                  message: 'Image value is empty',
                );
              }
              if (requiredAttributes.contains(e.key)) {
                return w;
              }
              return null;
            }

            /// If the warning is a MissingValueWarningEntity, check if the required attributes contains the key
            if (requiredAttributes.contains(e.key)) {
              return w;
            }
            return null;
          })
          .whereNotNull()
          .toList();
      final onlyRequiredErrors = warningAndErrors.errors
          .map((w) {
            if (w is MissingVariableWarningEntity) {
              if (type == NType.listView) {
                return null;
              }
            }
            if (requiredAttributes.contains(e.key)) {
              return w;
            }
            return null;
          })
          .whereNotNull()
          .toList();
      nodeWarningAndErrors = nodeWarningAndErrors.copyWith(warnings: [
        ...nodeWarningAndErrors.warnings,
        ...onlyRequiredWarnings,
      ], errors: [
        ...nodeWarningAndErrors.errors,
        ...onlyRequiredErrors,
      ]);
    }
  }
  return nodeWarningAndErrors;
}