Nullable Extension
Check nullable values before work with them.let:
Check nullable variableFuture<void> login(dynamic credentials) async {
final LoginResponse? response = await authRepository.login(credentials)
// without extension:
if (response != null) {
// do some logic
print(response.user);
}
// using extension:
response?.let((LoginResponse it) {
print(it.user);
});
}
filterNotNull:
Convert array of nullable objects to array if non-nullablefinal list = [1, null, 4, 2, null];
print(list.filterNotNull); // [1, 4, 2]