Che*_*133 3 provider dart flutter bloc
我正在尝试使用 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)
并在 pub.yaml 中添加了 flutter_bloc
bloc: ^8.1.0
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?为什么 BlocProvider 无法被识别?
先谢谢您的帮助。
归档时间: |
|
查看次数: |
3654 次 |
最近记录: |