I did a dart migrate to update my project to null-safety. I have several issues to sort as it was an old project. However, one thing is stumping me a lot and unable to figure out a way.
I realised that the function is actually void, but I need to return a Widget. I have tried adding try and a catch block but did nothing.
Widget showTopBarErrorWidget({required context, String? messageArg}) {
try {
showTopSnackBar(
context,
CustomSnackBar.error(
message: messageArg ??
"Error while starting the session Plans. Please try again",
),
displayDuration: Duration(seconds: 5));
} on Exception catch (e) {
print(e);
rethrow;
}
}
CodePudding user response:
As h8moss said
you don't have anything to return from showTopBarErrorWidget
so remove the Widget return type and make it void
void showTopBarErrorWidget({required context, String? messageArg}) {
The showTopSnackBar
will execute anyway, no need to return it or something.