Skip to content

ilham25/flutter_boilerplate

Repository files navigation

Flutter Boilerplate

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

👨‍🔧 Cloned from flutter_template repository created by Yusril Rapsanjani and modified to include UI Kit and also use updated dependencies.

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.38.3

➡️ Dart 3.10.1

🔨 Project Structure

lib
│── bloc
│── config
│── core
│   │── widgets
│   │── 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/ilham25/flutter_boilerplate.git <path>

For example:

copy_template my_app https://github.com/ilham25/flutter_boilerplate.git /path/to/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
dart run build_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

About

Flutter Boilerplate with custom UI Kit Included

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published