How do I access the value in a provider model from the init function or a workaround?
Basically, when my App loads, I save some value in a provider model.
One value is a search variable. Then I am redirected to a loading page where I need this value to get the data and render a list.
I am retrieving the data in the init method.
-- My Main function
void main() {
runApp(
Provider<UserModel>(
builder: (_) => UserModel(),
child: Jobs(),
),
); //added
}
This is a snippet of my Jobs page
case '/main':
return MaterialPageRoute(
builder: (_) => JobsHomePage(title: "jobs"));
break;
This is list page that displays this list --- JobsHomePage()
void initState() {
searchVal = Provider.of<UserModel>(context).searchVal;
jb =load(searchVal);
}
Then I have a builder method that iterates thru 'jb' and prints the value
The error I am getting is inherited error
flutter: When an inherited widget changes, for example, if the value of Theme.of() changes, it's dependent
Thanks for your help... I did not post the entire code because it is very long and I get some "all code" error in the stack.