How to Automate JSON to Dart Class in Flutter App Development

Aanal Mehta
Flutter Community
Published in
3 min readSep 7, 2020

Flutter app development gains ground swiftly in the developer’s community. On one hand, it attracts many developers to come up with innovative apps, and on the other hand, it keeps on evolving with advancements.

The Flutter platform is based on the Dart language. As a developer, I always wonder that we have so many plugins in Android to convert JSON to Java or Kotlin then why not we have plugins for JSON to Dart?

Here, I found a simple plugin that converts JSON to Dart(22,583 Downloads) in a very easy way.

This is the sample JSON we’ll take to convert in a Dart class.

To install this plugin, go to File > Settings > Plugins > JsonToDart(JSON To Dart).

To generate, right-click on the folder > New > Select Json To Dart.

We’ll look at the features that this plugin supports:

  • Formatting any legal JSON string: If you are putting any unformatted JSON file then, you can format it using this.
Format your JSON
  • Generating Dart data class as Inner Classes: If you wish to create an inner/separate class for each nested object.
Enabling this option will generate object class in a single file
Disabling this option will generate separate files for objects
  • Generates comments.
A good code always have comments for better understanding
  • Private fields feature with the option to make it enable/disable: As you already know that in Flutter, private variables start with _(underscore). You can create a Dart class files with private variables via enabling/disabling this option.

Short cut key to use ALT + Shift + D on Windows/Ubuntu or Option + Shift + D on Mac.

--

--

Aanal Mehta
Flutter Community

Software Engineer at Solution Analysts. Android | Flutter | React Native | NativeScript.