Building a Weather Application with Dart's Flutter Framework (Part 1, Handling Complex JSON with Built Code Generation)

in #utopian-io6 years ago (edited)

What Will I Learn?

  • You will learn how to use JSON Serialization inside of Dart
  • You will learn how to build a set of objects and annotate them for code generation
  • You will learn how to use build runner to generate code with JSON annotation and JSON serializable
  • You will learn how to avoid mirrors and reflection in a Dart/Flutter application.

Requirements

Difficulty

  • Intermediate

Description

In this Flutter Video tutorial, we create a series of objects to help with JSON serialization and decoding for our weather application. We make use of the JSON Annotation, JSON Serializable and Build Runner plugins to annotate these objects and then generate a large amount of boilerplate code that will help us convert our responses and requests to and from JSON. This not only helps us save time by creating boilerplate code, it also helps with performance.

In the past flutter tutorials, we have mostly been working with fairly simple JSON objects. As a result of this, it has been fairly easy for us to create methods and objects which let us take those JSON data objects into our dart code as dart objects. Now that we are using the OpenWeatherMap API which features many nested objects, we need a better method to decode our JSON objects. In Dart, typically when you want to decode and encode a piece of data into JSON you make use of mirrors and reflection. The dynamic nature of these abstractions can strain the performance of our applications especially when dealing with larger JSON objects.

The solution for this problem is Serialization and Code Generation. By using Serialization, we can avoid having to use Mirrors and Reflection in our Flutter application. Also, with the Code Generation, we can now generate multiple pieces of code that we would have had to manually implemented otherwise. In this way, we can easily expose various JSON Data objects to our application and also create an inner state for the application.

The source code for this project can be found here

Open Weather API can be found here

Video Tutorial

Projects and Series

Stand Alone Projects:
Building a Calculator
Movie Searcher Application

Minesweeper Game

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Nice informations

Hey @tensor! Thank you for the great work you've done!

We're already looking forward to your next contribution!

Fully Decentralized Rewards

We hope you will take the time to share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.

Utopian Witness!

Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.

Want to chat? Join us on Discord https://discord.me/utopian-io

Thank you for your contribution.

In the future, you may wish to add more graphical content and tutorial steps into your outline so that Utopian learners can follow along with your video tutorial.

Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Thank you for moderating my contribution. I will take your suggestion under advisement, unfortunately, there is only so much that I can do with the time I have each day.

Edit: I figure I might add that after seeing your latest tutorial, I will try to get some photos and at least write out a good outline for the content for my next tutorials.

Coin Marketplace

STEEM 0.20
TRX 0.13
JST 0.030
BTC 64118.79
ETH 3390.14
USDT 1.00
SBD 2.51