Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.4k views
in Technique[技术] by (71.8m points)

Flutter is using provider to load data is the right option?

So i have a situation where i make an request from the server for one widget. The widget is at the home page, lets take the worst case where the data is huge and the request take time. Should i change the widget to stateless and make a provider which i will initialize before i run the app with all the initial data? Should i contain all the data of the widgets at home page and deliver theme as props, i miss understood the concept of managing the state here, I'm coming from vue and i try to write my first app and I'm struggling how to structure my data through the routes. I would like if some one explain or give a good source that show how to initialize data from third party before the home page reload. Which approach is better getting all the app data before the app reload or request data every time from db with cash


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You might have seen this approach in other apps as well which is to show a splash screen until the data has been loaded and ready to be shown. This approach is mostly used by apps which got large data to load at the start. You could achieve this in your initState like the following.

  @override
  void initState() {
  loadData();
 splashTimer = Timer(Duration(seconds: 4), () {
  _goToHome();
});
super.initState();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...