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.