Provider vs. Get_it

前端 未结 3 1119
醉酒成梦
醉酒成梦 2021-02-07 01:56

Searching for Dependency Injection solutions for Flutter, I found two awesome libraries: provider and get_it.

As far as I can see, provid

3条回答
  •  一生所求
    2021-02-07 02:38

    The main difference between both is that provider is not strictly dependency injection.

    By using widgets, provider is also able to:

    • providers are compatible with the Flutter devtool
    • know when a variable cannot be accessed (scoped to a tree)
    • know when to create and dispose of an object
    • synchronize model -> model and model -> UI
    • override some values for only a specific widget tree
    • voluntarily prevent circular dependency

    All of these are, while optional, good for the health of your app in the long run.

    It ensures that you're always up to date, makes it harder to have "spaghetti code", and makes your different elements more composable.

提交回复
热议问题