Modularizing Code
Explore how to organize Flutter code by moving API fetching logic into a dedicated MoviesProvider class. Learn asynchronous programming with async, await, and Future to retrieve movie data, update state with setState, and prepare for building a dynamic UI.
We'll cover the following...
This lesson delves further into executing HTTP requests to fetch movie data and organize code for better readability.
Modularizing code
Let’s move the getJson() method in its own class, say MoviesProvider. This keeps related code together.
All images in TMDB are hosted in a common location. We’ll use the imagePathPrefix variable to hold this path in the MoviesProvider class. Since this path doesn’t change and should be accessible from other classes, it should be final and static.
The imagePathPrefix is the path to image storage. Each movie carries its ...