I cannot figure out what is wrong with this code. There is a bloc provider on this page:
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider(
create: (BuildContext context) {
return DatabaseBloc();
},
),
BlocProvider(
create: (BuildContext context) {
return QuestionholderBloc();
},
)
],`child:RaisedButton(
splashColor: Colors.green[600],
focusElevation: 50.0,
hoverElevation: 50.0,
color: Colors.green[600],
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.yellow[700]),
borderRadius: BorderRadius.circular(50.0)),
child: Text(
"Start",
style: TextStyle(fontWeight: FontWeight.bold),
),
textColor: Colors.white70,
onPressed: () {
ExtendedNavigator.of(context)
.pushNamed(Routes.questionHandler);
}),)
sorry for the possible syntax error. In the QuestionHolderPage I have:
void didChangeDependencies() {
_statusbloc = BlocProvider.of<QuestionholderBloc>(context);
_dbbloc = BlocProvider.of<DatabaseBloc>(context);
_statusbloc.add(CheckStatus());
super.didChangeDependencies();
}
Widget build(BuildContext context) {
return Scaffold(
body: MultiBlocListener(
listeners: [
BlocListener<QuestionholderBloc, QuestionholderState>(
listener: (context, state) {
if (state is NoQuestions) {
_dbbloc.add(GetQuestions());
} else if (state is HasQuestions) {
_statusbloc.add(GetQuestion());
}
},
),
BlocListener<DatabaseBloc, DatabaseState>(
listener: (context, state) {
if (state is Loaded) {
_statusbloc.add(SetQuestions(questionsToSet: state.questions));
}
},
),
],
child: BlocBuilder<QuestionholderBloc, QuestionholderState>(
builder: (context, state) {
if (state is QuestionLoaded) {
return QuestionWidget(question: state.question);
} else {
return CircularProgressIndicator();
}
},
),
),
);
}
}
Error:
Error: No ancestor could be found starting from the context that was passed to I/flutter ( 4318): BlocProvider.of().
`
), it looks like it is out of place. If that is just a type here, and not in your code, please repair it anyway.