Base Project
Creating a Base Project in Flutter
Last updated
Creating a Base Project in Flutter
Last updated
This article is complete when combined with and .
Any Flutter developer, after working on multiple projects, wants to create a project template to speed up the initialization of future projects. However, extracting reusable parts and setting up the project structure from scratch can be time-consuming and tedious.
To solve this, I explored various ways to automate the creation of essential files and folders. One approach is using Windows command-line tools to generate files, but a more powerful tool that can save time for you and your team is Mason.
If you're unfamiliar with Mason, check out my guide:
Below is a list of important libraries that I use to ensure the code is clean, scalable, and maintainable.
get_it
Helps with data retrieval and dependency injection.
Allows access to repositories anywhere in the project without manually passing data between classes.
go_router
Official Flutter routing libraryβworks well for both mobile and web.
Provides a clear and scalable way to manage navigation.
flutter_bloc
One of the most popular and efficient state management libraries.
If you're new to bloc
, check out my guide:
json_serializable
& freezed
Reduces repetitive boilerplate code.
Automatically generates helpful functions like copyWith
, fromJson
, and toJson
for easier data handling.
lint
Enforces Effective Dart coding standards.
Ensures consistent and readable code across teams.
flutter_launcher_icons
Automatically generates app icons for both Android and iOS.
Saves time when setting up project branding.
Below is how I structure the lib/
directory in my base project:
Outside of the lib/
folder, I also set up:
A well-configured development environment helps prevent issues before the app reaches users.
To easily switch between environments (dev, staging, production) without manual changes, I use an enum
to store environment settings.
You can extend this enum to include additional configurations like API keys, logging settings, and more.
Development Environment (Local Server)
Staging Environment (Internal Testing Before Release)
Production Environment (Final Release for Users)
Setting up a base project in Flutter saves a lot of time when starting a new project, making it easier to maintain and scale.
Use Mason to automatically generate necessary files and directories.
Leverage popular libraries such as go_router
, flutter_bloc
, json_serializable
, and freezed
to enhance development efficiency.
Configure dev, staging, and production environments to better manage application environments.
If you havenβt read Effective Dart, check it out here: .
You can check out my base project template, which is built using Mason, here:
|