Home > database >  Flutter null-safety migration - top_snackbar_flutter
Flutter null-safety migration - top_snackbar_flutter

Time:12-23

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 am using VSCode Error

I realised that the function is actually void, enter image description here 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.

  • Related