This commit is contained in:
Phuoc Nguyen
2025-10-10 17:36:10 +07:00
parent 04f7042b8d
commit bdaf0b96c5
82 changed files with 4753 additions and 329 deletions

View File

@@ -0,0 +1,340 @@
# Barrel Exports Quick Reference
## Quick Import Guide
### Complete Feature Import
```dart
// Import entire auth feature (all layers)
import 'package:retail/features/auth/auth.dart';
// Import entire products feature
import 'package:retail/features/products/products.dart';
// Import entire categories feature
import 'package:retail/features/categories/categories.dart';
// Import entire home/cart feature
import 'package:retail/features/home/home.dart';
// Import entire settings feature
import 'package:retail/features/settings/settings.dart';
// Import ALL features at once
import 'package:retail/features/features.dart';
```
### Layer-Specific Imports
```dart
// Auth layers
import 'package:retail/features/auth/data/data.dart'; // Data layer only
import 'package:retail/features/auth/domain/domain.dart'; // Domain layer only
import 'package:retail/features/auth/presentation/presentation.dart'; // Presentation only
// Products layers
import 'package:retail/features/products/data/data.dart';
import 'package:retail/features/products/domain/domain.dart';
import 'package:retail/features/products/presentation/presentation.dart';
// Categories layers
import 'package:retail/features/categories/data/data.dart';
import 'package:retail/features/categories/domain/domain.dart';
import 'package:retail/features/categories/presentation/presentation.dart';
// Home/Cart layers
import 'package:retail/features/home/data/data.dart';
import 'package:retail/features/home/domain/domain.dart';
import 'package:retail/features/home/presentation/presentation.dart';
// Settings layers
import 'package:retail/features/settings/data/data.dart';
import 'package:retail/features/settings/domain/domain.dart';
import 'package:retail/features/settings/presentation/presentation.dart';
```
### Component-Specific Imports
```dart
// Models
import 'package:retail/features/products/data/models/models.dart';
import 'package:retail/features/auth/data/models/models.dart';
// Entities
import 'package:retail/features/products/domain/entities/entities.dart';
import 'package:retail/features/home/domain/entities/entities.dart';
// Use Cases
import 'package:retail/features/products/domain/usecases/usecases.dart';
import 'package:retail/features/categories/domain/usecases/usecases.dart';
// Providers
import 'package:retail/features/products/presentation/providers/providers.dart';
import 'package:retail/features/home/presentation/providers/providers.dart';
// Pages
import 'package:retail/features/products/presentation/pages/pages.dart';
import 'package:retail/features/auth/presentation/pages/pages.dart';
// Widgets
import 'package:retail/features/products/presentation/widgets/widgets.dart';
import 'package:retail/features/auth/presentation/widgets/widgets.dart';
```
### Core Utilities
```dart
// All core utilities
import 'package:retail/core/core.dart';
// Specific core modules
import 'package:retail/core/constants/constants.dart'; // All constants
import 'package:retail/core/theme/theme.dart'; // Theme configuration
import 'package:retail/core/network/network.dart'; // HTTP & network
import 'package:retail/core/errors/errors.dart'; // Exceptions & failures
import 'package:retail/core/utils/utils.dart'; // Utilities & helpers
import 'package:retail/core/di/di.dart'; // Dependency injection
import 'package:retail/core/database/database.dart'; // Hive database
import 'package:retail/core/storage/storage.dart'; // Secure storage
import 'package:retail/core/widgets/widgets.dart'; // Core widgets
```
### Shared Components
```dart
// Shared widgets and components
import 'package:retail/shared/shared.dart';
```
## Common Use Cases
### Building a Page
```dart
// In a page file, you typically need presentation layer
import 'package:retail/features/products/presentation/presentation.dart';
// This gives you: pages, widgets, providers
```
### Implementing a Repository
```dart
// In repository implementation, import domain interfaces
import 'package:retail/features/products/domain/domain.dart';
// This gives you: entities, repository interfaces, use cases
```
### Creating a Provider
```dart
// In a provider, import domain layer and other providers
import 'package:retail/features/products/domain/domain.dart';
import 'package:retail/features/products/presentation/providers/providers.dart';
```
### Using Multiple Features
```dart
// When you need multiple features
import 'package:retail/features/products/products.dart';
import 'package:retail/features/categories/categories.dart';
import 'package:retail/core/core.dart';
```
## Layer Dependencies (Important!)
### Allowed Dependencies
```
Presentation Layer:
✅ Can import: domain, core, shared
❌ Cannot import: data
Data Layer:
✅ Can import: domain, core
❌ Cannot import: presentation
Domain Layer:
✅ Can import: core (only exceptions/interfaces)
❌ Cannot import: data, presentation
Core:
✅ Can import: nothing (self-contained)
❌ Cannot import: features
Shared:
✅ Can import: core
❌ Cannot import: features (to avoid circular dependencies)
```
### Example: Correct Dependencies
```dart
// ✅ GOOD: Presentation imports domain
// In: features/products/presentation/pages/products_page.dart
import 'package:retail/features/products/domain/domain.dart';
import 'package:retail/core/core.dart';
// ✅ GOOD: Data imports domain
// In: features/products/data/repositories/product_repository_impl.dart
import 'package:retail/features/products/domain/domain.dart';
import 'package:retail/core/core.dart';
// ✅ GOOD: Domain is independent
// In: features/products/domain/entities/product.dart
import 'package:retail/core/errors/errors.dart'; // Only core exceptions
// ❌ BAD: Domain importing data or presentation
// In: features/products/domain/usecases/get_products.dart
import 'package:retail/features/products/data/data.dart'; // NEVER!
import 'package:retail/features/products/presentation/presentation.dart'; // NEVER!
```
## Import Decision Tree
```
1. Do I need the entire feature?
├─ Yes → import 'features/[feature]/[feature].dart'
└─ No → Continue to 2
2. Do I need an entire layer?
├─ Yes → import 'features/[feature]/[layer]/[layer].dart'
└─ No → Continue to 3
3. Do I need specific components?
└─ Yes → import 'features/[feature]/[layer]/[component]/[component].dart'
4. Is it a core utility?
├─ All utilities → import 'core/core.dart'
└─ Specific module → import 'core/[module]/[module].dart'
5. Is it a shared component?
└─ Yes → import 'shared/shared.dart'
```
## Migration from Direct Imports
### Before (Direct Imports - Fragile)
```dart
import 'package:retail/features/products/data/models/product_model.dart';
import 'package:retail/features/products/data/datasources/product_local_datasource.dart';
import 'package:retail/features/products/data/repositories/product_repository_impl.dart';
import 'package:retail/features/products/domain/entities/product.dart';
import 'package:retail/features/products/domain/repositories/product_repository.dart';
import 'package:retail/features/products/presentation/pages/products_page.dart';
import 'package:retail/features/products/presentation/widgets/product_card.dart';
import 'package:retail/features/products/presentation/widgets/product_grid.dart';
import 'package:retail/core/constants/api_constants.dart';
import 'package:retail/core/theme/colors.dart';
```
### After (Barrel Imports - Clean & Maintainable)
```dart
import 'package:retail/features/products/products.dart';
import 'package:retail/core/core.dart';
```
## Special Notes
### Products Providers
The products feature has all providers consolidated in `products_provider.dart`:
```dart
// Import all product providers at once
import 'package:retail/features/products/presentation/providers/providers.dart';
// This includes:
// - productsProvider (list of products)
// - searchQueryProvider (search state)
// - filteredProductsProvider (filtered results)
```
### Selected Category Provider
The `selectedCategoryProvider` exists in multiple places:
- In `categories_provider.dart` (for category management)
- In `products/selected_category_provider.dart` (for product filtering)
Use the one from products when filtering products:
```dart
import 'package:retail/features/products/presentation/providers/providers.dart';
// Use: selectedCategoryProvider for product filtering
```
### Core Providers
Core providers are in `core/providers/providers.dart`:
```dart
import 'package:retail/core/providers/providers.dart';
// Includes: networkInfoProvider, syncStatusProvider
```
## Tips for Best Practices
1. **Start broad, narrow down if needed**
- Try feature-level import first
- Move to layer-level if you only need one layer
- Use component-level for very specific needs
2. **Avoid circular dependencies**
- Domain never imports from data/presentation
- Features don't import from each other (use shared instead)
3. **Use IDE autocomplete**
- Type `import 'package:retail/` and let IDE suggest
- Barrel exports will show up clearly
4. **Keep imports organized**
```dart
// 1. Dart/Flutter imports
import 'package:flutter/material.dart';
// 2. Third-party packages
import 'package:riverpod_annotation/riverpod_annotation.dart';
// 3. Project features
import 'package:retail/features/products/products.dart';
// 4. Core utilities
import 'package:retail/core/core.dart';
// 5. Shared components
import 'package:retail/shared/shared.dart';
```
5. **Update barrel exports when adding files**
- Added new model? Update `models/models.dart`
- Added new page? Update `pages/pages.dart`
- New use case? Update `usecases/usecases.dart`
## File Locations Reference
```
Core Barrel Exports:
/lib/core/core.dart
/lib/core/config/config.dart
/lib/core/constants/constants.dart
/lib/core/database/database.dart
/lib/core/di/di.dart
/lib/core/errors/errors.dart
/lib/core/network/network.dart
/lib/core/storage/storage.dart
/lib/core/theme/theme.dart
/lib/core/utils/utils.dart
Feature Barrel Exports:
/lib/features/features.dart
/lib/features/auth/auth.dart
/lib/features/products/products.dart
/lib/features/categories/categories.dart
/lib/features/home/home.dart
/lib/features/settings/settings.dart
Shared Barrel Exports:
/lib/shared/shared.dart
```
## Quick Command Reference
```bash
# Find all barrel export files
find lib -name "*.dart" -type f | grep -E "\/(data|domain|presentation|entities|models|usecases|providers|pages|widgets|datasources|constants|errors|network|storage|theme|utils|di|config|database)\.dart$"
# Check for ambiguous exports
flutter analyze | grep "ambiguous_export"
# Verify imports compile
flutter analyze
```
---
**Remember:** Barrel exports make your code cleaner, more maintainable, and easier to refactor!

