Another exception was thrown: NoSuchMethodError: The getter 'bLoC' was called on null.
jp1017 opened this issue · 5 comments
jp1017 commented
使用的scope的bloc,
class BlocProvider extends InheritedWidget{
final CountBloc bLoC = CountBloc();
BlocProvider({Key key, Widget child}) : super(key: key, child: child);
@override
bool updateShouldNotify(_) => true;
static CountBloc of(BuildContext context) =>
(context.inheritFromWidgetOfExactType(BlocProvider) as BlocProvider).bLoC;
}
移植到自己项目报错:
I/flutter: Another exception was thrown: NoSuchMethodError: The getter 'bLoC' was called on null.
jp1017 commented
现在用的单例提供bloc
jp1017 commented
找到问题了,BlocProvider 要先调用
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
child: MaterialApp(
title: 'scoped',
theme: ThemeData.dark(),
home: TopPage(),
),
);
}
}
mirkancal commented
After navigation I get the same error. Do I have to wrap my MaterialApp with BlocProvider?
nrooban commented
HI guys, this kind of The getter 'id' was called on null. happens because of when you do HotReload.
To reproduce this
- Restart the app again(Check the app wether its working fine without doing any modification in hot-reload)
- If works fine, do some text or icon change and let hot-reload.
- Now do the testing again it will fail with 'The getter 'id' was called on null.'
I too waiting for the solution..
souravroyrickey commented
I am getting same error but while navigating to a page from a drawer. Below is the code but after number of attempts unable to find solution.
Navigator.push(context,MaterialPageRoute(builder: (context){
final nbloc = BlocProvider.of(context);
return BlocProvider(child: NotificationPage(), bloc: nbloc);
}));
