Provider Throw Errors in InitState. Provider.of(context)

后端 未结 3 433
说谎
说谎 2021-01-28 05:34

How do I access the context for the Provider in the initState

I keep getting the error

flutter: The following assertion was thrown building Builder:
fl         


        
相关标签:
3条回答
  • 2021-01-28 06:08

    Provider.of<ProductProvider>(context, listen: false).selectedProduct and ensure there are no NotifyListeners in the initState call.

    0 讨论(0)
  • 2021-01-28 06:14

    Try to postpone this call with Future.delayed(...)

    0 讨论(0)
  • 2021-01-28 06:14

    Use Simon's AfterLayout package https://pub.dev/packages/after_layout and call it in the function you need to implement. It will be called after Build() has been run

    0 讨论(0)
提交回复
热议问题