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
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.
CodePudding user response:
Try using flutter_bloc package instead
It has the additional classes such as BlocProvider