My main.dart has this -
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return ChangeNotifierProvider(
builder: (_) => Athlete(),
child: MaterialApp(
.......
home: MyHomePage()));
My home page file has -
class MyHomePage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: new Stack(
children: [
GestureDetector(
onTap: () {
bool tmp = Provider.of(context, listen: false).dummy;
When I run this I get -
Error: Could not find the correct Provider above this MyHomePage Widget
To fix, please:
- Ensure the Provider is an ancestor to this MyHomePage Widget
In my understanding, MaterialApp is the child of ChangeNotifierProvider and MyHomePage is a descendent of MaterialApp, then why is the error showing cannot find Provider above MyHomePage widget? What could be going wrong?
Thanks,
-Anil
My main.dart has this -
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return ChangeNotifierProvider(
builder: (_) => Athlete(),
child: MaterialApp(
.......
home: MyHomePage()));
My home page file has -
class MyHomePage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: new Stack(
children: [
GestureDetector(
onTap: () {
bool tmp = Provider.of(context, listen: false).dummy;
When I run this I get -
Error: Could not find the correct Provider above this MyHomePage Widget
To fix, please:
In my understanding, MaterialApp is the child of ChangeNotifierProvider and MyHomePage is a descendent of MaterialApp, then why is the error showing cannot find Provider above MyHomePage widget? What could be going wrong?
Thanks,
-Anil