【问题标题】:How to get BlockProvider recognized in my flutter project?如何在我的颤振项目中识别 BlockProvider?
【发布时间】:2019-11-17 07:07:16
【问题描述】:

所以,我最近正在尝试 BLOCK 模式,并且在像这样在我的 pubsec yaml 文件中导入了 block_pattern 包之后

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  bloc_pattern: ^2.2.2+3
  rxdart:

现在,我建立了一个名为 CartListBloc 的类作为 BlockBase 的扩展

class CartListBloc extends BlocBase {
  CartListBloc();
  //etc...

当我尝试将 BlockProvider 放入主类时,尽管导入正确,但 IDE 无法识别它。

import 'package:bloc_pattern/bloc_pattern.dart';
import 'bloc/cartListBloc.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BlockProvider( // here it doesn't recognize BlockProvider
      blocs: [

      ],
      child:
    );
  }
}



【问题讨论】:

    标签: flutter bloc


    【解决方案1】:

    你必须去掉BlocProvider中的k

    import 'package:bloc_pattern/bloc_pattern.dart';
    import 'bloc/cartListBloc.dart';
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return BlocProvider( // remove the K
          blocs: [
    
          ],
          child:
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-01
      • 2020-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多