Start your Flutter apps from your own template with app_starter 🚀
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
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 createin order to prevent developers from putting their hands in all configuration files
- enabling developers to easily clone architecture and dependencies from their own template.
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:
- It creates a fresh new flutter application using the basic
flutter createcommand-line from the flutter version installed on your computer.
- It will get your model repository by cloning it (temporarily).
- Then, it will copy and paste the
testfolders, as well as the
pubspec.yamlfile from your model repository to your new app.
- 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.
- 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>
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.
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:
Or to see help:
What about Flavors?
Handling flavors is really common in app development.
For example, I always have, at least,
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 🔥
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.
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 :)