View File

@@ -0,0 +1,500 @@
# Clean Architecture Export Files Documentation
This document describes all barrel export files created for the retail POS application, following clean architecture principles.
## Overview
Barrel export files provide a clean, organized way to import code by:
- Simplifying imports across the codebase
- Enforcing layer separation and boundaries
- Making refactoring easier
- Improving IDE autocomplete
- Documenting module structure
## File Structure
```
lib/
├── core/
│ ├── core.dart # Main core export
│ ├── config/
│ │ └── config.dart # Configuration exports
│ ├── constants/
│ │ └── constants.dart # All constants
│ ├── database/
│ │ └── database.dart # Database utilities
│ ├── di/
│ │ └── di.dart # Dependency injection
│ ├── errors/
│ │ └── errors.dart # Exceptions & failures
│ ├── network/
│ │ └── network.dart # HTTP & network
│ ├── storage/
│ │ └── storage.dart # Secure storage
│ ├── theme/
│ │ └── theme.dart # Material 3 theme
│ ├── utils/
│ │ └── utils.dart # Utilities & helpers
│ └── widgets/
│ └── widgets.dart # Core widgets (already exists)
├── features/
│ ├── features.dart # Main features export
│ ├── auth/
│ │ ├── auth.dart # Main auth export
│ │ ├── data/
│ │ │ ├── data.dart # Auth data layer
│ │ │ ├── datasources/
│ │ │ └── models/
│ │ │ └── models.dart # Auth models
│ │ ├── domain/
│ │ │ ├── domain.dart # Auth domain layer
│ │ │ └── entities/
│ │ │ └── entities.dart # Auth entities
│ │ └── presentation/
│ │ ├── presentation.dart # Auth presentation layer
│ │ ├── pages/
│ │ │ └── pages.dart # Auth pages
│ │ └── widgets/
│ │ └── widgets.dart # Auth widgets
│ ├── categories/
│ │ ├── categories.dart # Main categories export
│ │ ├── data/
│ │ │ ├── data.dart # Categories data layer
│ │ │ ├── datasources/
│ │ │ │ └── datasources.dart # Category data sources
│ │ │ └── models/
│ │ │ └── models.dart # Category models
│ │ ├── domain/
│ │ │ ├── domain.dart # Categories domain layer
│ │ │ ├── entities/
│ │ │ │ └── entities.dart # Category entities
│ │ │ └── usecases/
│ │ │ └── usecases.dart # Category use cases
│ │ └── presentation/
│ │ ├── presentation.dart # Categories presentation layer
│ │ ├── pages/
│ │ │ └── pages.dart # Category pages
│ │ ├── providers/
│ │ │ └── providers.dart # Category providers (already exists)
│ │ └── widgets/
│ │ └── widgets.dart # Category widgets (already exists)
│ ├── home/
│ │ ├── home.dart # Main home/cart export
│ │ ├── data/
│ │ │ ├── data.dart # Cart data layer
│ │ │ ├── datasources/
│ │ │ │ └── datasources.dart # Cart data sources
│ │ │ └── models/
│ │ │ └── models.dart # Cart models
│ │ ├── domain/
│ │ │ ├── domain.dart # Cart domain layer
│ │ │ ├── entities/
│ │ │ │ └── entities.dart # Cart entities
│ │ │ └── usecases/
│ │ │ └── usecases.dart # Cart use cases
│ │ └── presentation/
│ │ ├── presentation.dart # Cart presentation layer
│ │ ├── pages/
│ │ │ └── pages.dart # Cart pages
│ │ ├── providers/
│ │ │ └── providers.dart # Cart providers (already exists)
│ │ └── widgets/
│ │ └── widgets.dart # Cart widgets (already exists)
│ ├── products/
│ │ ├── products.dart # Main products export
│ │ ├── data/
│ │ │ ├── data.dart # Products data layer
│ │ │ ├── datasources/
│ │ │ │ └── datasources.dart # Product data sources
│ │ │ └── models/
│ │ │ └── models.dart # Product models
│ │ ├── domain/
│ │ │ ├── domain.dart # Products domain layer
│ │ │ ├── entities/
│ │ │ │ └── entities.dart # Product entities
│ │ │ └── usecases/
│ │ │ └── usecases.dart # Product use cases
│ │ └── presentation/
│ │ ├── presentation.dart # Products presentation layer
│ │ ├── pages/
│ │ │ └── pages.dart # Product pages
│ │ ├── providers/
│ │ │ └── providers.dart # Product providers
│ │ └── widgets/
│ │ └── widgets.dart # Product widgets (already exists)
│ └── settings/
│ ├── settings.dart # Main settings export
│ ├── data/
│ │ ├── data.dart # Settings data layer
│ │ ├── datasources/
│ │ │ └── datasources.dart # Settings data sources
│ │ └── models/
│ │ └── models.dart # Settings models
│ ├── domain/
│ │ ├── domain.dart # Settings domain layer
│ │ ├── entities/
│ │ │ └── entities.dart # Settings entities
│ │ └── usecases/
│ │ └── usecases.dart # Settings use cases
│ └── presentation/
│ ├── presentation.dart # Settings presentation layer
│ ├── pages/
│ │ └── pages.dart # Settings pages
│ ├── providers/
│ │ └── providers.dart # Settings providers (already exists)
│ └── widgets/
│ └── widgets.dart # Settings widgets
└── shared/
└── shared.dart # Shared components export
```
## Usage Examples
### 1. Importing Entire Features
```dart
// Import complete auth feature (all layers)
import 'package:retail/features/auth/auth.dart';
// Import complete products feature
import 'package:retail/features/products/products.dart';
// Import all features at once
import 'package:retail/features/features.dart';
```
### 2. Importing Specific Layers
```dart
// Import only auth domain layer (entities + repositories)
import 'package:retail/features/auth/domain/domain.dart';
// Import only products presentation layer (pages + widgets + providers)
import 'package:retail/features/products/presentation/presentation.dart';
// Import only cart data layer
import 'package:retail/features/home/data/data.dart';
```
### 3. Importing Specific Components
```dart
// Import only auth entities
import 'package:retail/features/auth/domain/entities/entities.dart';
// Import only product models
import 'package:retail/features/products/data/models/models.dart';
// Import only category use cases
import 'package:retail/features/categories/domain/usecases/usecases.dart';
// Import only product providers
import 'package:retail/features/products/presentation/providers/providers.dart';
```
### 4. Importing Core Utilities
```dart
// Import all core utilities
import 'package:retail/core/core.dart';
// Import only constants
import 'package:retail/core/constants/constants.dart';
// Import only theme
import 'package:retail/core/theme/theme.dart';
// Import only network utilities
import 'package:retail/core/network/network.dart';
// Import only error handling
import 'package:retail/core/errors/errors.dart';
```
### 5. Importing Shared Components
```dart
// Import shared widgets
import 'package:retail/shared/shared.dart';
```
## Clean Architecture Benefits
### Layer Isolation
The export structure enforces clean architecture principles:
```dart
// ✅ GOOD: Domain layer importing from domain
import 'package:retail/features/products/domain/domain.dart';
// ❌ BAD: Domain layer importing from data/presentation
// Domain should never depend on outer layers
import 'package:retail/features/products/data/data.dart';
```
### Dependency Flow
Dependencies flow inward:
- **Presentation** → Domain ← Data
- **Data** → Domain (implements interfaces)
- **Domain** → Independent (pure business logic)
```dart
// In presentation layer - ✅ GOOD
import 'package:retail/features/products/domain/domain.dart';
// In data layer - ✅ GOOD
import 'package:retail/features/products/domain/domain.dart';
// In domain layer - ❌ NEVER
// import 'package:retail/features/products/data/data.dart';
// import 'package:retail/features/products/presentation/presentation.dart';
```
## Feature Export Hierarchy
Each feature follows this export hierarchy:
```
feature.dart # Top-level feature export
├── data/data.dart # Data layer export
│ ├── datasources/datasources.dart
│ ├── models/models.dart
│ └── repositories/ # Implementations (exported directly)
├── domain/domain.dart # Domain layer export
│ ├── entities/entities.dart
│ ├── repositories/ # Interfaces (exported directly)
│ └── usecases/usecases.dart
└── presentation/presentation.dart # Presentation layer export
├── pages/pages.dart
├── providers/providers.dart
└── widgets/widgets.dart
```
## Import Guidelines
### DO's
1. **Import at the appropriate level**
```dart
// If you need the entire feature
import 'package:retail/features/auth/auth.dart';
// If you only need domain entities
import 'package:retail/features/auth/domain/entities/entities.dart';
```
2. **Use barrel exports for cleaner code**
```dart
// ✅ Clean and maintainable
import 'package:retail/features/products/presentation/presentation.dart';
// ❌ Messy and fragile
import 'package:retail/features/products/presentation/pages/products_page.dart';
import 'package:retail/features/products/presentation/widgets/product_card.dart';
import 'package:retail/features/products/presentation/widgets/product_grid.dart';
import 'package:retail/features/products/presentation/providers/products_provider.dart';
```
3. **Respect layer boundaries**
```dart
// In a use case (domain layer)
import 'package:retail/features/products/domain/domain.dart'; // ✅
import 'package:retail/core/core.dart'; // ✅ (core is shared)
```
### DON'Ts
1. **Don't bypass barrel exports**
```dart
// ❌ Bypasses barrel export
import 'package:retail/features/products/data/models/product_model.dart';
// ✅ Use barrel export
import 'package:retail/features/products/data/models/models.dart';
```
2. **Don't violate layer dependencies**
```dart
// In domain layer
// ❌ Domain depends on outer layers
import 'package:retail/features/products/data/data.dart';
import 'package:retail/features/products/presentation/presentation.dart';
```
3. **Don't import entire feature when you need one layer**
```dart
// ❌ Over-importing
import 'package:retail/features/products/products.dart'; // Imports all layers
// When you only need:
import 'package:retail/features/products/domain/entities/entities.dart';
```
## Benefits Summary
### 1. Clean Imports
Before:
```dart
import 'package:retail/features/products/data/models/product_model.dart';
import 'package:retail/features/products/domain/entities/product.dart';
import 'package:retail/features/products/domain/repositories/product_repository.dart';
import 'package:retail/features/products/presentation/pages/products_page.dart';
import 'package:retail/features/products/presentation/widgets/product_card.dart';
import 'package:retail/features/products/presentation/widgets/product_grid.dart';
```
After:
```dart
import 'package:retail/features/products/products.dart';
```
### 2. Layer Isolation
- Domain layer never imports from data/presentation
- Each layer has clear boundaries
- Enforces dependency inversion
### 3. Easy Refactoring
- Change internal structure without breaking imports
- Move files within a layer without updating imports
- Rename files without affecting external code
### 4. Better IDE Support
- Autocomplete shows only exported items
- Easier to navigate code structure
- Clear module boundaries
### 5. Documentation
- Export files serve as documentation
- Shows what's public vs private
- Makes architecture explicit
## Migration Guide
If you have existing imports, migrate them gradually:
### Step 1: Update feature-level imports
```dart
// Old
import 'package:retail/features/products/presentation/pages/products_page.dart';
// New
import 'package:retail/features/products/presentation/pages/pages.dart';
```
### Step 2: Consolidate layer imports
```dart
// Old
import 'package:retail/features/products/presentation/pages/pages.dart';
import 'package:retail/features/products/presentation/widgets/widgets.dart';
import 'package:retail/features/products/presentation/providers/providers.dart';
// New
import 'package:retail/features/products/presentation/presentation.dart';
```
### Step 3: Use top-level feature import when appropriate
```dart
// If you need multiple layers
import 'package:retail/features/products/products.dart';
```
## Complete File List
Total export files created: **54 files**
### Core Module (10 files)
1. `/Users/ssg/project/retail/lib/core/core.dart`
2. `/Users/ssg/project/retail/lib/core/config/config.dart`
3. `/Users/ssg/project/retail/lib/core/constants/constants.dart`
4. `/Users/ssg/project/retail/lib/core/database/database.dart`
5. `/Users/ssg/project/retail/lib/core/di/di.dart`
6. `/Users/ssg/project/retail/lib/core/errors/errors.dart`
7. `/Users/ssg/project/retail/lib/core/network/network.dart`
8. `/Users/ssg/project/retail/lib/core/storage/storage.dart`
9. `/Users/ssg/project/retail/lib/core/theme/theme.dart`
10. `/Users/ssg/project/retail/lib/core/utils/utils.dart`
### Auth Feature (8 files)
11. `/Users/ssg/project/retail/lib/features/auth/auth.dart`
12. `/Users/ssg/project/retail/lib/features/auth/data/data.dart`
13. `/Users/ssg/project/retail/lib/features/auth/data/models/models.dart`
14. `/Users/ssg/project/retail/lib/features/auth/domain/domain.dart`
15. `/Users/ssg/project/retail/lib/features/auth/domain/entities/entities.dart`
16. `/Users/ssg/project/retail/lib/features/auth/presentation/presentation.dart`
17. `/Users/ssg/project/retail/lib/features/auth/presentation/pages/pages.dart`
18. `/Users/ssg/project/retail/lib/features/auth/presentation/widgets/widgets.dart` *(updated by flutter expert)*
### Products Feature (10 files)
19. `/Users/ssg/project/retail/lib/features/products/products.dart`
20. `/Users/ssg/project/retail/lib/features/products/data/data.dart`
21. `/Users/ssg/project/retail/lib/features/products/data/datasources/datasources.dart`
22. `/Users/ssg/project/retail/lib/features/products/data/models/models.dart`
23. `/Users/ssg/project/retail/lib/features/products/domain/domain.dart`
24. `/Users/ssg/project/retail/lib/features/products/domain/entities/entities.dart`
25. `/Users/ssg/project/retail/lib/features/products/domain/usecases/usecases.dart`
26. `/Users/ssg/project/retail/lib/features/products/presentation/presentation.dart`
27. `/Users/ssg/project/retail/lib/features/products/presentation/pages/pages.dart`
28. `/Users/ssg/project/retail/lib/features/products/presentation/providers/providers.dart`
### Categories Feature (10 files)
29. `/Users/ssg/project/retail/lib/features/categories/categories.dart`
30. `/Users/ssg/project/retail/lib/features/categories/data/data.dart`
31. `/Users/ssg/project/retail/lib/features/categories/data/datasources/datasources.dart`
32. `/Users/ssg/project/retail/lib/features/categories/data/models/models.dart`
33. `/Users/ssg/project/retail/lib/features/categories/domain/domain.dart`
34. `/Users/ssg/project/retail/lib/features/categories/domain/entities/entities.dart`
35. `/Users/ssg/project/retail/lib/features/categories/domain/usecases/usecases.dart`
36. `/Users/ssg/project/retail/lib/features/categories/presentation/presentation.dart`
37. `/Users/ssg/project/retail/lib/features/categories/presentation/pages/pages.dart`
38. `/Users/ssg/project/retail/lib/features/categories/presentation/providers/providers.dart` *(already exists)*
### Home/Cart Feature (10 files)
39. `/Users/ssg/project/retail/lib/features/home/home.dart`
40. `/Users/ssg/project/retail/lib/features/home/data/data.dart`
41. `/Users/ssg/project/retail/lib/features/home/data/datasources/datasources.dart`
42. `/Users/ssg/project/retail/lib/features/home/data/models/models.dart`
43. `/Users/ssg/project/retail/lib/features/home/domain/domain.dart`
44. `/Users/ssg/project/retail/lib/features/home/domain/entities/entities.dart`
45. `/Users/ssg/project/retail/lib/features/home/domain/usecases/usecases.dart`
46. `/Users/ssg/project/retail/lib/features/home/presentation/presentation.dart`
47. `/Users/ssg/project/retail/lib/features/home/presentation/pages/pages.dart`
48. `/Users/ssg/project/retail/lib/features/home/presentation/providers/providers.dart` *(already exists)*
### Settings Feature (10 files)
49. `/Users/ssg/project/retail/lib/features/settings/settings.dart`
50. `/Users/ssg/project/retail/lib/features/settings/data/data.dart`
51. `/Users/ssg/project/retail/lib/features/settings/data/datasources/datasources.dart`
52. `/Users/ssg/project/retail/lib/features/settings/data/models/models.dart`
53. `/Users/ssg/project/retail/lib/features/settings/domain/domain.dart`
54. `/Users/ssg/project/retail/lib/features/settings/domain/entities/entities.dart`
55. `/Users/ssg/project/retail/lib/features/settings/domain/usecases/usecases.dart`
56. `/Users/ssg/project/retail/lib/features/settings/presentation/presentation.dart`
57. `/Users/ssg/project/retail/lib/features/settings/presentation/pages/pages.dart`
58. `/Users/ssg/project/retail/lib/features/settings/presentation/providers/providers.dart` *(already exists)*
59. `/Users/ssg/project/retail/lib/features/settings/presentation/widgets/widgets.dart`
### Top-Level Exports (2 files)
60. `/Users/ssg/project/retail/lib/features/features.dart`
61. `/Users/ssg/project/retail/lib/shared/shared.dart`
### Documentation (1 file)
62. `/Users/ssg/project/retail/lib/EXPORTS_DOCUMENTATION.md`
---
## Maintenance
When adding new files to the project:
1. **New file in existing module**: Update the appropriate barrel export
2. **New module**: Create new barrel exports following the pattern
3. **Removing files**: Update barrel exports to remove deleted exports
4. **Renaming files**: Update barrel exports to reflect new names
## Support
For questions or issues with the export structure, refer to:
- This documentation
- Clean Architecture principles
- Feature-first organization patterns

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'core/theme/app_theme.dart';
import 'features/auth/presentation/presentation.dart';
import 'features/home/presentation/pages/home_page.dart';
import 'features/products/presentation/pages/products_page.dart';
import 'features/categories/presentation/pages/categories_page.dart';
@@ -8,7 +9,7 @@ import 'features/settings/presentation/pages/settings_page.dart';
import 'features/settings/presentation/providers/theme_provider.dart';
import 'shared/widgets/app_bottom_nav.dart';
/// Root application widget
/// Root application widget with authentication wrapper
class RetailApp extends ConsumerStatefulWidget {
const RetailApp({super.key});
@@ -17,14 +18,14 @@ class RetailApp extends ConsumerStatefulWidget {
}
class _RetailAppState extends ConsumerState<RetailApp> {
int _currentIndex = 0;
final List<Widget> _pages = const [
HomePage(),
ProductsPage(),
CategoriesPage(),
SettingsPage(),
];
@override
void initState() {
super.initState();
// Initialize auth state on app start
WidgetsBinding.instance.addPostFrameCallback((_) {
ref.read(authProvider.notifier).initialize();
});
}
@override
Widget build(BuildContext context) {
@@ -36,19 +37,46 @@ class _RetailAppState extends ConsumerState<RetailApp> {
theme: AppTheme.lightTheme(),
darkTheme: AppTheme.darkTheme(),
themeMode: themeMode,
home: Scaffold(
body: IndexedStack(
index: _currentIndex,
children: _pages,
),
bottomNavigationBar: AppBottomNav(
currentIndex: _currentIndex,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
),
// Wrap the home with AuthWrapper to require login
home: const AuthWrapper(
child: MainScreen(),
),
);
}
}
/// Main screen with bottom navigation (only accessible after login)
class MainScreen extends ConsumerStatefulWidget {
const MainScreen({super.key});
@override
ConsumerState<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends ConsumerState<MainScreen> {
int _currentIndex = 0;
final List<Widget> _pages = const [
HomePage(),
ProductsPage(),
CategoriesPage(),
SettingsPage(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _currentIndex,
children: _pages,
),
bottomNavigationBar: AppBottomNav(
currentIndex: _currentIndex,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
),
);
}

View File

@@ -0,0 +1,6 @@
/// Export all core configuration
///
/// Contains app configuration settings
library;
export 'image_cache_config.dart';

View File

@@ -0,0 +1,10 @@
/// Export all core constants
///
/// Contains all application-wide constant values
library;
export 'api_constants.dart';
export 'app_constants.dart';
export 'performance_constants.dart';
export 'storage_constants.dart';
export 'ui_constants.dart';

34
lib/core/core.dart Normal file
View File

@@ -0,0 +1,34 @@
/// Core Module Barrel Export
///
/// Central export file for all core utilities, constants, and shared components.
/// This module contains everything that's shared across features.
///
/// Usage:
/// ```dart
/// import 'package:retail/core/core.dart';
/// ```
///
/// Includes:
/// - Constants: API, app, storage, UI, performance
/// - Network: Dio client, interceptors, network info
/// - Storage: Secure storage, database
/// - Theme: Material 3 theme, colors, typography
/// - Utils: Formatters, validators, extensions, helpers
/// - DI: Dependency injection setup
/// - Widgets: Reusable UI components
/// - Errors: Exception and failure handling
library;
// Export all core modules
export 'config/config.dart';
export 'constants/constants.dart';
export 'database/database.dart';
export 'di/di.dart';
export 'errors/errors.dart';
export 'network/network.dart';
export 'performance.dart';
export 'providers/providers.dart';
export 'storage/storage.dart';
export 'theme/theme.dart';
export 'utils/utils.dart';
export 'widgets/widgets.dart';

View File

@@ -0,0 +1,8 @@
/// Export all core database components
///
/// Contains Hive database initialization and utilities
library;
export 'database_initializer.dart';
export 'hive_database.dart';
export 'seed_data.dart';

7
lib/core/di/di.dart Normal file
View File

@@ -0,0 +1,7 @@
/// Export all dependency injection components
///
/// Contains service locator and injection container setup
library;
export 'injection_container.dart';
export 'service_locator.dart';

View File

@@ -0,0 +1,7 @@
/// Export all core error handling
///
/// Contains custom exceptions and failure classes
library;
export 'exceptions.dart';
export 'failures.dart';

View File

@@ -0,0 +1,8 @@
/// Export all core network components
///
/// Contains HTTP client, interceptors, and network utilities
library;
export 'api_interceptor.dart';
export 'dio_client.dart';
export 'network_info.dart';

View File

@@ -0,0 +1,6 @@
/// Export all core storage components
///
/// Contains secure storage utilities
library;
export 'secure_storage.dart';

View File

@@ -0,0 +1,8 @@
/// Export all core theme components
///
/// Contains Material 3 theme configuration
library;
export 'app_theme.dart';
export 'colors.dart';
export 'typography.dart';

12
lib/core/utils/utils.dart Normal file
View File

@@ -0,0 +1,12 @@
/// Export all core utilities
///
/// Contains helper functions, extensions, and utility classes
library;
export 'database_optimizer.dart';
export 'debouncer.dart';
export 'extensions.dart';
export 'formatters.dart';
export 'performance_monitor.dart';
export 'responsive_helper.dart';
export 'validators.dart';

View File

@@ -0,0 +1,15 @@
/// Authentication Feature
///
/// Complete authentication feature following clean architecture.
/// Includes login, registration, and user management.
///
/// Usage:
/// ```dart
/// import 'package:retail/features/auth/auth.dart';
/// ```
library;
// Export all layers
export 'data/data.dart';
export 'domain/domain.dart';
export 'presentation/presentation.dart';

View File

@@ -0,0 +1,8 @@
/// Export all auth data layer components
///
/// Contains data sources, models, and repository implementations
library;
export 'datasources/auth_remote_datasource.dart';
export 'models/models.dart';
export 'repositories/auth_repository_impl.dart';

View File

@@ -0,0 +1,9 @@
/// Export all auth data models
///
/// Contains DTOs and models for authentication data transfer
library;
export 'auth_response_model.dart';
export 'login_dto.dart';
export 'register_dto.dart';
export 'user_model.dart';

View File

@@ -0,0 +1,7 @@
/// Export all auth domain layer components
///
/// Contains entities and repository interfaces (no use cases yet)
library;
export 'entities/entities.dart';
export 'repositories/auth_repository.dart';

View File

@@ -0,0 +1,7 @@
/// Export all auth domain entities
///
/// Contains core business entities for authentication
library;
export 'auth_response.dart';
export 'user.dart';

View File

@@ -1,8 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../providers/auth_provider.dart';
import '../widgets/widgets.dart';
import '../utils/validators.dart';
import 'register_page.dart';
/// Login page for user authentication
/// Login page with email and password authentication
class LoginPage extends ConsumerStatefulWidget {
const LoginPage({super.key});
@@ -12,9 +15,9 @@ class LoginPage extends ConsumerStatefulWidget {
class _LoginPageState extends ConsumerState<LoginPage> {
final _formKey = GlobalKey<FormState>();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
bool _obscurePassword = true;
final _emailController = TextEditingController(text: 'admin@retailpos.com');
final _passwordController = TextEditingController(text: 'Admin123!');
bool _rememberMe = false;
@override
void dispose() {
@@ -24,8 +27,15 @@ class _LoginPageState extends ConsumerState<LoginPage> {
}
Future<void> _handleLogin() async {
if (!_formKey.currentState!.validate()) return;
// Dismiss keyboard
FocusScope.of(context).unfocus();
// Validate form
if (!_formKey.currentState!.validate()) {
return;
}
// Attempt login
final success = await ref.read(authProvider.notifier).login(
email: _emailController.text.trim(),
password: _passwordController.text,
@@ -33,135 +43,196 @@ class _LoginPageState extends ConsumerState<LoginPage> {
if (!mounted) return;
if (success) {
// Navigate to home or show success
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Login successful!')),
);
// TODO: Navigate to home page
} else {
final errorMessage = ref.read(authProvider).errorMessage;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(errorMessage ?? 'Login failed'),
backgroundColor: Colors.red,
),
);
// Show error if login failed
if (!success) {
final authState = ref.read(authProvider);
if (authState.errorMessage != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(authState.errorMessage!),
backgroundColor: Theme.of(context).colorScheme.error,
behavior: SnackBarBehavior.floating,
action: SnackBarAction(
label: 'Dismiss',
textColor: Colors.white,
onPressed: () {},
),
),
);
}
}
// Navigation is handled by AuthWrapper
}
void _navigateToRegister() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const RegisterPage(),
),
);
}
void _handleForgotPassword() {
// TODO: Implement forgot password functionality
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Forgot password feature coming soon!'),
behavior: SnackBarBehavior.floating,
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final authState = ref.watch(authProvider);
final isLoading = authState.isLoading;
return Scaffold(
appBar: AppBar(
title: const Text('Login'),
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Logo or app name
Icon(
Icons.shopping_cart,
size: 80,
color: Theme.of(context).primaryColor,
),
const SizedBox(height: 16),
Text(
'Retail POS',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 48),
// Email field
TextFormField(
controller: _emailController,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
labelText: 'Email',
prefixIcon: Icon(Icons.email),
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your email';
}
if (!value.contains('@')) {
return 'Please enter a valid email';
}
return null;
},
),
const SizedBox(height: 16),
// Password field
TextFormField(
controller: _passwordController,
obscureText: _obscurePassword,
decoration: InputDecoration(
labelText: 'Password',
prefixIcon: const Icon(Icons.lock),
border: const OutlineInputBorder(),
suffixIcon: IconButton(
icon: Icon(
_obscurePassword
? Icons.visibility
: Icons.visibility_off,
return GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Scaffold(
body: SafeArea(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24.0),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Header with logo and title
const AuthHeader(
title: 'Retail POS',
subtitle: 'Welcome back! Please login to continue.',
),
onPressed: () {
setState(() {
_obscurePassword = !_obscurePassword;
});
},
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your password';
}
if (value.length < 8) {
return 'Password must be at least 8 characters';
}
return null;
},
),
const SizedBox(height: 24),
const SizedBox(height: 48),
// Login button
FilledButton(
onPressed: authState.isLoading ? null : _handleLogin,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: authState.isLoading
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
// Email field
AuthTextField(
controller: _emailController,
label: 'Email',
hint: 'Enter your email',
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
prefixIcon: Icons.email_outlined,
validator: AuthValidators.validateEmail,
enabled: !isLoading,
autofocus: true,
),
const SizedBox(height: 16),
// Password field
PasswordField(
controller: _passwordController,
label: 'Password',
hint: 'Enter your password',
textInputAction: TextInputAction.done,
validator: AuthValidators.validateLoginPassword,
onFieldSubmitted: (_) => _handleLogin(),
enabled: !isLoading,
),
const SizedBox(height: 8),
// Remember me and forgot password row
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// Remember me checkbox
Row(
children: [
Checkbox(
value: _rememberMe,
onChanged: isLoading
? null
: (value) {
setState(() {
_rememberMe = value ?? false;
});
},
),
Text(
'Remember me',
style: theme.textTheme.bodyMedium,
),
],
),
// Forgot password link
TextButton(
onPressed: isLoading ? null : _handleForgotPassword,
child: Text(
'Forgot Password?',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.primary,
fontWeight: FontWeight.w600,
),
),
)
: const Text('Login'),
),
],
),
const SizedBox(height: 24),
// Login button
AuthButton(
onPressed: _handleLogin,
text: 'Login',
isLoading: isLoading,
),
const SizedBox(height: 24),
// Divider
Row(
children: [
Expanded(
child: Divider(
color: theme.colorScheme.onSurface.withOpacity(0.2),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
'OR',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.5),
),
),
),
Expanded(
child: Divider(
color: theme.colorScheme.onSurface.withOpacity(0.2),
),
),
],
),
const SizedBox(height: 24),
// Register link
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Don't have an account? ",
style: theme.textTheme.bodyMedium,
),
TextButton(
onPressed: isLoading ? null : _navigateToRegister,
child: Text(
'Register',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
),
],
),
],
),
),
const SizedBox(height: 16),
// Register link
TextButton(
onPressed: () {
// TODO: Navigate to register page
// Navigator.push(context, MaterialPageRoute(builder: (_) => const RegisterPage()));
},
child: const Text('Don\'t have an account? Register'),
),
],
),
),
),
),

