This repository showcases a collection of example bricks built using Mason, a Dart templating tool that helps you eliminate boilerplate and scaffold code efficiently in Flutter and Dart projects.
- Dart SDK
- Flutter SDK
- Mason
- Mason CLI
dart pub global activate mason_cli
Generates a custom card widget for Flutter applications with configurable title and subtitle.
Prompts:
widget_name
(string): Name of the widgettitle
(string): Title inside the Cardsubtitle
(string): Subtitle inside the Card
Usage:
mason make custom_card
The project is structured as a Flutter application with Mason integration:
mason_blog_example/
├── lib/ # Main Flutter application code
│ ├── main.dart # Entry point of the Flutter application
│ ├── repository/ # Repository pattern implementation
│ ├── usercase/ # Use case implementations
│ └── view/ # UI components and screens
├── custom_card/ # Custom card brick
│ ├── brick.yaml # Brick configuration
│ ├── __brick__/ # Template files
│ │ └── lib/ # Generated code structure
│ └── hooks/ # Pre and post generation hooks
│ ├── pre_gen.dart # Pre-generation validation
│ └── post_gen.dart # Post-generation formatting
├── mason.yaml # Mason configuration file
└── mason-lock.json # Lock file for Mason dependencies
The project uses pre-generation and post-generation hooks:
- Pre-Generation Hook: Validates that widget names are not empty
- Post-Generation Hook: Automatically formats generated Dart code
You can include/exclude parts of your template based on variables defined in brick.yaml
.
Syntax:
{{#condition}}
This code appears if 'condition' is true.
{{/condition}}
{{^condition}}
This code appears if 'condition' is false.
{{/condition}}
You can define variables in brick.yaml
and use them in your templates.
Example:
vars:
widget_name:
type: string
description: The name of the widget
title:
type: string
description: The title of the card
subtitle:
type: string
description: The subtitle of the card
The custom_card
brick included in this project generates a reusable Flutter card widget with customizable title and subtitle. It demonstrates how to:
- Set up variable prompts in
brick.yaml
- Implement pre-generation validation with hooks
- Apply automatic formatting post-generation
- Structure generated code within a Flutter project
# From project root
mason make custom_card
# Or, if you want to use hooks
mason make custom_card --hooks
Mason supports community bricks published on BrickHub.dev.
Search and install other bricks using:
mason add <brick-name>
mason get
- Clone this repository
- Install dependencies:
flutter pub get
- Install Mason CLI:
dart pub global activate mason_cli
- Get Mason Bricks:
mason get
- Create a new brick:
mason make <brick-name>
- Run the Flutter app:
flutter run
You can learn more in the accompanying blog post: 🔗 Mason for Flutter Developers
This repo is for learning and demonstration purposes.