Handling JSON schemas that are incompatible with your models
In a perfect world, JSON data would always be 100% compatible with your Dart classes, so the code you completed in the previous recipe would be ready to go to production and never raise errors. But as you are fully aware, this world is far from perfect, and so is the data you are likely to deal with in your apps. That's why, in this recipe, you will learn how to transform your code and make it more solid and resilient, and hopefully production ready.
Getting ready
To follow along with this recipe, you need to do the following:
- Complete the previous recipe.
- Download a more real-world
pizzalist_broken.json
file at https://github.com/PacktPublishing/Flutter-Cookbook/tree/master/chapter_08. - Rename the file to
pizzalist.json
How to do it...
For this recipe, using the project we built in the previous recipe, we will deal with a real-world JSON file, available at https://github.com/PacktPublishing/Flutter-Cookbook/tree/master...