Integrate the NovelCOVID API with Flutter
COVID 19 has now become a global pandemic and by now more than 300,000 people around the world have been infected. While staying home and searching the internet I found this API (please refer to this link to learn more about NOVELCOVID API) which provides real-time statistics about COVID 19 and I thought to integrate that API with Flutter Framework. So without further ado, let’s learn how to integrate NOVELCOVID API with Flutter.
Install the http Package
- First, add the following line to the pubspec.yaml file in your flutter application. (The version may change, at the time you check this article)
- After that you should install the package, just write the following code in your command line (for this to work you must have set an environmental variable for flutter). But keep in mind for some code editors like VS Code, this line will be automatically completed, therefore it would be better to check the documentation for your code editor to learn more about that.
For more information about the installation and other details about the http package please refer to the link.
Let’s Start Implementing!
I hope you have successfully installed the http package. Then let’s dive into the code.
First of all, we need to create two methods where one returning total statistics and other returning statistics based on the country.
Now we have the two methods which will return the necessary statistics. Now let’s call them!
Now you can see the statistics in your console.
Here I have used two important keywords, async and await. If you want to learn more about those keywords please refer to this link.
Github link to the code shown in the article
You can find the code shown in the article, in this GitHub link.
In this article, I discussed a simple example on how to use the NovelCOVID API in Flutter. I have also created a full application using NovelCOVID API, if anyone is interested to view the application, you can find the code in this GitHub link.
So now you have reached to the end of the article, and before I finish this article I want to say, if I have made any mistakes or if there is an easy way to do this please add a comment below about it and share this article among your colleagues if this is helpful.
Thank you and HAPPY CODING!
The endpoints of the API has been changed. You can refer the following link, to check for future endpoint updates.
Thank you ✌.