Skip to content

SimformSolutionsPvtLtd/flutter_mason_sample

Repository files navigation

🧱 Mason Blog Example

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.

🔧 Requirements

  • Dart SDK
  • Flutter SDK
  • Mason
  • Mason CLI

🔨 Install Mason

dart pub global activate mason_cli

📦 Bricks Included

1. custom_card

Generates a custom card widget for Flutter applications with configurable title and subtitle.

Prompts:

  • widget_name (string): Name of the widget
  • title (string): Title inside the Card
  • subtitle (string): Subtitle inside the Card

Usage:

mason make custom_card

📁 Project Structure

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

✨ Mason Features Demonstrated

✅ Hooks

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

✅ Conditional Statements

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}}

✅ Variables

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

📱 Custom Card Widget

The custom_card brick included in this project generates a reusable Flutter card widget with customizable title and subtitle. It demonstrates how to:

  1. Set up variable prompts in brick.yaml
  2. Implement pre-generation validation with hooks
  3. Apply automatic formatting post-generation
  4. Structure generated code within a Flutter project

🔧 Using the custom_card brick

# From project root
mason make custom_card
# Or, if you want to use hooks
mason make custom_card --hooks

🌍 Public Bricks (BrickHub)

Mason supports community bricks published on BrickHub.dev.

Search and install other bricks using:

mason add <brick-name>
mason get

🚀 Getting Started

  1. Clone this repository
  2. Install dependencies:
    flutter pub get
  3. Install Mason CLI:
    dart pub global activate mason_cli
  4. Get Mason Bricks:
    mason get
  5. Create a new brick:
     mason make <brick-name>
  6. Run the Flutter app:
    flutter run

📚 Related Resources

You can learn more in the accompanying blog post: 🔗 Mason for Flutter Developers


🤝 Contributing

This repo is for learning and demonstration purposes.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published