Scaff is a simple command-line utility for generating Dart and Flutter components from template files.

Overview

Introduction

Scaffold Generator for Dart and Flutter.

scaff is a simple command-line utility for generating Dart and Flutter components from template files. It is a very tedious job to keep replicating the boilerplate codes every time you try to add a new component in your app. Using scaff, you can generate dart or flutter components from the custom-defined templates. You can even include template variables in the component files and directories name for easy and flexible scaffolding.

scaff uses 'Mustache templating library' variable schemes for defining and processing the template files.

Installation/Upgrade

$ pub global activate scaff

Usage

$ pub global run scaff

Example

Let us create a simple component. First of all, we need to create a working directory and it should contain a scaff.setup.json file. The scaff.setup.json file should contain all the template variables used in the working directory. The component subdirectories and files should be included inside the working directory. The files and directories name may contain template variables as well.

Template variable examples: {{var1}}, {{className}}Base, {{fileName}}_store

The example template directory structure:

component_templates
│   └── general_store_architecture
│       ├── scaff.setup.json
│       └── {{componentName}}
│           ├── {{componentName}}.dart
│           └── {{componentName}}_store.dart
  1. Create a new directory in the project root
$ mkdir -p component_templates/general_store_architecture
$ cd component_templates/general_store_architecture
  1. Create the component directory
$ mkdir {{componentName}}
$ cd {{componentName}}
  1. Create the component template file
$ touch {{componentName}}.dart
  1. Add the code to {{componentName}}.dart file
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../data/mobx/{{componentName}}_store.dart';

class {{className}}Screen extends StatelessWidget {
  {{className}}Screen({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final {{componentName}} = Provider.of<{{className}}Store>(context);

    return Scaffold(
      body: Center(
        child: Column(),
      ),
    );
  }
}
  1. Create the store template file
$ touch {{componentName}}_store.dart
  1. Add the code to {{componentName}}_store.dart file
import 'package:mobx/mobx.dart';

abstract class {{className}}StoreBase with Store {
  @observable
  bool dummyValue = false;
}
  1. Create the scaff.setup.json file
$ cd ..
$ touch scaff.setup.json
  1. Add all the template variables used in the working directory to scaff.setup.json file as
{
  "variables": [
	"componentName",
	"className"
  ],
  "mappedVariables": {
	"componentName": "login",
	"className": "LoginScreen"
  }
}
  • variables holds a list of template variables. The CLI will prompt for the user input.
  • mappedVariables holds the values for the template variables. The generator will pick values from the mappedVariables automatically, if required.
  • You may use either of the one or in combination. CLI will skip the prompt if the value for a template variable is already available inside the mappedVariables.
  1. cd into general_store_architecture folder.
$ pwd # it should be pointing to =>  /path/component_templates/general_store_architecture
  1. Run scaff globally
$ pub global run scaff
  1. You will be prompted to:
Enter source directory (/path/component_templates/general_store_architecture) »
Enter destination directory (/path/component_templates/general_store_architecture/__component__) »
Enter template extension (dart) » 
Enter 'componentName' variable value » login
Enter 'className' variable value » Login
  1. The destination directory will have the newly generated component. The destination directory structure:
└── login
    ├── login.dart
    └── login_store.dart

Buy me a coffee

Help me keep the app FREE and open for all. Paypal me: paypal.me/ganeshrvel

Contacts

Please feel free to contact me at [email protected]

About

License

scaff | Scaffold Generator for Dart and Flutter. MIT License.

Copyright © 2018-Present Ganesh Rathinavel

You might also like...

shared_versions is a command line tool that allow share the versions for multiple packages in Flutter

shared_versions shared_versions is a CLI tool that allow share the versions for multiple packages in Flutter. Usage shared_versions will match the pac

Sep 20, 2022

Icons Launcher - A command-line tool that simplifies the task of updating your Flutter app's launcher icon.

Icons Launcher - A command-line tool that simplifies the task of updating your Flutter app's launcher icon.

Icons Launcher - A command-line tool that simplifies the task of updating your Flutter app's launcher icon. Full flexibility allows you to only update the launcher icon for specific platforms as needed.

Nov 17, 2022

A command-line application provide an load optimization solution for flutter web

A command-line application provide an load optimization solution for flutter web

一个命令行工具,针对flutter web加载慢和缓存问题提供了一套解决方案。 功能 通过大文件分片和资源文件cdn化方式,优化flutter web页面加载慢问题。 通过资源文件hash化,解决浏览器强缓存导致功能无法更新问题。 开始 局部安装 dev_dependencies: flutte

Dec 29, 2022

Command Line Interface (CLI) for Lucifer

Lucy Command Line Interface (CLI) for Lucifer. Installation Activate command line from your terminal with this command. pub global activate lucy Usage

Dec 16, 2021

☄ Anime/Manga command-line interface backed up by Tenka.

☄ Anime/Manga command-line interface backed up by Tenka.

Yukimi ☄ Anime/Manga command-line interface backed up by Tenka. By using this project, you agree to the usage policy. Installation Pre-built binaries

Jan 6, 2023

A fluent API for generating valid Dart source code

A fluent, builder-based library for generating valid Dart code. Usage code_builder has a narrow and user-friendly API. See the example and test folder

Jan 7, 2023

OrderFoody - A template with command buttons in horizontal scrolling list

OrderFoody - A template with command buttons in horizontal scrolling list

order_coffee In this project you create a template with command buttons in horiz

Jun 22, 2022

A Flutter package for generating sign in buttons for different social media accounts.

A Flutter package for generating sign in buttons for different social media accounts.

Sign In Button A Flutter plugin for generating sign in buttons for different social media accounts. Getting Started You must add the library as a depe

Dec 8, 2022

Download files from Firebase Storage with Flutter. List all images, videos, or other files from Firebase and download them.

Download files from Firebase Storage with Flutter. List all images, videos, or other files from Firebase and download them.

Flutter Tutorial - Download Files From Firebase Storage Download files from Firebase Storage with Flutter. List all images, videos, or other files fro

Dec 4, 2022
Comments
  • Can't execute pub global run scaff successfully

