Async methods should return futures

Last updated: 12.09.2020 - 16:00 by Boehrsi

Any async method should wrap the expected return type in a Future, this is also valid for void methods. This way you ensure your code is understandable and future proof.

DO return Future<void>

Future<void> loadChat() async { // Good
    await dataRepository.load(chatId);
}

DON'T return just void

void loadChat() async { // Bad, as the caller doesn't know about the future
    await dataRepository.load(chatId);
}
loadChat() async { // Bad, as the caller doesn't know about the future
    await dataRepository.load(chatId);
}