我正在尝试使用 Bloc,但我的 BlocProvider 返回错误:
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'.
Run Code Online (Sandbox Code Playgroud)
我找不到任何关于解决这个问题的地方。
这是我正在使用的代码
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(),
),
);
} …
Run Code Online (Sandbox Code Playgroud)