    Can't execute pub global run scaff successfully

    When I try to run pub global run scaff every time I get an error:

    Unhandled exception:
    StdinException: Error getting terminal echo mode, OS Error: Inappropriate ioctl for device, errno = 25
    #0      Stdin.echoMode (dart:io-patch/stdio_patch.dart:71:7)
    #1      get (package:prompts/prompts.dart:60:27)
    #2      CliParser.getCliStream (package:scaff/src/classes/cli_parser.dart:51:23)
    #3      main (file:///Library/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/scaff-1.2.0+2/lib/src/main.dart:22:31)
    #4      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
    #5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
    pub finished with exit code 255
    

    What should I do for avoiding this problem?

    Scaff version: 1.2.0+2 OS: BigSur 11.2.1 (20D74)

    Flutter 1.22.6 • channel stable • https://github.com/flutter/flutter.git Framework • revision 9b2d32b605 (6 weeks ago) • 2021-01-22 14:36:39 -0800 Engine • revision 2f0af37152 Tools • Dart 2.10.5

    The folder structure is exactly the same as in your example. Full regards.

    opened by AdMeen89 9
Owner
Ganesh Rathinavel Medayil
Now building UNIX/Windows Kernel at @SubconsciousCompute!
Ganesh Rathinavel Medayil
Interactive command line interface Couchbase Lite REPL utility built with the Dart

Couchbase Lite Dart CLI Interactive command line interface Couchbase Lite REPL utility built with the Dart programming language. This code uses the cb

Pieter Greyling 2 Jul 20, 2022
Screenshots - A command line utility and package for capturing screenshots for Flutter

A screenshot image with overlaid status bar placed in a device frame. For an example of images generated with Screenshots on a live app in both stores

Maurice McCabe 258 Nov 22, 2022
Basf flutter components - A BASF Flutter components library for iOS and Android

basf_flutter_components A BASF Flutter components library for iOS and Android In

BASF Mobile Solutions 7 Dec 15, 2022
This is a simple Gantt chart generator written as Dart command line tool.

Gantt Chart Generator This is a simple Gantt chart generator written as Dart command line tool. Currently the tool generates an HTML/CSS Gantt chart.

John Lyon-Smith 1 Apr 26, 2022
changelog.dart provides a library and a command-line application to manage in the correct way the git metadata to build the changelog between two release

changelog.dart ?? changelog.dart: a collection of tools to manages in a fashion way a repository as maintainer. ?? Project Homepage Table of Content I

Vincenzo Palazzo 7 Dec 18, 2022
Package your Flutter app into OS-specific bundles (.dmg, .exe, etc.) via Dart or the command line.

flutter_distributor Package your Flutter app into OS-specific bundles (.dmg, .exe, etc.) via Dart or the command line. The flutter_distributor source

LeanFlutter 416 Dec 24, 2022
This is a command-line app written on dart language for flutter applications that will help you to generate some boilerplate code

dart-generator Manual installation: 1- generate a platform executable from code dart compile exe main.dart -o generator this will generate a new gene

One Studio 11 Oct 26, 2022
A Nerolab Command Line Interface for Dart created by Nerolab

Nerolab CLI Nerolab Command Line Interface for Dart. Special thanks to GroovinChip with groovin_cli and very_good_cli. Installing dart pub global acti

Nerolab 1 Jan 19, 2022
Listen to remote Flutter GTK application instances' command-line arguments and file open requests.

gtk_application This package allows the primary Flutter GTK application instance to listen to remote application instances' command-line arguments and

null 12 Dec 15, 2022
An incredible command line interface for Flutter.

Fast CLI An incredible command line interface for Flutter. It allows you to create your own CLI without coding a line. With this CLI, you can create y

Pedro Bissonho 41 Jul 12, 2022