A comprehensive Flutter project demonstrating MVC (Model-View-Controller) architecture with GetX state management.
lib/
├── app/
│ ├── bindings/ # Dependency injection bindings
│ │ └── initial_binding.dart
│ ├── data/ # Data layer
│ │ ├── models/ # Data models
│ │ │ ├── user.dart
│ │ │ ├── product.dart
│ │ │ ├── order.dart
│ │ │ └── profile.dart
│ │ ├── providers/ # API providers
│ │ │ └── api_provider.dart
│ │ └── repositories/ # Data repositories
│ │ ├── auth_repository.dart
│ │ ├── product_repository.dart
│ │ ├── order_repository.dart
│ │ └── profile_repository.dart
│ ├── middlewares/ # Route middlewares
│ │ └── auth_middleware.dart
│ ├── modules/ # Feature modules
│ │ ├── auth/ # Authentication module
│ │ │ ├── login_binding.dart
│ │ │ ├── login_controller.dart
│ │ │ └── login_view.dart
│ │ ├── home/ # Home module
│ │ │ ├── home_binding.dart
│ │ │ ├── home_controller.dart
│ │ │ └── home_view.dart
│ │ ├── products/ # Products module
│ │ │ ├── products_binding.dart
│ │ │ ├── products_controller.dart
│ │ │ └── products_view.dart
│ │ ├── orders/ # Orders module
│ │ │ ├── orders_binding.dart
│ │ │ ├── orders_controller.dart
│ │ │ └── orders_view.dart
│ │ └── profile/ # Profile module
│ │ ├── profile_binding.dart
│ │ ├── profile_controller.dart
│ │ └── profile_view.dart
│ ├── routes/ # App routing
│ │ ├── app_pages.dart
│ │ └── app_routes.dart
│ ├── services/ # Business logic services
│ │ └── auth_service.dart
│ ├── theme/ # App theming
│ │ └── app_theme.dart
│ └── utils/ # Utility functions
│ └── validators.dart
└── main.dart # App entry pointThis project follows the Model-View-Controller pattern enhanced with GetX for state management:
- Model: Data models and repositories in the
data/folder - View: UI components in the
modules/*/views/folders - Controller: Business logic in the
modules/*/controllers/folders
- Dependency injection setup for each module
- Manages the lifecycle of controllers and services
- Models: Data structures with JSON serialization
- Providers: HTTP client for API communication
- Repositories: Data access abstraction layer
- Feature-based organization
- Each module contains its own MVC components
- Self-contained with bindings, controllers, and views
- Business logic that spans multiple modules
- Authentication, notifications, etc.
- Centralized routing configuration
- Route guards and middleware support
- User login/logout
- Route protection with middleware
- Session management
- Dashboard with navigation
- Bottom navigation bar
- Module overview
- Product listing with search
- Category filtering
- Product details
- Order management
- Status tracking
- Order history
- User profile management
- Editable form fields
- Avatar handling
- get: ^4.6.6 - State management and routing
- http: ^1.1.0 - HTTP client for API calls
- very_good_analysis: ^9.0.0 - Comprehensive code analysis and linting
1.Create the module folder structure:
lib/app/modules/new_feature/
├── new_feature_binding.dart
├── new_feature_controller.dart
└── new_feature_view.dart2.Add the binding:
class NewFeatureBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<NewFeatureController>(() => NewFeatureController());
}
}3.Create the controller:
class NewFeatureController extends GetxController {
final _data = ''.obs;
String get data => _data.value;
void updateData(String value) => _data.value = value;
}4.Build the view:
class NewFeatureView extends GetView<NewFeatureController> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('New Feature')),
body: Center(
child: Obx(() => Text(controller.data)),
),
);
}
}5.Add to routes:
GetPage(
name: '/new-feature',
page: () => NewFeatureView(),
binding: NewFeatureBinding(),
),class ExampleController extends GetxController {
final _count = 0.obs;
int get count => _count.value;
void increment() => _count.value++;
void decrement() => _count.value--;
}Obx(() => Text('Count: ${controller.count}'))- Keep modules self-contained
- Use consistent naming conventions
- Separate concerns (UI, logic, data)
- Use
.obsfor reactive variables - Keep controllers focused and lightweight
- Avoid business logic in views
- Implement proper error handling in repositories
- Show user-friendly error messages
- Log errors for debugging
- Use
Get.lazyPut()for lazy loading - Implement proper disposal in controllers
- Optimize list views with
ListView.builder
This project is licensed under the MIT License - see the LICENSE file for details.