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.
- 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
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
- Flutter SDK (^3.9.2)
- Dart SDK (bundled with Flutter)
-
Clone the repository
git clone https://github.com/neebs2021/flutter_getx_clean_architecture cd flutter_getx_clean_architecture -
Install dependencies
flutter pub get
-
Generate code (for json_serializable models)
flutter pub run build_runner build --delete-conflicting-outputs
-
Run the app
flutter run
-
Presentation Layer (UI)
- GetX controllers for reactive state management
- Flutter widgets and pages
- User interaction handling
-
Domain Layer (Business Logic)
- Business entities and rules
- Use cases for application logic
- Repository contracts (interfaces)
-
Data Layer (External Interfaces)
- Repository implementations
- Data sources (API, local storage)
- Model-to-entity mapping
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
- 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
- flutter_lints: ^5.0.0 - Linting rules
- build_runner: ^2.4.7 - Code generation
- json_serializable: ^6.7.1 - JSON serialization
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-uiOptions:
--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
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.amazingappOptions:
--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
class HomeController extends GetxController {
final count = 0.obs;
final isLoading = false.obs;
void increment() => count.value++;
}
// In UI
Obx(() => Text('Count: ${controller.count.value}'))// Define routes
final appRouter = GoRouter(
initialLocation: '/home',
routes: [
GoRoute(
path: '/home',
builder: (context, state) => const HomePage(),
),
],
);
// Navigate
context.go('/home');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'),
);class ServiceLocator {
static void init() {
// Register dependencies
Get.lazyPut(() => Dio());
Get.lazyPut(() => GetStorage());
Get.lazyPut<HomeRepository>(() => HomeRepositoryImpl());
}
}- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request## π License
This project is licensed under the MIT License - see the LICENSE file for details.
This project is licensed under the MIT License - see the LICENSE file for details.
This project is licensed under the MIT License - see the LICENSE file for details.
- GetX - State management library
- Go Router - Routing package
- Clean Architecture - Architectural pattern
- flutter_riverpod_clean_architecture - Inspiration for clean architecture implementation
This project is licensed under the MIT License - see the LICENSE file for details.