DocumentLoadFailure.fromMap constructor

DocumentLoadFailure.fromMap(
  1. Object? arguments
)

Builds a DocumentLoadFailure from a platform-channel payload.

Tolerates a missing or malformed map: anything unusable becomes null, and message falls back to type and then to a generic description, so a native-side regression degrades the detail rather than dropping the failure (which is the bug this callback exists to fix).

Implementation

factory DocumentLoadFailure.fromMap(Object? arguments) {
  final map = arguments is Map ? arguments : const <Object?, Object?>{};

  String? nonEmpty(Object? value) {
    final string = value is String ? value.trim() : null;
    return (string == null || string.isEmpty) ? null : string;
  }

  final type = nonEmpty(map['type']);
  final code = nonEmpty(map['code']);

  return DocumentLoadFailure(
    message: nonEmpty(map['message']) ?? type ?? 'Document failed to load.',
    type: type,
    code: code,
  );
}