Using Mason in flutter: A template generator

Mohit Joshi
2 min readJul 26, 2023

--

Today we are going to learn about what is Mason and how to implement it in our Flutter app.

Mason is template generator which helps teams generate files quickly and consistently. package:mason contains the core generator that powers package:mason_cli and can be used to build custom code generation tools.

Quick Start:

# 🎯 Activate from https://pub.dev
 dart pub global activate mason_cli
 
 # 🚀 Initialize mason
 mason init
 
 # 📦 Install your first brick
 mason add hello
 
 # 🧱 Use your first brick
 mason make hello

By using the above commands you can setup mason in your computer and use it in your projects.

You can discover new bricks to use from https://brickhub.dev/search. Its very similary to pub.dev. Let’s see an example of using mason bricks.

I like this brick very much and using it in most of my apps. This generate a new Flutter feature with bloc. Built for the bloc state management library.

Enter the following lines in your terminal to use this brick.

mason make flutter_bloc_feature --name counter --type bloc --style basic

This command will generate the following files.

Using this will saves a lot of time as we already know implementing Bloc takes a lot of boiler plate code, so by using this we can get most of the code.

--

--