We're at Web Summit Vancouver | May 27-30
Contact us to meet!
Somnio Software Logo
Services
OverviewFull Product DevelopmentProduct DiscoveryStaff Augmentation
About
CompanyFlutter ExpertisePress & NewsCareers
Our work
Industries
Fintech
Healthcare
Education
Fashion
Media & Entertainment
Retail & Ecommerce
Other
Success Cases
Pronti
Pronti
ProWallet
ProWallet
Jaac
Jaac
Meet
Meet
bonnee
bonnee
Aqilis
Aqilis
View all
Resources
Open SourceTutorials & TalksDownloadables
Somnio Solutions
OverviewE-commerceNews
Blog
Let’s talk

Dart Macros, enhancing our developer experience

Discover how Dart Macros, introduced at Google I/O 2024, revolutionize code generation, enhancing developer productivity and streamlining tasks like JSON handling. Learn how this new feature impacts popular packages like json_serializable and freezed.

Dart Macros, enhancing our developer experience
Authors
Gianfranco Papa
Gianfranco Papa
CTO & Co-Founder
Technical
N
min read
/
September 6, 2024
Share
Copy post url
linkedin
Facebook
Twitter

The recent announcement of Dart Macros at Google I/O 2024 marks a significant milestone in the evolution of the Dart language, ushering in a new era of metaprogramming that promises to enhance the developer experience profoundly. Dart Macros, introduced as a preview in Dart 3.4 with the JsonCodable macro, offers a groundbreaking approach to code generation that integrates directly into the language. This feature allows developers to automate repetitive tasks, like JSON serialization and deserialization, which have long been a pain point in Dart due to the lack of runtime reflection. Introducing macros simplifies these tasks and maintains Dart’s emphasis on performance and developer productivity.

One of the most exciting aspects of Dart macros is how they can raise the level of abstraction in Dart programming. Macros enable developers to create powerful, reusable solutions tailored to their specific needs by allowing code to generate more code at compile time. The preview of the JsonCodable macro demonstrates the potential of this system, offering an elegant solution to JSON handling that seamlessly integrates with existing workflows, including hot reload. This integration ensures that using macros does not disrupt the developer’s workflow, but rather enhances it, making development more efficient and less error-prone.

What’s the state-of-the-art today, and what does this mean for the future of Dart?

First, this feature is still experimental so even though we’ve seen tremendous improvements we would have to wait until we can use it in a production environment. This doesn’t mean we can’t start getting familiarized with the macros system.

How will this impact code generation packages?

As Flutter developers, we rely so much on code generation packages using build_runner. For instance, json_serializable or freezed. This approach, although it works, is not the best, as it takes so many seconds of our lives to re-generate the files with any changes. However, the idea of code generation isn’t wrong. At the end of the day, while using this approach you get confidence that the actual code you are maintaining is smaller, less error prune on details and overall less time writing repetitive code. Well, while these packages are not going to disappear, they are probably going to adopt macros so that the developer experience will increase. The way we will interact with the package will be slightly different, but the essence will be maintained: we will still write annotations and some code will be created for us.

How can we expect these packages to get updated? Is there an actual migration guide?

Regarding a migration guide, because of the type of change it represents it is unlikely we will count on migration tooling, so I think starting using it from scratch in a project would be the easiest path but in bigger ongoing projects the migration (if desired) is going to be quite manual. 

How’s the community reacting to Dart Macros?

Overall the reaction has been quite positive since this is a feature that the community has asked for and has been interested in since a long time ago, as we can here.

So far, we’ve seen some packages that are trying to include this approach, like the freezed rewrite dataclass or a simply data_class package that provides things like `copyWith` or `toString`. I think that any package author who has created a package using code generation 

should start looking forward to macros to update it. 

Conclusions and next steps

In conclusion, introducing Dart macros represents a bold step forward for the Dart language, offering a powerful new tool for developers to enhance their productivity and creativity. As the macro system matures and becomes more widely adopted, we can expect to see a new wave of innovation in the Dart community, with developers leveraging macros to create more efficient, maintainable, and expressive code. This evolution will benefit current Dart users and attract new developers to the language, further solidifying Dart’s position as a leading platform for modern development.

Exciting Announcement

I'm thrilled to announce that Somnio will be participating in Fluttercon USA! I'll also be speaking at the conference, delivering two talks, including "The Power of Macros in Dart." I hope to see you there!

To learn more about my talks and Fluttercon USA, please feel free to contact me.

Contact us

Stay in the loop!

Receive tech news, software tips, and business insights.
Subscribe to our newsletter!

Thank you! Your submission has been received!
Oops! Something went wrong.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Read next

Technical

Flutter 3.32 & Dart 3.8: What’s New and What to Watch Out For

Read more
Flutter 3.32 & Dart 3.8: What’s New and What to Watch Out For
Read more
Business

How to Get a Job in Tech in 2025: Tips to Stand Out

Read more
How to Get a Job in Tech in 2025: Tips to Stand Out
Read more
Somnio Software Logo
Services
Full Product DevelopmentProduct DiscoveryStaff Augmentation
Our work
IndustriesFintechHealthcareEducationEntertainmentSuccess Cases
About
CompanyFlutter ExpertiseCareersPress & NewsPrivacy PolicyCompany Presentation Brochure
Resources
Open SourceTutorials & TalksDownloadablesBlog
Office
José Ellauri 1142
Montevideo, Uruguay
11300
Contact
hello@somniosoftware.comjobs@somniosoftware.com
(+598) 98 168 142 - Uruguay+1 (786) 726‑1751 - US
Clutch Award Top B2B Company 2022
Clutch Award Top B2B Company 2022Clutch Award Top B2B Company 2022Clutch Award Top B2B Company 2022Clutch Award Top B2B Company 2023Clutch Award Top B2B Company 2023Clutch Award Top B2B Company 2023Clutch Award Top B2B Company 2023Clutch Award Top B2B Company 2022The Manifest Award Top Flutter Developers 2021Clutch Award Top 1000 Companies Global 2022Clutch Award Top B2B Company 2023