When to use Provider.of vs. Consumer in Flutter

前端 未结 4 590
一整个雨季
一整个雨季 2020-12-08 19:42

I\'m still wrapping my head around state-management techniques in flutter and am a bit confused about when and why to use Provider.of vs. Consume

4条回答
  •  鱼传尺愫
    2020-12-08 20:14

    It doesn't matter. But to explain things rapidly:

    Provider.of is the only way to obtain and listen to an object. Consumer, Selector, and all the *ProxyProvider calls Provider.of to work.

    Provider.of vs Consumer is a matter of personal preference. But there's a few arguments for both

    Provider.of

    • can be called in all the widgets lifecycle, including click handlers and didChangeDependencies
    • doesn't increase the indentation

    Consumer

    • allows more granular widgets rebuilds
    • solves most BuildContext misuse

提交回复
热议问题