Skip to content

neebs2021/flutter_getx_clean_architecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Flutter GetX Clean Architecture Template

A comprehensive Flutter project template featuring GetX state management, Go Router for navigation, and clean architecture principles with modular feature-based organization. Inspired by flutter_riverpod_clean_architecture.

πŸš€ Features

  • GetX State Management: Reactive state management with dependency injection
  • Go Router Navigation: Type-safe routing with deep linking support
  • Clean Architecture: Separation of concerns with domain-driven design
  • Modular Structure: Feature-based organization for scalability
  • Error Handling: Comprehensive error management with Result types
  • HTTP Client: Dio-based HTTP client with interceptors
  • JSON Serialization: Built-in support for json_serializable
  • Local Storage: GetStorage integration for persistent data
  • Theme System: Complete light/dark theme implementation
  • Code Generation: Automated feature scaffolding and app renaming scripts

πŸ“ Project Structure

lib/
β”œβ”€β”€ config/                 # App configuration
β”‚   β”œβ”€β”€ router_config.dart          # Go Router setup
β”‚   β”œβ”€β”€ routes_constants.dart       # Route path constants
β”‚   └── service_locator.dart        # GetX dependency injection
β”œβ”€β”€ core/                   # Core utilities and constants
β”‚   β”œβ”€β”€ constants/
β”‚   β”‚   β”œβ”€β”€ app_dimensions.dart     # Dimension constants
β”‚   β”‚   └── app_strings.dart        # String constants
β”‚   β”œβ”€β”€ datasources/
β”‚   β”‚   β”œβ”€β”€ local/                  # Local data sources
β”‚   β”‚   └── remote/                 # Remote data sources
β”‚   β”‚       β”œβ”€β”€ http_client.dart    # Shared HTTP client
β”‚   β”‚       └── remote_database.dart # Remote database client
β”‚   β”œβ”€β”€ errors/
β”‚   β”‚   β”œβ”€β”€ exceptions.dart         # Custom exceptions
β”‚   β”‚   └── failures.dart           # Failure types
β”‚   β”œβ”€β”€ models/             # Shared models
β”‚   β”œβ”€β”€ repositories/       # Shared repositories
β”‚   └── utils/
β”‚       └── result.dart             # Result type for success/failure
β”œβ”€β”€ features/               # Feature modules
β”‚   └── home/               # Home feature example
β”‚       β”œβ”€β”€ data/
β”‚       β”‚   β”œβ”€β”€ datasources/        # Feature-specific data sources
β”‚       β”‚   β”œβ”€β”€ models/            # Feature-specific models
β”‚       β”‚   └── repositories/      # Feature repository implementations
β”‚       β”œβ”€β”€ domain/
β”‚       β”‚   β”œβ”€β”€ entities/          # Feature business objects
β”‚       β”‚   β”œβ”€β”€ repositories/      # Feature repository contracts
β”‚       β”‚   └── usecases/          # Feature business logic
β”‚       └── presentation/
β”‚           β”œβ”€β”€ controllers/       # Feature GetX controllers
β”‚           β”œβ”€β”€ pages/            # Feature pages
β”‚           └── widgets/          # Feature widgets
β”œβ”€β”€ theme/                  # Theme configuration
β”‚   β”œβ”€β”€ colors.dart                # App color palette
β”‚   β”œβ”€β”€ light_theme.dart           # Light theme definition
β”‚   β”œβ”€β”€ dark_theme.dart            # Dark theme definition
β”‚   └── src/                       # Theme components
└── main.dart              # App entry point

πŸ› οΈ Getting Started

Prerequisites

  • Flutter SDK (^3.9.2)
  • Dart SDK (bundled with Flutter)

Installation

  1. Clone the repository

    git clone https://github.com/neebs2021/flutter_getx_clean_architecture
    cd flutter_getx_clean_architecture
  2. Install dependencies

    flutter pub get
  3. Generate code (for json_serializable models)

    flutter pub run build_runner build --delete-conflicting-outputs
  4. Run the app

    flutter run

πŸ—οΈ Architecture Overview

