Improve your productivity with Fast.cli 🔥
By: Alfredo Bautista Santos
Tags: Time, Dart, Flutter, Clean Code, Automation

Hi everyone! My name is Alfredo, I´m Flutter developer in HandCash and I coorganize Flutterconf and GDGMarbella, in Spain. In this article, I´m going to show how to optimice your time making projects in Flutter.

If you have worked with Flutter, you know you can create the scaffold project for Flutter apps using the Flutter CLI

$ flutter create …

And later, you can start implementing dependencies that will use in the project , like flutter_bloc, freezed, url_launcher… Searching in pub.dev and paste in pubspec.yaml

Then, you start creating your folder structure below lib, like domain, data_access, ui… And recursively, the subfolders inside their folders.

Very bored and repetitive, so I start searching how to automate it and I find this project.

Fast.cli project 🤖

Fast.cli is a tool, made by pbissonho, to create a custom CLI that can handle all of this task.

This tool works using plugins like VSCode system. You can create your own plugins and share with all people that use this tool, is amazing!

Currently, creating your plugin, you will have this features:

Templates generator

Application Scaffold generator

Snippet generator for Visual Studio Code

Custom commands

Standard line commands (Some commands already included in the CLI)

Amazing!! Let´s see how to install it.

Installation

You have to be installed the Dart SDK in your system to continue with this steps. When you have installed and configured the environment, only you have to write:

$ pub global activate fast

And add this folder to your environment in your bash, this is a example if you use zsh

echo export PATH="$PATH:$HOME/.fastcli/bin/" >> .zshrc

Clean-bloc project 🛠

This is the perfect tool to achieve my goal, create a tool to implement all dependencies and scaffold of whole of my projects.

Using this tool, I made a plugin for this automate, you can see here and all PR are welcome!

Installation

In order to install my plugin, you need to install before Fast.cli. After, you only have to write:

$ fast plugin add git git@github.com:alfredobs97/clean-bloc.git

And this is all! Now you can my plugin.

How to use

The first approach to my plugin was:

I need to create a standard scaffold, following clean-architecture principies and add the dependencies that all project need to use to create a robust, scalable and efficiency Flutter apps.

In order to create this, I wrote the “bloc scaffold”

$ clean-bloc create --name <flutter_projet_name> --scaffold bloc

This command will create the normal Flutter app scaffold with this content in lib

And this follow dependencies:

flutter_bloc: ^6.0.5

freezed_annotation: ^0.12.0

logger: ^0.9.4

json_annotation: ^3.0.1

chopper: ^3.0.2

injector: ^1.0.9

build_runner: ^1.10.4

freezed: ^0.12.2

bloc_test: ^7.1.0

mockito: ^4.1.3

json_serializable: ^3.5.0

chopper_generator: ^3.0.6

Finally, you can forget the hell flutter command:

$ flutter pub run build_runner build

And use:

$ clean-bloc run build

Make your own plugin!

This approach could be useful for developers that use bloc pattern and clean architecture but there are a lot of people using another patters or guidelines so I recommend you to create the plugin that optimize your time!

Following my plugin structure or Fast.cli tutorial, you can implement your own plugins in easy mode. Adding VSCode snippets or templates.

Thanks to the Flutter/Dart community 💙

This tool is a great example how the community is growing and there are a lot of great and useful packages for your day a day.

I encourage you to contribute to the Fast.cli project, this has a great future helping us saving time in new projects.

That´s all for today, thanks for your reading and you can find me in Twitter where DM are open!

Follow FlutterConf account and GDGMarbella to stay tuned with new events of Flutter! 💙

Thank you for your time and see you later! 👋🏼👋🏼