Could Not Find The Correct Provider - Flutter
Answer :
You need a builder
bridge between ChangeNotifierProvider
and Scaffold
.
Provider package already has it's own builder called Consumer
, you can use it like:
ChangeNotifierProvider<MySchedule>(
create: (context) => MySchedule(),
child: Consumer<MySchedule>(
builder: (context, provider, child) => Scaffold(....,
Check this link: https://pub.dev/packages/provider#reading-a-value
edit: builder
is now create
.
According to the latest version of the Provider package, the builder()
method of ChangeNotifierProvider
was changed to create()
.
So editing Esen Mehmet's version, this will work instead:
ChangeNotifierProvider(
create: (context) => MySchedule(), //change builder to create
child: Consumer<MySchedule>(
builder: (context, provider, child) => Scaffold(....,
Comments
Post a Comment