Data Layer in Flutter | Use the Repository Pattern to keep a local copy of your API data
David Serrano
In this video I'm going to demonstrate how to implement the Repository Pattern to keep a local copy of the data fetched from a remote API.
Contents of the video:
- Explanation and application of the Repository Pattern in Flutter
- How to make API requests using the dio package
- How to interact with an SQLite database using sqflite
- How to write models faster using json_serializable
Useful resources:
- Open source project created in the video: https://github.com/svprdga/Flutter-Data-Layer-Repository-Pattern-V2
- Recipes API used in the demo app: https://rapidapi.com/apidojo/api/tasty/
- Clean Architecture: https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html
- Package to make the API requests (dio): https://pub.dev/packages/dio
- Package to interact with the database (sqflite): https://pub.dev/packages/sqflite
- Package to auto-generate models (json_serializable): https://pub.dev/packages/json_serializable
- Flutter pagination example: https://odysee.com/@svprdga:d/flutter-giphy-clone-speed-code Command to execute json_serializable to auto-generate the models:
- flutter pub run build_runner build
š¤ Text version of the video: https://davidserrano.io/data-layer-in-flutter-use-the-repository-pattern-to-keep-a-local-copy-of-your-api-data
šµ Follow me for more content like this: https://twitter.com/svprdga https://hashnode.com/@svprdga https://dev.to/svprdga https://mastodon.social/@svprdga https://davidserrano.io/
ā³ Timecodes: 00:00 - Introduction 00:36 - Final sample app demonstration 01:12 - Summary and scope 02:05 - What is the Repository Pattern? 03:52 - Create the app and add the required dependencies 06:03 - Create the domain model (Recipe) 06:50 - Create the network model (RecipeEntity) 12:05 - Create the API client 16:40 - Create the mapper to convert models 18:14 - Create the repository 19:20 - Create the App widget 22:47 - Create the main screen 27:10 - First app execution only fetching the data from the remote API 27:43 - Detail screen to show the recipe description 30:20 - Create the database model (RecipeDbEntity) 33:05 - Create the Data Access Object (DAO) 37:55 - Refactor the repository to be able to use both data sources 40:45 - Final app adjustments 41:32 - Second app execution to check the final behavior 44:13 - Final words
445972619 Bytes