anexar method

Future<void> anexar(
  1. String caminho,
  2. String nome,
  3. Uint8List bytes
)

Envia o arquivo bytes (de nome nome) como a mídia caminho do bloco.

Implementation

Future<void> anexar(String caminho, String nome, Uint8List bytes) async {
  if (isClosed) return;
  final problema = problemasDaPartitura(nome, bytes);
  if (problema != null) {
    _avisar(problema);
    return;
  }
  emit(state.copyWith(enviando: caminho));
  try {
    final referencia = await remote
        .enviarPartitura(profUid: profUid, nome: nome, bytes: bytes)
        .timeout(esperaMaxima);
    if (!isClosed) {
      emit(
        state.copyWith(
          midias: {
            ...state.midias,
            caminho: MidiaDoBloco(caminho: caminho, referencia: referencia),
          },
        ),
      );
    }
  } on TimeoutException {
    _avisar('Sem conexão agora: o arquivo não foi enviado. Tente de novo.');
  } on Object catch (e) {
    _avisar('Não consegui enviar o arquivo: $e');
  } finally {
    if (!isClosed) emit(state.copyWith(enviando: ''));
  }
}