
Take a look at the screenshot of this activity at the top. screens (activities)Ĭity_screen.dart – This code is the welcome screen, where the user need to provide city name. Weather.dart – This code implementing the WeatherModel class in order to retreive weather data from OpenWeatherMap API and modify conditional information according to the data. Networking.dart – This code implementing the Network Helper class in order to communicate with OpenWeatherMap API using http protocol and decoding the data which written in json format. Location.dart – This code implementing the Location class in order to get current location with Geolocator. Specifically, this constants.dart file contains theme classes for app widgets. utilitiesĬonstants.dart – All the application level constants. Hit like the article.Now, lets dive into the lib folder which has the main code for the application. If you like this article, do star the repo in GitHub. You can download the full source code of the article in GitHub. WeatherService service = retrofit.create(WeatherService.class) Ĭall call = service.getCurrentWeatherData(lat, lon, AppId) Ĭall.enqueue(new Callback () void Call call, Response response) To know more about Retrofit and Open Weather API

addConverterFactory(GsonConverterFactory.create()) Retrofit retrofit = new Retrofit.Builder() The following code snippet will help us to call the service. Then initialize Retrofit to call the weather service.The SerializedName annotation is used to parsing the server response and their name & type should be same as the Json Response received from the server.Public class WeatherResponse Coord Sys ArrayList weather = new ArrayList Main Wind Rain Clouds float int String float cod Ĭlass Weather int String String String icon Ĭlass Main float float float float float temp_max

I have used json to java converter in online to generate the Response class and the equivalent java class should be should be shown below.We will get the response as json as in the following. Create a class file named as “WeatherResponse.java” and add the following lines.Public interface WeatherService String lat, String lon, String app_id) Create an interface file named as “WeatherService.java” and add the following lines.We will see, how to use the link to access the weather data. The following API link is used to get the current weather report respect to the geo-coordinates. Step 4: Implementation of consumption of Weather API using Retrofit
