#9 || Repository Provider - Creating the Repository || Flutter Bloc & Cubit Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back everyone in the coming few videos I will discuss how to F data from API in flutter block with the help of repository provider and repository pattern in this particular video I will discuss how to create the repository now let me discuss about the API which we will use to F the data as you can see that this is the API and this API is giving us this particular response now based on this response we need to create the model and to create the model here I have used the site app. quicktype doio and here I have pasted the Jon response after that I have given the model name as user model based on this Jon response and this name it has created the user model class now let me switch to vs code here I have created this particular project that is a repository provider and in the P.L file I have taken flutter block and Dio as dependency see now inside the LI folder here I will create a new folder named as data inside the data folder here I will create a subfolder named as model then inside the data folder I will create another folder named as provider and let me create one more folder named as repository now inside the model folder here I will create a file named as user model do dot sorry it will be D T and after that here this class which has been created I will simply copy this and after that I will paste it here so our user model class has been created now inside the provider here I will create a file named as user provider here I will write the code to fish the data from the API so let me create create a class here class user provider and here to fish the data I will use the instance of Dio so let me create the instance of Dio final Dio and to the Constructor of this Dio it will take base options and in the base options here I need to pass the base URL now we know the base URL so let me copy this base URL and let me paste it here so our instance of Dio has been created after that here I will create a method that is get users which will fish the data from that particular API to do that here I need to create a method get users obviously I will declare this method async and the return type of this G users method will be future of user model now here I need to use try catch and in the catch I will return future error then e do tost string now inside the try here I will declare a variable final response equals to now I need to use a wa and then I will use the Dio instance and then I will call the get method and in this G method here I need to specify the path and as you can see here the path is users page one so let me copy this and let me paste it here after that I need to return user model from Jon Now from where I'm getting this method this method I'm getting from the user model class as you can see here this user model from G has been created so I will use that method and here I need to pass response dot to a string so our user provider class has been created now inside the repository I will create a file named as user Repository here I will create a abstract class I user repository and inside this class here I will create a method having the return type as future of user model and the method name will be gate users sorry it will be gate users now the implementation of this method I will provide inside a class named as user repository so here I will create user repository and what it will do it will Implement a user repository and once it implements I user repository then it is mandatory to override this particular method so let me click here create one missing override now here I need to provide the implementation of this particular method that is get users and to do that first of all here I will create the instance of user provider and to the Constructor of this user repository here I will pass this dot user provider and here I will do one more thing I will declare this as final now inside this particular method what I need to do is that here I will simply write return return user provider do get users because the implementation of this method is already created inside the user provider now the advantage of using this user repository is that later on now here I am fishing the data from the remote API later on suppose the requirement is that I will fish the data from the local repository then I need to change only this particular code okay and after changing this particular code I will write the logic to fish the data from the local data source from the local DB but the rest of the application will not be affected because these methods will remain same and we need to call these methods only okay so whether your data source is same or changing the uh the rest of the application will not be affected that is the advantage of you uh Repository pattern that I have already discussed in the previous video okay so this is how we have created the model the provider and the repository in the next video I will discuss how to create the state event and block that's it for today's video thank you so much for watching
Info
Channel: Ripples Code
Views: 1,367
Rating: undefined out of 5
Keywords: Flutter Bloc Tutorial, Flutter Cubit Tutorial, Flutter Bloc Pattern, Cubit Pattern Flutter, Bloc Flutter Tutorial for Beginners, Cubit Flutter Tutorial Step by Step, bloc Flutter Tutorial Step by Step, Flutter Bloc Pattern Architecture, Flutter Cubit Pattern Architecture, Flutter Bloc Implementation, flutter bloc complete tutorial, flutter bloc and cubit tutorial series, flutter bloc and cubit from scratch, how to create the respository in flutter bloc
Id: rl2YdGjpB5s
Channel Id: undefined
Length: 7min 20sec (440 seconds)
Published: Mon Jan 01 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.