Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 18.104.22.168 release ready!
Owner and Founder. Opencart
We are going to learn that how can we use the Retrofit networking library in our Flutter projects, It might be possible for you to hear about retrofit if your background is Android app development.
Don’t worry 🙂 if your background is not Android development we will cover this blog with basic in easy language.
Retrofit is a networking library that is used to call the API to fetch or post the data to the server, It is the most liked network library because a lot of work is done by itself as JSON data parse into models, easy make GET, POST, PUT, etc requests by using awesome annotations.
In brief, Retrofit creates .g.dart classes from annotation at compile time which has all the logic behind the annotations like JSON parsing into models, etc. It will clear when you see the examples below.
Let’s start Retrofit integration in Flutter, First of all, we have to add Retrofit dependencies to include its lib classes in our project.
Here, we are using retrofit dependency along with helper dependencies like dio, logger, build_runner, retrofit_generator, and json_serializable
First, create an abstract class where your all API request method will be declared.
From where you call these request methods.
Same as SplashResponse.dart you can create LoginResponse.dart class as per your response.
Run this command on the terminal, Please make sure you are targeting the correct project dir path in the terminal.
Here, we created APIClient class where we declare our request method to get the splash data and post the login data. The Repo class where we call these methods and use async and await because the request method returns the Future type model which will get the data when the API response gets any response from the server.
flutter pub run build_runner build -> After this command, the respective .g.dart class automatically generated for logic to parse splash data response which will come in JSON format convert into SplashResponse model (Internally .g.dart are using the toJson() and fromJson() methods to achieve this), etc.
For more interesting blogs check out here – https://mobikul.com/blog/
Happy Coding <:)…/>
I hope this blog will help you to integrate Retrofit in Flutter, For any query comment down!
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
When I think in getting solutions for my Ecommerce Platform, I think of Webkul. They have been such a blessing in our business. We have spent thousands of dollars in support and modules from them. We love their support team. They work very closely with us, and they always go the extra mile when we need help.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.