flutter - This function has a return type of 'Widget', but doesn't end with a return statement. Build widget returning error - TagMerge
2This function has a return type of 'Widget', but doesn't end with a return statement. Build widget returning errorThis function has a return type of 'Widget', but doesn't end with a return statement. Build widget returning error

This function has a return type of 'Widget', but doesn't end with a return statement. Build widget returning error

Asked 1 years ago
1
2 answers

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.

Source: link

0

Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      builder: (_) => UserRepository.instance(),
      child: Consumer(
        builder: (context, UserRepository user, _) {
          switch (user.status) {
            case Status.Uninitialized:
              return Splash();
            case Status.Unauthenticated:
            case Status.Authenticating:
              return LoginPage();
            case Status.Authenticated:
              return UserInfoPage(user: user.user);
          }
          //Add return statement here.
          return LoginPage();
        },
      ),
    );
  }

Source: link

Recent Questions on flutter

    Programming Languages