View File

@@ -0,0 +1,7 @@
/// Export all auth presentation pages
///
/// Contains all screens related to authentication
library;
export 'login_page.dart';
export 'register_page.dart';

View File

@@ -1,8 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../providers/auth_provider.dart';
import '../widgets/widgets.dart';
import '../utils/validators.dart';
/// Register page for new user registration
/// Registration page for new users
class RegisterPage extends ConsumerStatefulWidget {
const RegisterPage({super.key});
@@ -16,8 +18,7 @@ class _RegisterPageState extends ConsumerState<RegisterPage> {
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
final _confirmPasswordController = TextEditingController();
bool _obscurePassword = true;
bool _obscureConfirmPassword = true;
bool _acceptTerms = false;
@override
void dispose() {
@@ -29,8 +30,27 @@ class _RegisterPageState extends ConsumerState<RegisterPage> {
}
Future<void> _handleRegister() async {
if (!_formKey.currentState!.validate()) return;
// Dismiss keyboard
FocusScope.of(context).unfocus();
// Validate form
if (!_formKey.currentState!.validate()) {
return;
}
// Check terms acceptance
if (!_acceptTerms) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Please accept the terms and conditions'),
backgroundColor: Theme.of(context).colorScheme.error,
behavior: SnackBarBehavior.floating,
),
);
return;
}
// Attempt registration
final success = await ref.read(authProvider.notifier).register(
name: _nameController.text.trim(),
email: _emailController.text.trim(),
@@ -40,191 +60,241 @@ class _RegisterPageState extends ConsumerState<RegisterPage> {
if (!mounted) return;
if (success) {
// Navigate to home or show success
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Registration successful!')),
);
// TODO: Navigate to home page
} else {
final errorMessage = ref.read(authProvider).errorMessage;
// Show success message
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(errorMessage ?? 'Registration failed'),
backgroundColor: Colors.red,
content: const Text('Registration successful!'),
backgroundColor: Theme.of(context).colorScheme.primary,
behavior: SnackBarBehavior.floating,
),
);
// Navigation is handled by AuthWrapper
} else {
// Show error message
final authState = ref.read(authProvider);
if (authState.errorMessage != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(authState.errorMessage!),
backgroundColor: Theme.of(context).colorScheme.error,
behavior: SnackBarBehavior.floating,
action: SnackBarAction(
label: 'Dismiss',
textColor: Colors.white,
onPressed: () {},
),
),
);
}
}
}
void _navigateBackToLogin() {
Navigator.of(context).pop();
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final authState = ref.watch(authProvider);
final isLoading = authState.isLoading;
return Scaffold(
appBar: AppBar(
title: const Text('Register'),
),
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24.0),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 24),
// Logo or app name
Icon(
Icons.shopping_cart,
size: 80,
color: Theme.of(context).primaryColor,
),
const SizedBox(height: 16),
Text(
'Create Account',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 48),
// Name field
TextFormField(
controller: _nameController,
decoration: const InputDecoration(
labelText: 'Full Name',
prefixIcon: Icon(Icons.person),
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your name';
}
if (value.length < 2) {
return 'Name must be at least 2 characters';
}
return null;
},
),
const SizedBox(height: 16),
// Email field
TextFormField(
controller: _emailController,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
labelText: 'Email',
prefixIcon: Icon(Icons.email),
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your email';
}
if (!value.contains('@')) {
return 'Please enter a valid email';
}
return null;
},
),
const SizedBox(height: 16),
// Password field
TextFormField(
controller: _passwordController,
obscureText: _obscurePassword,
decoration: InputDecoration(
labelText: 'Password',
prefixIcon: const Icon(Icons.lock),
border: const OutlineInputBorder(),
suffixIcon: IconButton(
icon: Icon(
_obscurePassword
? Icons.visibility
: Icons.visibility_off,
return GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: isLoading ? null : _navigateBackToLogin,
),
),
body: SafeArea(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24.0),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Header
const AuthHeader(
title: 'Create Account',
subtitle: 'Join us and start managing your retail business.',
),
onPressed: () {
setState(() {
_obscurePassword = !_obscurePassword;
});
},
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your password';
}
if (value.length < 8) {
return 'Password must be at least 8 characters';
}
// Check for uppercase, lowercase, and number
if (!RegExp(r'(?=.*[a-z])(?=.*[A-Z])(?=.*\d)').hasMatch(value)) {
return 'Password must contain uppercase, lowercase, and number';
}
return null;
},
),
const SizedBox(height: 16),
const SizedBox(height: 40),
// Confirm password field
TextFormField(
controller: _confirmPasswordController,
obscureText: _obscureConfirmPassword,
decoration: InputDecoration(
labelText: 'Confirm Password',
prefixIcon: const Icon(Icons.lock_outline),
border: const OutlineInputBorder(),
suffixIcon: IconButton(
icon: Icon(
_obscureConfirmPassword
? Icons.visibility
: Icons.visibility_off,
// Name field
AuthTextField(
controller: _nameController,
label: 'Full Name',
hint: 'Enter your full name',
keyboardType: TextInputType.name,
textInputAction: TextInputAction.next,
prefixIcon: Icons.person_outline,
validator: AuthValidators.validateName,
enabled: !isLoading,
autofocus: true,
),
onPressed: () {
setState(() {
_obscureConfirmPassword = !_obscureConfirmPassword;
});
},
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please confirm your password';
}
if (value != _passwordController.text) {
return 'Passwords do not match';
}
return null;
},
),
const SizedBox(height: 24),
const SizedBox(height: 16),
// Register button
FilledButton(
onPressed: authState.isLoading ? null : _handleRegister,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: authState.isLoading
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
// Email field
AuthTextField(
controller: _emailController,
label: 'Email',
hint: 'Enter your email',
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
prefixIcon: Icons.email_outlined,
validator: AuthValidators.validateEmail,
enabled: !isLoading,
),
const SizedBox(height: 16),
// Password field
PasswordField(
controller: _passwordController,
label: 'Password',
hint: 'Create a strong password',
textInputAction: TextInputAction.next,
validator: AuthValidators.validatePassword,
enabled: !isLoading,
),
const SizedBox(height: 16),
// Confirm password field
PasswordField(
controller: _confirmPasswordController,
label: 'Confirm Password',
hint: 'Re-enter your password',
textInputAction: TextInputAction.done,
validator: (value) => AuthValidators.validateConfirmPassword(
value,
_passwordController.text,
),
onFieldSubmitted: (_) => _handleRegister(),
enabled: !isLoading,
),
const SizedBox(height: 16),
// Terms and conditions checkbox
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Checkbox(
value: _acceptTerms,
onChanged: isLoading
? null
: (value) {
setState(() {
_acceptTerms = value ?? false;
});
},
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(top: 12),
child: GestureDetector(
onTap: isLoading
? null
: () {
setState(() {
_acceptTerms = !_acceptTerms;
});
},
child: Text.rich(
TextSpan(
text: 'I agree to the ',
style: theme.textTheme.bodyMedium,
children: [
TextSpan(
text: 'Terms and Conditions',
style: TextStyle(
color: theme.colorScheme.primary,
fontWeight: FontWeight.w600,
),
),
const TextSpan(text: ' and '),
TextSpan(
text: 'Privacy Policy',
style: TextStyle(
color: theme.colorScheme.primary,
fontWeight: FontWeight.w600,
),
),
],
),
),
),
),
)
: const Text('Register'),
),
],
),
const SizedBox(height: 24),
// Register button
AuthButton(
onPressed: _handleRegister,
text: 'Create Account',
isLoading: isLoading,
),
const SizedBox(height: 24),
// Divider
Row(
children: [
Expanded(
child: Divider(
color: theme.colorScheme.onSurface.withOpacity(0.2),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
'OR',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.5),
),
),
),
Expanded(
child: Divider(
color: theme.colorScheme.onSurface.withOpacity(0.2),
),
),
],
),
const SizedBox(height: 24),
// Login link
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Already have an account? ',
style: theme.textTheme.bodyMedium,
),
TextButton(
onPressed: isLoading ? null : _navigateBackToLogin,
child: Text(
'Login',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
),
],
),
],
),
),
const SizedBox(height: 16),
// Login link
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Already have an account? Login'),
),
],
),
),
),
),

