Start your Flutter apps from your own template with app_starter šŸš€

Thomas Ecalle
5 min readMar 20, 2021

Whether you are a freelance Flutter developper, a tech lead or even a student, you may create new apps very often. And it takes time...

First steps of creating a new Flutter app are always the same:

  • create the app with the right name and organization
  • put on the architecture you are used to work with
    Working with BloC ? Provider ? MobX ?
    Willing to work with Clean Architecture ?
    You have to setup all of this each time.
  • put all the dependencies you are used to work with
    Your usual i18n, tests or http dependencies for example.
  • (depending on your needs): adding some flavors
  • etc.

app_starter is here to make you save some time šŸ”„

How to automate apps creation?

Ok. Now that you want to automate your apps creation, you have several choices:

Using an already existing ā€œstarterā€

You could use an already existing app starter as the good one from Very Good Ventures : very_good_cli

And yes: this is a good starter šŸ˜

But the issue with it is that you canā€™t really customize its content.

very_good_cli is based on a good architecture example but what if you want to have another one ? What if you want to change something ?

Cloning a repository and ā€œchange the nameā€

This is what I used to do for a while.

I created then a ā€œmodelā€ git repository that was built as I wanted each of my new apps to be built.
When I wanted to create a new app, I cloned this model and all I had to do was to change the different names and package identifier all over the app.

Wellā€¦ that was never that simple.

ā€œChanging the different names and packages identifiers should not be hardā€

This is one of the most naive sentence I could have said šŸ˜­

In fact, creating a Flutter app using Flutter command-line automate a bunch of things for you ! From putting the right packages identifiers on iOS & Android to the right names in different configurations files, etc.

And the number of concerned files increase with Flutter evolvingā€¦ šŸ“ˆ

Using app_starter šŸš€

The idea behind app_starter is really simple.

I just wanted to reunite the best of the 2 worlds:

  • creating the app using Flutterā€™s command-line flutter create in order to prevent developers from putting their hands in all configuration files
  • enabling developers to easily clone architecture and dependencies from their own template.

Flutter evolves?

That is not a problem: you will still be able to create new apps cloning your base architecture without any effort šŸŽ‰

How does it work?

The way app_starter works is surprisingly easy:

  1. It creates a fresh new flutter application using the basic flutter create command-line from the flutter version installed on your computer.
  2. It will get your model repository by cloning it (temporarily).
  3. Then, it will copy and paste the lib and test folders, as well as the pubspec.yaml file from your model repository to your new app.
  4. Fourth step: it will change all imports and references in these directories (and in pubspec.yaml), recursively, in order to put the right new dart package identifier.
  5. Finally, the tool will delete temporary cloned repository andā€¦

You are good to go šŸš€

Under the hood, this is quite as simple as a copy and paste.

This way developers have the insurance that configuration files and directories will always be created by flutter create command-line and conform with their local Flutter version.

And they can create a model repository with their base architecture and dependencies that would represent a ā€œfresh new appā€ from their point of view.

How to play with it?

At first, you have to activate the executable:

flutter pub global activate app_starter

Then, you just have to call app_starter with following information:

  • your package identifier
  • your organization identifier
  • your templateā€™s repository url

And your fresh new app will be created šŸ”„

app_starter --name <package_identifier> --org <organisation> --template <template_git_repository>

For example:

app_starter --name toto --org io.example --template https://github.com/ThomasEcalle/flappy_template

You can also use abbreviations:

app_starter -n toto -o io.example -t https://github.com/ThomasEcalle/flappy_template

If you want to save these values for the next times, you can add a --save flag. It will store values in a configuration files and use them next time if you donā€™t provide some.

For example:

app_starter --save -n toto -o io.example -t https://github.com/ThomasEcalle/flappy_template

All these values are now stored in configuration file.

If I always use the same template and organization identifier, it allows me to call it that way next time:

app_starter -n totobis

If you need to see values stored in configuration file:

app_starter --config

Or to see help:

app_starter --help

What about Flavors?

Handling flavors is really common in app development.

For example, I always have, at least, dev and prod flavors on each of my apps, sometimes more.

But creating flavors is not really simple (here is the official doc)

On Android, it is not really hard but on iOSā€¦ well, it is not ā€œhardā€, but it takes time and tests to be sure everything is well configured.

Having to setup flavors for every new Flutter app is really time consuming and boring!

But I didnā€™t want to handle flavors with app_starter.

In my point of view, app_starter should be really agnostic about developers personal points of view. Maybe you donā€™t want to use flavors and I didnā€™t want to force anyone.
The point of this tool is to let it absolutely customizable through templates.

BUT, app_starter can still help you handling flavors more easily šŸ”„

All you have to do is to setup your template repository the good way.
For example, I have created a template that use flutter_flavorizr as depedency.

This package is awesome in flavors handling.
All you have to do is to declare all of the wanted flavors in pubspec.yaml.
Then, you just have to execute the right command-line to automatically generate them (see its doc for more details).

How to use it with app_starter?

If you take a look at this example template, all I have done is to declare flavors in pubspec.yaml.

Then, every time I would create a new app, I would just have to change the default names of the flavors, run the flutter_flavorizr command-line andā€¦

everything would be generated šŸš€

As you can see, the way app_starter works is willingly agnostic of any architecture or point of view.

It should let any developer having his own template, his own logic, and not forcing him to use anything.

Whatā€™s next?

To be honest, I have created this package for my personal usage.
It perfectly suits my own needs and I donā€™t really need something else for the moment.

I have decided to make it public in case it may help somebody else but I donā€™t even know if it would suit anybody else needs.

For the moment, I have absolutely no idea of future evolutions but feel free to propose some on the GitHub repository.

Time is a rare commodity for me and I canā€™t assure you that I would be able to handle them, but we never know :)

--

--