I have the following warning => This function has a return type of 'Widget', but doesn't end with a return statement. (Documentation) Try adding a return statement, or changing the return type to 'void'.
When I add the return statement in the void function, I encounter the following error:
A value of type 'void' can't be returned from the method 'build' because it has a return type of 'Widget'. (Documentation)
[...]else if (state is CancelOrderErrorState) {
showCoreMessageSnackBar(
CoreMessageWidget.error(title: strings.cancelOrderFailureText.localize(context)),
autoDismiss: true,
);
[...]
Can someone help me fix this return statement?
CodePudding user response:
To expand your code a little bit:
@override
Widget build(BuildContext context) {
...
else if (state is CancelOrderErrorState) {
showCoreMessageSnackBar(
CoreMessageWidget.error(title: strings.cancelOrderFailureText.localize(context)),
autoDismiss: true,
);
return Container(); //<--add this
}
...
}
You HAVE to return what the method is defined to return which is a Widget. Since the build method is overridden you can't change the return type. Sometimes returning something simple is all you can do.