flutter bloc . what is wrong android studio no error but when i run project

Hazem El-masrey

Exception caught by widgets library:

The following ProviderNotFoundException was thrown building _InheritedProviderScope<AppCubit?>(value: <not yet loaded>):
Error: Could not find the correct Provider<StateStreamable<Object?>> above this BlocConsumer<StateStreamable<Object?>, Object?> Widget

This happens because you used a BuildContext that does not include the provider of your choice. There are a few common scenarios:

  • You added a new provider in your main.dart and performed a hot-reload. To fix, perform a hot-restart.

  • The provider you are trying to read is in a different route.

    Providers are "scoped". So if you insert of provider inside a route, then other routes will not be able to access that provider.

  • You used a BuildContext that is an ancestor of the provider you are trying to read.

    Make sure that BlocConsumer<StateStreamable<Object?>, Object?> is under your MultiProvider/Provider<StateStreamable<Object?>>. This usually happens when you are creating a provider and trying to read it immediately.

    For example, instead of:

    Widget build(BuildContext context) {
      return Provider<Example>(
        create: (_) => Example(),
        // Will throw a ProviderNotFoundError, because `context` is associated
        // to the widget that is the parent of `Provider<Example>`
        child: Text(context.watch<Example>().toString()),
      );
    }
    

    consider using builder like so:

    Widget build(BuildContext context) {
      return Provider<Example>(
        create: (_) => Example(),
        // we use `builder` to obtain a new `BuildContext` that has access to the provider
        builder: (context, child) {
          // No longer throws
          return Text(context.watch<Example>().toString());
        }
      );
    }
    

i what is wrong try too make blocprovider

Rahul

You are using context.read or BlocProvider.of(context) on the same context which you used to define BlocProvider/MultiBlocProvider.

Only the child contexts have knowledge about the AppCubit, you should wrap the child of BlocProvider/MultiBlocProvider inside a LayoutBuilder widget. Rest will remain same. Your app will work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Android - Getting error when i run project in android studio

I am new to Flutter, I try to run my project on Android Studio but I get an error in the console like:

i have a problem in my flutter App when project run in android studio

This Error will be shown when I'll try to run flutter project

missing android.jar when I try to run flutter project

What happens after I run rebuild project in Android Studio?

Error when debugging flutter project in android studio with Memu play emulator

Cant run flutter project in android studio

Problem with android Studio with run a Flutter project

Error when I tried to run flutter doctor --android-licenses

My flutter project splashscreen is freezing when I run the project maybe due to firebase error in the code

error when i try to run app on emulator android studio

I am getting this error when i run my flutter project on ios simulator:-ProcessException: Process timed out:

I have problem to run flutter in android studio

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'. These error comes when I run flutter project in emulator

How to prevent Android Monitor from automatically opening when I run a project in Android Studio?

BlackBerry Simulator doesn't show when i run android project in android studio?

Flutter: can not create flutter project or run fluter project in Android studio. (flutter works fine)

My app is crashing in android studio, and I cannot figure out what's wrong when looking at my logs

Why does Android Studio not deploy my latest changes to my device when I run my project?

Error when running project in Android Studio

What is the minumun version to run firebase in a flutter project for iOS and Android?

Error when run Android studio IDE

Adapter uses wrong layout when run in android studio

Flutter Pub Get Error when trying to run some old project

What wrong with my code because there is no error but I cant run it?

I am getting error like this, when I create new project in Android Studio

Why i get build error when i try to open my android studio project?

what is wrong in this code? when i run it just shows 0 as the result