gerar method
Gera um código. Com uma geração em curso, ou sem conta e sem Firestore, não faz nada.
Implementation
Future<void> gerar() async {
final uid = this.uid;
final remote = this.remote;
if (isClosed || uid == null || remote == null || state.gerando) return;
emit(state.copyWith(gerando: true));
try {
final convite = await remote.gerarConvite(uid).timeout(esperaMaxima);
if (!isClosed) emit(state.copyWith(convite: convite));
} on TimeoutException {
_avisar(
'Sem conexão: não deu para gerar o código. Tente quando tiver internet.',
);
} on VinculoException catch (e) {
_avisar(e.mensagem);
} on Object catch (e) {
_avisar('Não consegui gerar o código: $e');
} finally {
if (!isClosed) emit(state.copyWith(gerando: false));
}
}