How to deal with unwanted widget build?

前端 未结 3 1885
长发绾君心
长发绾君心 2020-11-21 11:28

For various reasons, sometimes the build method of my widgets is called again.

I know that it happens because a parent updated. But this causes undesired

3条回答
  •  [愿得一人]
    2020-11-21 12:14

    You can prevent unwanted build calling, using these way

    1) Create child Statefull class for individual small part of UI

    2) Use Provider library, so using it you can stop unwanted build method calling

    In these below situation build method call

    • After calling initState
    • After calling didUpdateWidget
    • when setState() is called.
    • when keyboard is open
    • when screen orientation changed
    • Parent widget is build then child widget also rebuild

提交回复
热议问题