Skip to content

yusriltakeuchi/flutter_template

Repository files navigation

Flutter Template

This is a template for creating a new Flutter project with a well-structured architecture and best practices.

👨‍🔧 Created by : Yusril Rapsanjani

Features:

  • Domain-Driven Design (DDD): Organizes code into logical layers for maintainability and scalability.
  • Freezed: Utilized for immutable data classes and sealed classes, reducing boilerplate code.
  • BLoC / Cubit: Implements state management using the BLoC pattern for a clear separation of concerns.
  • AutoRoute: Provides automatic route generation and navigation management.
  • Multiple Variants: Supports multiple environments (dev, staging, prod) to facilitate testing and deployment.
  • Dependency Injection: Ensures modular and testable code structure.
  • Error Handling: Centralized error handling using Failure and ResponseCode for better debugging and UX.

This template serves as a solid foundation for developing scalable and maintainable Flutter applications. 🚀

🚀 Tested On Framework

➡️ Flutter 3.29.0

➡️ Dart 3.7.0

🔨 Project Structure

lib
│── bloc
│── config
│── core
│   │── components
│   │── constant
│   │── models
│   │── networks
│── domain
│   │── entities
│   │── models
│   │── repositories
│── gen
│── infrastructure
│   │── datasource
│   │── repositories
│── injection
│── presentation
│── routing
│── theme
│── utils
│── app.dart
│── bootstrap.dart
│── main.dart

💻 Install Template

  1. First you need to install copy_template to generate project based on name
dart pub global activate copy_template
  1. Install to specific directory on your pc with your project name
copy_template <project_name> https://github.com/yusriltakeuchi/flutter_template.git <path>

For example:

copy_template my_app https://github.com/yusriltakeuchi/flutter_template.git /Users/mac/Documents/FLUTTER_PROJECT

📦 Change Package Name

You can change the package name by running the command below

dart run change_app_package_name:main com.package.name
  1. Change name in android/app/build.gradle -> productFlavors
  2. Then change package name in utils/flavor/flavor_utils.dart

🔑 Keystore

  1. Create key.properties file in android directory with the following content:
storePassword=yourpassword
keyPassword=yourpassword
keyAlias=youralias
storeFile=yourfilelocation.jks
  1. Place your keystore .jks file in storeFile setting location

🚀 Run The Project

You can choose to run your project with various variant, currently available is dev, staging, and prod.

flutter run --flavor dev

🌓 Access Flavor Variant

You can access the flavor variant by using FlavorUtils class

flavor.current

📖 Create New Page

  1. You need to create a page on presentation directory
  2. Add the @RoutePage() annotation in your screen class, example:
@RoutePage()
class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          'Home Screen',
          style: MyTheme.style.title.copyWith(
              color: MyTheme.color.white,
              fontSize: AppSetting.setFontSize(45)
          ),
        ),
        automaticallyImplyLeading: false,
        backgroundColor: MyTheme.color.primary,
      ),
      body: BlocProvider(
        create: (context) => UserBloc()..getUsers(params: {'page': 1}),
        child: const HomeBody(),
      ),
    );
  }
}
  1. Run the make file to generate the code
make runner-build
  1. open route.dart file and add your page into routes variables.
  @override
List<AutoRoute> get routes => [
  AutoRoute(page: SplashRoute.page, initial: true),
  AutoRoute(page: HomeRoute.page),
];

🌓 Support Theme Mode

You can listen to the mode by using BlocBuilder into ThemeBloc. There are three modes available, light, dark, and system.

ℹ️ Step to Fetch Data

  1. Create Entity class in domain/entities
  2. Create APIExtension in infrastructure/datasource/base/api_datasource_ext.dart
  3. Create DataSource in infrastructure/datasource
  4. Create Abstract Class Repository in domain/repositories
  5. Create Repository Implementation in infrastructure/repositories
  6. Inject DataSource & Repository in injection
  7. Create Bloc Cubit in bloc
  8. Create Pages in presentation

📁 File Template IntelliJ

You can use the file template to generate the file quickly. It's available to create Entity, DTO and Bloc Cubit.

➡️ File Template

How to install:

  1. Download the file template
  2. Open IntelliJ IDEA
  3. Go to File -> Manage IDE Settings -> Import Settings...
  4. Choose the file template that you have downloaded
  5. Create new file and you will see the following options.

📦 My Flutter Package

♻️ assets_cleaner - A command-line tool wich helps you to clean your assets folder. It will remove all files that are not used in your project.

About

Template for creating new flutter project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published