Hello I have a Widget build(BuildContext context) {}.' I tried to initialize the provider outside and use it, but I getting the following error:
Tried to listen to a value exposed with provider, from outside of the widget tree.
This is likely caused by an event handler (like a button's onPressed) that called
Provider.of without passing listen: false
.
To fix, write: Provider.of(context, listen: false);
It is unsupported because may pointlessly rebuild the widget associated to the event handler, when the widget tree doesn't care about the value.
The context used was: LoginSelectPage(dependencies: [MediaQuery], state: _LoginSelectPageState#0e08d)
@override
void initState() {
// TODO: implement initState
//registrationBloc = BlocProvider.of<RegistrationBloc>(context);
super.initState();
(() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
bool res = prefs.getBool('autoLoginKey');
SocketProvider provider = Provider.of<SocketProvider>(context);//This is where it matters.
}
In this case, how do we initialize the provider to use it?