Clean Architecture Layers

  1. Presentation Layer (UI)

    • GetX controllers for reactive state management
    • Flutter widgets and pages
    • User interaction handling
  2. Domain Layer (Business Logic)

    • Business entities and rules
    • Use cases for application logic
    • Repository contracts (interfaces)
  3. Data Layer (External Interfaces)

    • Repository implementations
    • Data sources (API, local storage)
    • Model-to-entity mapping

Feature-Based Organization

Each feature is self-contained with its own:

  • Data layer: Models, repositories, data sources
  • Domain layer: Entities, use cases, repository contracts
  • Presentation layer: Controllers, pages, widgets

πŸ“¦ Dependencies

Core Dependencies

  • get: ^4.6.6 - State management and dependency injection
  • go_router: ^14.0.0 - Declarative routing
  • dio: ^5.3.0 - HTTP client
  • get_storage: ^2.1.1 - Local storage
  • json_annotation: ^4.8.1 - JSON serialization

Development Dependencies

  • flutter_lints: ^5.0.0 - Linting rules
  • build_runner: ^2.4.7 - Code generation
  • json_serializable: ^6.7.1 - JSON serialization

πŸ› οΈ Utility Scripts

Generate Feature Script

The generate_feature.sh script helps you quickly scaffold new features following the clean architecture pattern.

# Make script executable (first time only)
chmod +x generate_feature.sh

# Generate a full feature with clean architecture
./generate_feature.sh --name user_profile

# Generate a basic feature without repository pattern
./generate_feature.sh --name theme_switcher --basic

# Generate UI components only
./generate_feature.sh --name custom_button --component-only

# Generate service logic only
./generate_feature.sh --name data_manager --logic-only

# Skip UI generation
./generate_feature.sh --name api_service --skip-ui

Options:

  • --name <feature_name>: Feature name in snake_case (required)
  • --skip-ui: Skip UI/presentation layer generation
  • --basic: Use basic structure without repository pattern
  • --component-only: Generate UI components only
  • --logic-only: Generate service logic only

Rename App Script

The rename_app.sh script updates app names and bundle identifiers across all platforms.

# Make script executable (first time only)
chmod +x rename_app.sh

# Rename the app
./rename_app.sh --display-name "My Amazing App" --bundle-id com.mycompany.amazingapp

Options:

  • --display-name "App Name": New app display name (required)
  • --bundle-id com.example.app: New bundle/package identifier (required)

What it updates:

  • Android: strings.xml, build.gradle, AndroidManifest.xml
  • iOS: Info.plist, project.pbxproj
  • macOS: Info.plist, project.pbxproj
  • Windows: CMakeLists.txt, runner.rc
  • Linux: CMakeLists.txt, my_application.cc
  • Web: index.html, manifest.json
  • pubspec.yaml: name and description
  • Dart imports: Updates package references

🎯 Key Concepts

State Management with GetX

class HomeController extends GetxController {
  final count = 0.obs;
  final isLoading = false.obs;

  void increment() => count.value++;
}

// In UI
Obx(() => Text('Count: ${controller.count.value}'))

Navigation with Go Router

// Define routes
final appRouter = GoRouter(
  initialLocation: '/home',
  routes: [
    GoRoute(
      path: '/home',
      builder: (context, state) => const HomePage(),
    ),
  ],
);

// Navigate
context.go('/home');

Error Handling with Result Type

Future<Result<User>> getUser(int id) async {
  try {
    final user = await repository.getUser(id);
    return Success(user);
  } catch (e) {
    return Failure_(NetworkFailure(message: e.toString()));
  }
}

// Usage
result.when(
  success: (user) => print('User: $user'),
  failure: (error) => print('Error: $error'),
);

Dependency Injection with GetX

class ServiceLocator {
  static void init() {
    // Register dependencies
    Get.lazyPut(() => Dio());
    Get.lazyPut(() => GetStorage());
    Get.lazyPut<HomeRepository>(() => HomeRepositoryImpl());
  }
}

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request## πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


About

Flutter GetX Clean Architecture Template

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published