Home > OS >  Error: Android studio Flutter BlocBuilder builder not detecting return statement from a switch case
Error: Android studio Flutter BlocBuilder builder not detecting return statement from a switch case

Time:02-02

The switch-case statement from a flutter blocbuilder is not recognising the return statement. I dont understand why this is happening.

The body might complete normally, causing 'null' to be returned, but the return type, 'Widget', is a potentially non-nullable type. (Documentation) Try adding either a return or a throw statement at the end.

This is the code

             WelcomeScreenNavigationState>(
           builder: (context, state) { <= error appears after this opening bracket
             switch (state.runtimeType) {
               case OnSignInScreenState:
                 return const SignInScreen();
               case OnSignUpScreenState:
                 return const SignUpScreen();
               default:
                 const SignInScreen();
                 break;
             }
           },
         ), 

Flutter doctor returns this:

 flutter doctor -v                
[√] Flutter (Channel stable, 3.3.10, on Microsoft Windows [Version 10.0.22621.1105],
    locale en-US)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)

[√] Chrome - develop for the web

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.4)

[!] Android Studio (version 2022.1)
    • Android Studio at
      C:\Users\user\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\221.6008.13.2
      211.9477386
    • Flutter plugin version 71.2.4
    • Dart plugin version 221.6096
    X Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[√] VS Code

[√] Connected device (3 available)        

[√] HTTP Host Availability

! Doctor found issues in 1 category.

If I check for Java I get this:

java -v Unrecognized option: -v Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. PS C:\Users\user> java --version java 19.0.2 2023-01-17 Java(TM) SE Runtime Environment (build 19.0.2 7-44) Java HotSpot(TM) 64-Bit Server VM (build 19.0.2 7-44, mixed mode, sharing)

CodePudding user response:

In default state you do not add return before "const SingInScreen();"

  • Related