Flutter: How Code Generators Work

Learn how packages like freezed, json_serializable, and riverpod_generator work under the hood

Tomic Riedel
4 min readMay 20, 2024
Icon by freepik

Being a Flutter developer, I’d bet you have used at least once a code generation tool. Have you ever used freezed? json_serializable? riverpod_generator? mobx_codegen? Or have you ever run dart run build_runner build? If your answer is yes, you have already used a code generation tool in Flutter.

But… what exactly are code generators? And most importantly, how do they work?

All of that, we are going to cover in today’s article.

· What Are Code Generators?
· The Role of Code Generators in Flutter
· How Code Generators Work

What Are Code Generators?

Code generation in software development refers to the process of automatically generating code that is typically written by developers.

This is achieved by using tools and scripts that convert specific inputs or models into source code that can be compiled and executed. These inputs might include domain-specific languages, annotations in code, or model descriptions. The primary aim of code generation is to automate repetitive coding tasks, reduce human errors, and…

--

--

Tomic Riedel

Sharing the process of building a portfolio of apps to make people more productive.