decode method

  1. @override
List<T>? decode(
  1. String? base64String
)
override

Decodes a Base64-encoded String into a list of elements of type T.

Returns null if the input base64String is null or if the decoded byte length is not a multiple of byteSize.

Implementation

@override

/// Decodes a Base64-encoded [String] into a list of elements of type [T].
///
/// Returns `null` if the input [base64String] is `null` or if the
/// decoded byte length is not a multiple of [byteSize].
List<T>? decode(String? base64String) {
  if (base64String == null) return null;
  try {
    final bytes = base64Decode(base64String);
    if (bytes.length % byteSize != 0) return null;

    final result = <T>[];
    final byteData = ByteData.sublistView(bytes);
    for (var i = 0; i < byteData.lengthInBytes; i += byteSize) {
      result.add(read(byteData, i));
    }
    return result;
  } catch (_) {
    return null;
  }
}