Flutter中initState访问context及CountProvider初始化位置报错问题咨询
Flutter中initState访问context及CountProvider初始化位置报错问题咨询
大家好,我遇到一个Flutter相关的问题想请教各位:
当我把CountProvider的初始化代码放在initState和build函数外面的时候,就会触发错误;但如果把它放到initState方法内部(同样处于build函数之外),这个错误就消失了。
具体的报错信息如下:
The instance member 'context' can't be accessed in an initializer.
Try replacing the reference to the instance member with a different expression
有没有人能帮我解释一下这背后的原因呀?
备注:内容来源于stack exchange,提问作者Tawhidul Islam
相关产品推荐
相关产品推荐

