小编Che*_*133的帖子

未定义方法“BlocProvider”

我正在尝试使用 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)

provider dart flutter bloc

3
推荐指数
1
解决办法
3654
查看次数

标签 统计

bloc ×1

dart ×1

flutter ×1

provider ×1