Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The method 'BlocProvider' isn't defined

I’m trying to to use Bloc but my BlocProvider return an error:

The method 'BlocProvider' isn't defined for the type '_MyAppState'.
Try correcting the name to the name of an existing method, or defining a method named 'BlocProvider'.

I cant find anywhere about solving this issue.

Here’s the code i’m working with

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import 'package:app_13/post_cubit.dart';
import 'package:app_13/post_view.dart';
import 'package:flutter/material.dart';
import 'package:bloc/bloc.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: BlocProvider<PostsCubit> (
        create: (context) => PostsCubit(),
        child: PostsView(),
      ),
    );
  }
}

And added flutter_bloc in pub.yaml

  bloc: ^8.1.0

What am i doing wrong? Why is BlocProvider not recognized?

Thanks in advance for the help.

>Solution :

Try using flutter_bloc package instead

It has the additional classes such as BlocProvider

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading