Flutter网站:BlocProvider:TypeError:无法读取未定义的属性“ get $ bloc”

时间:2019-12-28 12:48:24

标签: flutter flutter-web

我仅在配置文件和发行版(网络)版本中遇到此问题,但在调试版本中一切正常。

因此,我正在使用此类,该类可以访问didChangeDependencies()

中的bloc
class _CategoryPageState extends State<CategoryPage> {
  BizBloc _bizBloc;
  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    _bizBloc = BizBlocProvider.of(context);
  }
}

BlocProvider几乎位于应用程序的根目录附近,在main.dart中定义如下:

Widget build(BuildContext context) {
  return CityBlocProvider(
    child: CategoryBlocProvider(
        child: BizBlocProvider(
            child: MaterialApp( /** actual code goes here */ )
  )));
}

使用此设置,它在调试模式下都能正常工作,但是在配置文件构建中,出现以下错误:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
js_primitives.dart:49 The following NullError was thrown building Builder:
js_primitives.dart:49 NoSuchMethodError: method not found: 'get$bloc' on null
js_primitives.dart:49 
js_primitives.dart:49 Widget creation tracking is currently disabled. Enabling it enables improved error messages. It can
js_primitives.dart:49 be enabled by passing `--track-widget-creation` to `flutter run` or `flutter test`.
js_primitives.dart:49 
js_primitives.dart:49 When the exception was thrown, this was the stack:
js_primitives.dart:49 TypeError: Cannot read property 'get$bloc' of undefined
js_primitives.dart:49     at Object.BizBlocProvider_of (https://bazon.in/app/main.dart.js:10277:126)
js_primitives.dart:49     at _CategoryPageState.didChangeDependencies$0 (https://bazon.in/app/main.dart.js:47315:25)
js_primitives.dart:49     at StatefulElement._firstBuild$0 (https://bazon.in/app/main.dart.js:85143:31)
js_primitives.dart:49     at StatefulElement.mount$2 (https://bazon.in/app/main.dart.js:85016:12)
js_primitives.dart:49     at SingleChildRenderObjectElement.inflateWidget$2 (https://bazon.in/app/main.dart.js:84733:16)
js_primitives.dart:49     at SingleChildRenderObjectElement.updateChild$3 (https://bazon.in/app/main.dart.js:84661:20)
js_primitives.dart:49     at SingleChildRenderObjectElement.mount$2 (https://bazon.in/app/main.dart.js:85506:39)
js_primitives.dart:49     at StatelessElement.inflateWidget$2 (https://bazon.in/app/main.dart.js:84733:16)
js_primitives.dart:49     at StatelessElement.updateChild$3 (https://bazon.in/app/main.dart.js:84661:20)
js_primitives.dart:49     at StatelessElement.performRebuild$0 (https://bazon.in/app/main.dart.js:85039:41)

个人资料版本托管在https://bazon.in/app/#/

这里可能出什么问题了?

0 个答案:

没有答案