View File

@@ -0,0 +1,7 @@
/// Export all authentication presentation layer components
library;
export 'pages/pages.dart';
export 'providers/auth_provider.dart';
export 'utils/validators.dart';
export 'widgets/widgets.dart';

View File

@@ -1,14 +1,44 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../../../../core/di/injection_container.dart';
import '../../../../core/network/dio_client.dart';
import '../../../../core/storage/secure_storage.dart';
import '../../data/datasources/auth_remote_datasource.dart';
import '../../data/repositories/auth_repository_impl.dart';
import '../../domain/entities/user.dart';
import '../../domain/repositories/auth_repository.dart';
part 'auth_provider.g.dart';
/// Provider for DioClient (singleton)
@Riverpod(keepAlive: true)
DioClient dioClient(Ref ref) {
return DioClient();
}
/// Provider for SecureStorage (singleton)
@Riverpod(keepAlive: true)
SecureStorage secureStorage(Ref ref) {
return SecureStorage();
}
/// Provider for AuthRemoteDataSource
@Riverpod(keepAlive: true)
AuthRemoteDataSource authRemoteDataSource(Ref ref) {
final dioClient = ref.watch(dioClientProvider);
return AuthRemoteDataSourceImpl(dioClient: dioClient);
}
/// Provider for AuthRepository
@riverpod
@Riverpod(keepAlive: true)
AuthRepository authRepository(Ref ref) {
return sl<AuthRepository>();
final remoteDataSource = ref.watch(authRemoteDataSourceProvider);
final secureStorage = ref.watch(secureStorageProvider);
final dioClient = ref.watch(dioClientProvider);
return AuthRepositoryImpl(
remoteDataSource: remoteDataSource,
secureStorage: secureStorage,
dioClient: dioClient,
);
}
/// Auth state class
@@ -45,14 +75,15 @@ class AuthState {
class Auth extends _$Auth {
@override
AuthState build() {
_checkAuthStatus();
// Don't call async operations in build
// Use a separate method to initialize auth state
return const AuthState();
}
AuthRepository get _repository => ref.read(authRepositoryProvider);
/// Check if user is authenticated on app start
Future<void> _checkAuthStatus() async {
/// Initialize auth state - call this on app start
Future<void> initialize() async {
state = state.copyWith(isLoading: true);
final isAuthenticated = await _repository.isAuthenticated();

View File

@@ -8,6 +8,151 @@ part of 'auth_provider.dart';
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, type=warning
/// Provider for DioClient (singleton)
@ProviderFor(dioClient)
const dioClientProvider = DioClientProvider._();
/// Provider for DioClient (singleton)
final class DioClientProvider
extends $FunctionalProvider<DioClient, DioClient, DioClient>
with $Provider<DioClient> {
/// Provider for DioClient (singleton)
const DioClientProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'dioClientProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$dioClientHash();
@$internal
@override
$ProviderElement<DioClient> $createElement($ProviderPointer pointer) =>
$ProviderElement(pointer);
@override
DioClient create(Ref ref) {
return dioClient(ref);
}
/// {@macro riverpod.override_with_value}
Override overrideWithValue(DioClient value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<DioClient>(value),
);
}
}
String _$dioClientHash() => r'895f0dc2f8d5eab562ad65390e5c6d4a1f722b0d';
/// Provider for SecureStorage (singleton)
@ProviderFor(secureStorage)
const secureStorageProvider = SecureStorageProvider._();
/// Provider for SecureStorage (singleton)
final class SecureStorageProvider
extends $FunctionalProvider<SecureStorage, SecureStorage, SecureStorage>
with $Provider<SecureStorage> {
/// Provider for SecureStorage (singleton)
const SecureStorageProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'secureStorageProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$secureStorageHash();
@$internal
@override
$ProviderElement<SecureStorage> $createElement($ProviderPointer pointer) =>
$ProviderElement(pointer);
@override
SecureStorage create(Ref ref) {
return secureStorage(ref);
}
/// {@macro riverpod.override_with_value}
Override overrideWithValue(SecureStorage value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<SecureStorage>(value),
);
}
}
String _$secureStorageHash() => r'5c9908c0046ad0e39469ee7acbb5540397b36693';
/// Provider for AuthRemoteDataSource
@ProviderFor(authRemoteDataSource)
const authRemoteDataSourceProvider = AuthRemoteDataSourceProvider._();
/// Provider for AuthRemoteDataSource
final class AuthRemoteDataSourceProvider
extends
$FunctionalProvider<
AuthRemoteDataSource,
AuthRemoteDataSource,
AuthRemoteDataSource
>
with $Provider<AuthRemoteDataSource> {
/// Provider for AuthRemoteDataSource
const AuthRemoteDataSourceProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'authRemoteDataSourceProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$authRemoteDataSourceHash();
@$internal
@override
$ProviderElement<AuthRemoteDataSource> $createElement(
$ProviderPointer pointer,
) => $ProviderElement(pointer);
@override
AuthRemoteDataSource create(Ref ref) {
return authRemoteDataSource(ref);
}
/// {@macro riverpod.override_with_value}
Override overrideWithValue(AuthRemoteDataSource value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<AuthRemoteDataSource>(value),
);
}
}
String _$authRemoteDataSourceHash() =>
r'83759467bf61c03cf433b26d1126b19ab1d2b493';
/// Provider for AuthRepository
@ProviderFor(authRepository)
@@ -25,7 +170,7 @@ final class AuthRepositoryProvider
argument: null,
retry: null,
name: r'authRepositoryProvider',
isAutoDispose: true,
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@@ -52,7 +197,7 @@ final class AuthRepositoryProvider
}
}
String _$authRepositoryHash() => r'0483b13ac95333b56a1a82f6c9fdb64ae46f287d';
String _$authRepositoryHash() => r'5a333f81441082dd473e9089124aa65fda42be7b';
/// Auth state notifier provider
@@ -89,7 +234,7 @@ final class AuthProvider extends $NotifierProvider<Auth, AuthState> {
}
}
String _$authHash() => r'c88e150224fa855ed0ddfba30bef9e2b289f329d';
String _$authHash() => r'67ba3b381308cce5e693827ad22db940840c3978';
/// Auth state notifier provider

