durlav kalita

Hi, I am Durlav. Developer and chess enthusiast.

Home Blog Projects About View on GitHub
    23 June 2021

    Flutter and json

    by durlavk

    flutter json and all the serializationšŸ’».

    Working with json is a necessary part for every app and flutter is no different. In order to use all the apiā€™s of world and for own backend we need to work with json but itā€™s not very straight forward in flutter. As flutter cannot directly use json data. We have to do something called serialization with it. So what is serialization. It is the process of converting json data to dart data and vice versa(in simple terms).

    There are two types of serialization manual and automated. In automated we have to use third party packages and it is suitable for large apps. But manual is writing the the whole process with models and jsonDecode() function. I seem to get the hang of manual serialization at least for now.

    In manual serialization first step is creating a model class for eg.- class User or class Post etc. Once the model class is defined, use Model.fromJson() to create a new instance of model and toJson() to convert the Model instance to a map. The jsonDecode() function can be used to get a model value from itā€™s json and jsonEncode() for the opposite. Now there is much more to it but it is a good start to manual json serialization in flutter.

    tags: flutter - json