I can't return a null from catchError handler of dart Future. I can do it using try catch but I need to use then catchError.
Using try catch
Future<bool?> test() async {
try {
return await someFuture();
} catch (e) {
return null;
}
}
// Works without error
But when using then catchError
Future<bool?> test() {
return someFuture().catchError((e) {
return null;
});
}
// Error: A value of type 'Null' can't be returned by the 'onError' handler because it must be assignable to 'FutureOr<bool>'
How do I return null if I encounter some error using then and catchError?