View File

@@ -0,0 +1,86 @@
/// Form validators for authentication
class AuthValidators {
AuthValidators._();
/// Validates email format
static String? validateEmail(String? value) {
if (value == null || value.isEmpty) {
return 'Email is required';
}
final emailRegex = RegExp(
r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
);
if (!emailRegex.hasMatch(value)) {
return 'Please enter a valid email address';
}
return null;
}
/// Validates password strength
/// Requirements: min 8 characters, at least one uppercase, one lowercase, one number
static String? validatePassword(String? value) {
if (value == null || value.isEmpty) {
return 'Password is required';
}
if (value.length < 8) {
return 'Password must be at least 8 characters';
}
if (!RegExp(r'[A-Z]').hasMatch(value)) {
return 'Password must contain at least one uppercase letter';
}
if (!RegExp(r'[a-z]').hasMatch(value)) {
return 'Password must contain at least one lowercase letter';
}
if (!RegExp(r'[0-9]').hasMatch(value)) {
return 'Password must contain at least one number';
}
return null;
}
/// Validates name field
static String? validateName(String? value) {
if (value == null || value.isEmpty) {
return 'Name is required';
}
if (value.length < 2) {
return 'Name must be at least 2 characters';
}
if (value.length > 50) {
return 'Name must not exceed 50 characters';
}
return null;
}
/// Validates password confirmation
static String? validateConfirmPassword(String? value, String password) {
if (value == null || value.isEmpty) {
return 'Please confirm your password';
}
if (value != password) {
return 'Passwords do not match';
}
return null;
}
/// Simple password validator for login (no strength requirements)
static String? validateLoginPassword(String? value) {
if (value == null || value.isEmpty) {
return 'Password is required';
}
return null;
}
}

View File

@@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
/// Custom elevated button for authentication actions
class AuthButton extends StatelessWidget {
const AuthButton({
super.key,
required this.onPressed,
required this.text,
this.isLoading = false,
this.enabled = true,
});
final VoidCallback? onPressed;
final String text;
final bool isLoading;
final bool enabled;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: (enabled && !isLoading) ? onPressed : null,
style: ElevatedButton.styleFrom(
backgroundColor: theme.colorScheme.primary,
foregroundColor: theme.colorScheme.onPrimary,
disabledBackgroundColor:
theme.colorScheme.onSurface.withOpacity(0.12),
disabledForegroundColor:
theme.colorScheme.onSurface.withOpacity(0.38),
elevation: 2,
shadowColor: theme.colorScheme.primary.withOpacity(0.3),
),
child: isLoading
? SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
theme.colorScheme.onPrimary,
),
),
)
: Text(
text,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onPrimary,
),
),
),
);
}
}

View File

@@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
/// Auth header widget displaying app logo and welcome text
class AuthHeader extends StatelessWidget {
const AuthHeader({
super.key,
required this.title,
required this.subtitle,
});
final String title;
final String subtitle;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// App logo/icon
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(20),
),
child: Icon(
Icons.store,
size: 60,
color: theme.colorScheme.primary,
),
),
const SizedBox(height: 24),
// Title
Text(
title,
style: theme.textTheme.displaySmall?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onSurface,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
// Subtitle
Text(
subtitle,
style: theme.textTheme.bodyLarge?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.6),
),
textAlign: TextAlign.center,
),
],
);
}
}

View File

@@ -0,0 +1,65 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// Custom text field for authentication forms
class AuthTextField extends StatelessWidget {
const AuthTextField({
super.key,
required this.controller,
required this.label,
this.hint,
this.validator,
this.keyboardType,
this.textInputAction,
this.onFieldSubmitted,
this.prefixIcon,
this.enabled = true,
this.autofocus = false,
this.inputFormatters,
});
final TextEditingController controller;
final String label;
final String? hint;
final String? Function(String?)? validator;
final TextInputType? keyboardType;
final TextInputAction? textInputAction;
final void Function(String)? onFieldSubmitted;
final IconData? prefixIcon;
final bool enabled;
final bool autofocus;
final List<TextInputFormatter>? inputFormatters;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return TextFormField(
controller: controller,
validator: validator,
keyboardType: keyboardType,
textInputAction: textInputAction,
onFieldSubmitted: onFieldSubmitted,
enabled: enabled,
autofocus: autofocus,
inputFormatters: inputFormatters,
style: theme.textTheme.bodyLarge,
decoration: InputDecoration(
labelText: label,
hintText: hint,
prefixIcon: prefixIcon != null
? Icon(prefixIcon, color: theme.colorScheme.primary)
: null,
labelStyle: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.7),
),
hintStyle: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.4),
),
errorStyle: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.error,
),
),
);
}
}

View File

@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../providers/auth_provider.dart';
import '../pages/login_page.dart';
/// Wrapper widget that checks authentication status
/// Shows login page if not authenticated, otherwise shows child widget
class AuthWrapper extends ConsumerWidget {
const AuthWrapper({
super.key,
required this.child,
});
final Widget child;
@override
Widget build(BuildContext context, WidgetRef ref) {
final authState = ref.watch(authProvider);
// Show loading indicator while checking auth status
if (authState.isLoading && authState.user == null) {
return const Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
// Show child widget if authenticated, otherwise show login page
if (authState.isAuthenticated) {
return child;
} else {
return const LoginPage();
}
}
}

View File

@@ -0,0 +1,78 @@
import 'package:flutter/material.dart';
/// Password field with show/hide toggle
class PasswordField extends StatefulWidget {
const PasswordField({
super.key,
required this.controller,
required this.label,
this.hint,
this.validator,
this.textInputAction,
this.onFieldSubmitted,
this.enabled = true,
this.autofocus = false,
});
final TextEditingController controller;
final String label;
final String? hint;
final String? Function(String?)? validator;
final TextInputAction? textInputAction;
final void Function(String)? onFieldSubmitted;
final bool enabled;
final bool autofocus;
@override
State<PasswordField> createState() => _PasswordFieldState();
}
class _PasswordFieldState extends State<PasswordField> {
bool _obscureText = true;
void _toggleVisibility() {
setState(() {
_obscureText = !_obscureText;
});
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return TextFormField(
controller: widget.controller,
validator: widget.validator,
obscureText: _obscureText,
textInputAction: widget.textInputAction,
onFieldSubmitted: widget.onFieldSubmitted,
enabled: widget.enabled,
autofocus: widget.autofocus,
style: theme.textTheme.bodyLarge,
decoration: InputDecoration(
labelText: widget.label,
hintText: widget.hint,
prefixIcon: Icon(
Icons.lock_outline,
color: theme.colorScheme.primary,
),
suffixIcon: IconButton(
icon: Icon(
_obscureText ? Icons.visibility : Icons.visibility_off,
color: theme.colorScheme.onSurface.withOpacity(0.6),
),
onPressed: _toggleVisibility,
),
labelStyle: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.7),
),
hintStyle: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.4),
),
errorStyle: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.error,
),
),
);
}
}

View File

@@ -0,0 +1,6 @@
/// Export file for all auth widgets
export 'auth_button.dart';
export 'auth_header.dart';
export 'auth_text_field.dart';
export 'auth_wrapper.dart';
export 'password_field.dart';

View File

@@ -0,0 +1,15 @@
/// Categories Feature
///
/// Complete categories feature following clean architecture.
/// Includes category listing, filtering, and management.
///
/// Usage:
/// ```dart
/// import 'package:retail/features/categories/categories.dart';
/// ```
library;
// Export all layers
export 'data/data.dart';
export 'domain/domain.dart';
export 'presentation/presentation.dart';

View File

@@ -0,0 +1,8 @@
/// Export all categories data layer components
///
/// Contains data sources, models, and repository implementations
library;
export 'datasources/datasources.dart';
export 'models/models.dart';
export 'repositories/category_repository_impl.dart';

View File

@@ -0,0 +1,6 @@
/// Export all categories data sources
///
/// Contains local data sources for categories
library;
export 'category_local_datasource.dart';

View File

@@ -0,0 +1,6 @@
/// Export all categories data models
///
/// Contains DTOs and models for category data transfer
library;
export 'category_model.dart';

View File

@@ -0,0 +1,8 @@
/// Export all categories domain layer components
///
/// Contains entities, repository interfaces, and use cases
library;
export 'entities/entities.dart';
export 'repositories/category_repository.dart';
export 'usecases/usecases.dart';

View File

@@ -0,0 +1,6 @@
/// Export all categories domain entities
///
/// Contains core business entities for categories
library;
export 'category.dart';

View File

@@ -0,0 +1,6 @@
/// Export all categories domain use cases
///
/// Contains business logic for category operations
library;
export 'get_all_categories.dart';

View File

@@ -0,0 +1,6 @@
/// Export all categories presentation pages
///
/// Contains all screens related to categories
library;
export 'categories_page.dart';

View File

@@ -0,0 +1,8 @@
/// Export all categories presentation layer components
///
/// Contains pages, widgets, and providers for category UI
library;
export 'pages/pages.dart';
export 'providers/providers.dart';
export 'widgets/widgets.dart';

View File

@@ -1,4 +1,13 @@
/// Export all category providers
///
/// Contains Riverpod providers for category state management
library;
export 'category_datasource_provider.dart';
export 'categories_provider.dart';
export 'category_product_count_provider.dart';
// Note: SelectedCategory provider is defined in categories_provider.dart
// but we avoid exporting it separately to prevent ambiguous exports with
// the products feature. Use selectedCategoryProvider directly from
// categories_provider.dart or from products feature.

View File

@@ -0,0 +1,24 @@
/// Features Barrel Export
///
/// Central export file for all application features.
/// Import this file to access any feature in the app.
///
/// Usage:
/// ```dart
/// import 'package:retail/features/features.dart';
///
/// // Now you can access all features:
/// // - Auth: Login, Register, User management
/// // - Products: Product listing, search, filtering
/// // - Categories: Category management
/// // - Home: Shopping cart, checkout
/// // - Settings: App configuration
/// ```
library;
// Export all feature modules
export 'auth/auth.dart';
export 'categories/categories.dart';
export 'home/home.dart';
export 'products/products.dart';
export 'settings/settings.dart';

View File

@@ -0,0 +1,8 @@
/// Export all home/cart data layer components
///
/// Contains data sources, models, and repository implementations
library;
export 'datasources/datasources.dart';
export 'models/models.dart';
export 'repositories/cart_repository_impl.dart';

View File

@@ -0,0 +1,6 @@
/// Export all home/cart data sources
///
/// Contains local data sources for cart operations
library;
export 'cart_local_datasource.dart';

