我刚进入一个网络应用程序的Ffltter项目,所有的开发人员都在使用Ffltter提供程序进行状态管理时遇到了问题.
What is the problem
When you arrive on a screen, the variables of the corresponding provider are initialised by calling a function of the provider. This function calls an api, and sets the variables in the provider.
Problem : This function is called in the build section of the widget. Each time the window is resized, the widget is rebuilt, and the function is called again.
What we want
We want to call an api when the page is first displayed, set variables with the result, and not call the api again when the widget is rebuilt.
What solution ?个
- 我们使用从第一个屏幕到第二个屏幕的推送.此时,我们可以调用提供程序的函数,以在第二个屏幕之前初始化提供程序. →,但第二页上的刷新将清除提供程序变量,并且不会再次调用初始化它们的函数.
- 我们在第二个屏幕的构造函数中调用该函数来初始化提供程序.这是一个好的图案吗?
感谢您在我的Ffltter新体验中提供的帮助:)