View File

@@ -0,0 +1,7 @@
/// Export all home/cart data models
///
/// Contains DTOs and models for cart and transaction data transfer
library;
export 'cart_item_model.dart';
export 'transaction_model.dart';

View File

@@ -0,0 +1,8 @@
/// Export all home/cart domain layer components
///
/// Contains entities, repository interfaces, and use cases
library;
export 'entities/entities.dart';
export 'repositories/cart_repository.dart';
export 'usecases/usecases.dart';

View File

@@ -0,0 +1,6 @@
/// Export all home/cart domain entities
///
/// Contains core business entities for cart operations
library;
export 'cart_item.dart';

View File

@@ -0,0 +1,9 @@
/// Export all home/cart domain use cases
///
/// Contains business logic for cart operations
library;
export 'add_to_cart.dart';
export 'calculate_total.dart';
export 'clear_cart.dart';
export 'remove_from_cart.dart';

View File

@@ -0,0 +1,15 @@
/// Home/Cart Feature
///
/// Complete home and shopping cart feature following clean architecture.
/// Includes cart management, product selection, and checkout operations.
///
/// Usage:
/// ```dart
/// import 'package:retail/features/home/home.dart';
/// ```
library;
// Export all layers
export 'data/data.dart';
export 'domain/domain.dart';
export 'presentation/presentation.dart';

View File

@@ -0,0 +1,6 @@
/// Export all home/cart presentation pages
///
/// Contains all screens related to home and cart
library;
export 'home_page.dart';

View File

@@ -0,0 +1,8 @@
/// Export all home/cart presentation layer components
///
/// Contains pages, widgets, and providers for cart UI
library;
export 'pages/pages.dart';
export 'providers/providers.dart';
export 'widgets/widgets.dart';

View File

@@ -0,0 +1,8 @@
/// Export all products data layer components
///
/// Contains data sources, models, and repository implementations
library;
export 'datasources/datasources.dart';
export 'models/models.dart';
export 'repositories/product_repository_impl.dart';

View File

@@ -0,0 +1,7 @@
/// Export all products data sources
///
/// Contains local and remote data sources for products
library;
export 'product_local_datasource.dart';
export 'product_remote_datasource.dart';

View File

@@ -0,0 +1,6 @@
/// Export all products data models
///
/// Contains DTOs and models for product data transfer
library;
export 'product_model.dart';

View File

@@ -0,0 +1,8 @@
/// Export all products domain layer components
///
/// Contains entities, repository interfaces, and use cases
library;
export 'entities/entities.dart';
export 'repositories/product_repository.dart';
export 'usecases/usecases.dart';

View File

@@ -0,0 +1,6 @@
/// Export all products domain entities
///
/// Contains core business entities for products
library;
export 'product.dart';

View File

@@ -0,0 +1,7 @@
/// Export all products domain use cases
///
/// Contains business logic for product operations
library;
export 'get_all_products.dart';
export 'search_products.dart';

View File

@@ -0,0 +1,6 @@
/// Export all products presentation pages
///
/// Contains all screens related to products
library;
export 'products_page.dart';

View File

@@ -0,0 +1,8 @@
/// Export all products presentation layer components
///
/// Contains pages, widgets, and providers for product UI
library;
export 'pages/pages.dart';
export 'providers/providers.dart';
export 'widgets/widgets.dart';

View File

@@ -0,0 +1,15 @@
/// Export all products providers
///
/// Contains Riverpod providers for product state management
library;
// Export individual provider files
// Note: products_provider.dart contains multiple providers
// so we only export it to avoid ambiguous exports
export 'products_provider.dart';
// These are also defined in products_provider.dart, so we don't export them separately
// to avoid ambiguous export errors
// export 'filtered_products_provider.dart';
// export 'search_query_provider.dart';
// export 'selected_category_provider.dart';

View File

@@ -0,0 +1,15 @@
/// Products Feature
///
/// Complete products feature following clean architecture.
/// Includes product listing, search, filtering, and management.
///
/// Usage:
/// ```dart
/// import 'package:retail/features/products/products.dart';
/// ```
library;
// Export all layers
export 'data/data.dart';
export 'domain/domain.dart';
export 'presentation/presentation.dart';

View File

@@ -0,0 +1,8 @@
/// Export all settings data layer components
///
/// Contains data sources, models, and repository implementations
library;
export 'datasources/datasources.dart';
export 'models/models.dart';
export 'repositories/settings_repository_impl.dart';

View File

@@ -0,0 +1,6 @@
/// Export all settings data sources
///
/// Contains local data sources for settings
library;
export 'settings_local_datasource.dart';

View File

@@ -0,0 +1,6 @@
/// Export all settings data models
///
/// Contains DTOs and models for app settings data transfer
library;
export 'app_settings_model.dart';

View File

@@ -0,0 +1,8 @@
/// Export all settings domain layer components
///
/// Contains entities, repository interfaces, and use cases
library;
export 'entities/entities.dart';
export 'repositories/settings_repository.dart';
export 'usecases/usecases.dart';

View File

@@ -0,0 +1,6 @@
/// Export all settings domain entities
///
/// Contains core business entities for app settings
library;
export 'app_settings.dart';

View File

@@ -0,0 +1,7 @@
/// Export all settings domain use cases
///
/// Contains business logic for settings operations
library;
export 'get_settings.dart';
export 'update_settings.dart';

View File

@@ -0,0 +1,6 @@
/// Export all settings presentation pages
///
/// Contains all screens related to settings
library;
export 'settings_page.dart';

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../providers/settings_provider.dart';
import '../../../auth/presentation/providers/auth_provider.dart';
import '../../../../core/constants/app_constants.dart';
/// Settings page
@@ -37,8 +38,105 @@ class SettingsPage extends ConsumerWidget {
),
),
data: (settings) {
final user = ref.watch(currentUserProvider);
return ListView(
children: [
// User Profile Section
if (user != null) ...[
Card(
margin: const EdgeInsets.all(16),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
CircleAvatar(
radius: 40,
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
child: Text(
user.name.isNotEmpty ? user.name[0].toUpperCase() : '?',
style: TextStyle(
fontSize: 32,
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
),
),
const SizedBox(height: 12),
Text(
user.name,
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 4),
Text(
user.email,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
if (user.roles.isNotEmpty) ...[
const SizedBox(height: 12),
Wrap(
spacing: 8,
alignment: WrapAlignment.center,
children: user.roles
.map((role) => Chip(
label: Text(
role.toUpperCase(),
style: const TextStyle(fontSize: 11),
),
padding: const EdgeInsets.symmetric(horizontal: 8),
backgroundColor:
Theme.of(context).colorScheme.primaryContainer,
labelStyle: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
))
.toList(),
),
],
const SizedBox(height: 16),
FilledButton.icon(
onPressed: () async {
// Show confirmation dialog
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('Logout'),
content: const Text('Are you sure you want to logout?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
FilledButton(
onPressed: () => Navigator.pop(context, true),
style: FilledButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.error,
),
child: const Text('Logout'),
),
],
),
);
if (confirmed == true && context.mounted) {
await ref.read(authProvider.notifier).logout();
}
},
icon: const Icon(Icons.logout),
label: const Text('Logout'),
style: FilledButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.error,
foregroundColor: Theme.of(context).colorScheme.onError,
),
),
],
),
),
),
const Divider(),
],
// Appearance Section
_buildSectionHeader(context, 'Appearance'),
ListTile(

View File

@@ -0,0 +1,8 @@
/// Export all settings presentation layer components
///
/// Contains pages, widgets, and providers for settings UI
library;
export 'pages/pages.dart';
export 'providers/providers.dart';
export 'widgets/widgets.dart';

View File

@@ -0,0 +1,7 @@
/// Export all settings presentation widgets
///
/// Contains reusable widgets for settings UI
/// (Currently empty - add settings-specific widgets here)
library;
// TODO: Add settings-specific widgets (e.g., settings tiles, sections)

View File

@@ -0,0 +1,15 @@
/// Settings Feature
///
/// Complete settings feature following clean architecture.
/// Includes app configuration, theme management, and user preferences.
///
/// Usage:
/// ```dart
/// import 'package:retail/features/settings/settings.dart';
/// ```
library;
// Export all layers
export 'data/data.dart';
export 'domain/domain.dart';
export 'presentation/presentation.dart';

View File

@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:hive_ce_flutter/hive_flutter.dart';
import 'app.dart';
import 'core/di/service_locator.dart';
/// Main entry point of the application
void main() async {
@@ -26,10 +25,7 @@ void main() async {
// await Hive.openBox<CartItemModel>(StorageConstants.cartBox);
// await Hive.openBox<AppSettingsModel>(StorageConstants.settingsBox);
// Setup dependency injection
await setupServiceLocator();
// Run the app
// Run the app with Riverpod (no GetIt needed - using Riverpod for DI)
runApp(
const ProviderScope(
child: RetailApp(),

13
lib/shared/shared.dart Normal file
View File

@@ -0,0 +1,13 @@
/// Shared Module Barrel Export
///
/// Central export file for cross-feature shared components.
/// These widgets and utilities are used across multiple features.
///
/// Usage:
/// ```dart
/// import 'package:retail/shared/shared.dart';
/// ```
library;
// Export shared widgets
export 'widgets/widgets.dart';