Skip to content

kael-moreno/flutter-base

Repository files navigation

Flutter Base Project - Unified API Architecture

A modern Flutter application template implementing a Unified API Architecture that eliminates 90% of boilerplate while maintaining clean architecture benefits. Perfect starting point for scalable mobile and web applications with real API integration.

πŸš€ Architecture Revolution

This project demonstrates a revolutionary unified approach that replaces traditional Clean Architecture complexity:

  • 2 files per API instead of 12+ files
  • Generic base classes for all CRUD operations
  • Centralized provider management with type safety
  • Unified error handling with consistent UX
  • Real API integration with JSONPlaceholder

Example: Complete Users and Posts features with full CRUD operations, demonstrating the power of unified architecture patterns.

πŸ“± Project Features

🎯 Unified API Architecture:

  • βœ… Generic DataListState for type-safe state management
  • βœ… ApiServiceFactory for automatic CRUD operations
  • βœ… Centralized providers in core/providers/api_providers.dart
  • βœ… Unified error handling with ErrorApiWidget
  • βœ… 90% less boilerplate compared to traditional Clean Architecture

πŸ”§ Modern State Management:

  • βœ… Riverpod for dependency injection and state management
  • βœ… Generic StateNotifiers with DataListNotifier<T>
  • βœ… Automatic API operations (GET, POST, PUT, DELETE)
  • βœ… Real-time error handling and retry functionality

πŸ“¦ Production-Ready Setup:

  • βœ… Multi-platform support (Android, iOS, Web)
  • βœ… Real API integration with JSONPlaceholder
  • βœ… Comprehensive test suite (30+ tests)
  • βœ… Facebook-inspired Material 3 theming

πŸš€ Getting Started

Prerequisites

Installation

  1. Use this template for a new project:

    git clone https://github.com/CoreProc/flutter-base.git your-new-project
    cd your-new-project
  2. Customize for your project:

    # Remove existing git history (optional)
    rm -rf .git
    
    # Initialize new git repository
    git init
    
    # Update project name in pubspec.yaml
    # Update README.md with your project details
  3. Install dependencies:

    flutter pub get
  4. Run the app:

    # For Android
    flutter run -d android
    
    # For iOS (macOS only)
    flutter run -d ios
    
    # For Web
    flutter run -d chrome

πŸ› οΈ Customization

When using this base for a new project:

  1. Update Project Details:

    • Modify pubspec.yaml with your project name and details
    • Update README.md with your project description
    • Customize app icons and splash screens
  2. Configure Platforms:

    • Update Android package name in android/app/build.gradle.kts
    • Update iOS bundle identifier in ios/Runner.xcodeproj/project.pbxproj
    • Modify web title and description in web/index.html
  3. Add Dependencies:

    • Add required packages to pubspec.yaml
    • Configure any platform-specific dependencies

πŸ—οΈ Quick Start Example

Want to add a new API? Here's how easy it is with the unified architecture:

Traditional Way (12+ files):

❌ features/products/data/datasources/...
❌ features/products/data/models/...
❌ features/products/data/repositories/...
❌ features/products/domain/entities/...
❌ features/products/domain/repositories/...
❌ features/products/domain/usecases/...
❌ features/products/presentation/pages/...
❌ features/products/presentation/providers/...

Unified Way (2 files):

βœ… // 1. Create model (lib/models/product.dart)
class Product {
  final int id;
  final String name;
  // ... add fromJson/toJson
}

βœ… // 2. Add provider (lib/core/providers/api_providers.dart)
static final productsProvider = ApiServiceFactory.createListProvider<Product>(
  ApiConfig<Product>(
    endpoint: '/products',
    fromJson: (json) => Product.fromJson(json),
    toJson: (product) => product.toJson(),
    getId: (product) => product.id,
  ),
);

That's it! You now have full CRUD operations with loading states, error handling, and type safety. πŸŽ‰

πŸ› οΈ Development

Available Commands

  • flutter run - Run the app on connected device
  • flutter run -d chrome - Run on web browser
  • flutter test - Run all tests (30+ comprehensive tests)
  • flutter build apk - Build Android APK
  • flutter build ios - Build iOS app (macOS only)
  • flutter build web - Build for web deployment
  • flutter clean - Clean build files

Project Structure

lib/
β”œβ”€β”€ core/                           # Core unified architecture
β”‚   β”œβ”€β”€ api/api_service.dart        # Generic API service factory
β”‚   β”œβ”€β”€ baseui/error_api.dart       # Centralized error widget
β”‚   β”œβ”€β”€ data/base_repository.dart   # HTTP operations
β”‚   β”œβ”€β”€ errors/failures.dart        # Error classes
β”‚   β”œβ”€β”€ network/api_client.dart     # Dio client configuration
β”‚   β”œβ”€β”€ providers/api_providers.dart # Centralized providers ⭐
β”‚   └── state/base_state.dart       # Generic state classes
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ post.dart                   # Post model with JSON serialization
β”‚   └── user.dart                   # User model with nested objects
β”œβ”€β”€ pages/
β”‚   β”œβ”€β”€ posts_page.dart             # Posts UI with CRUD operations
β”‚   └── users_page.dart             # Users UI with rich details
β”œβ”€β”€ home_page.dart                  # Navigation hub
└── main.dart                       # App entry point with Material 3 theme

test/                               # Comprehensive test suite
β”œβ”€β”€ widget_test.dart                # App and navigation tests
β”œβ”€β”€ core/                           # Core system tests
β”‚   β”œβ”€β”€ baseui/error_api_test.dart  # Error widget tests
β”‚   β”œβ”€β”€ providers/api_providers_test.dart # Provider tests
β”‚   └── state/base_state_test.dart  # State management tests
└── models/                         # Model serialization tests
    β”œβ”€β”€ post_test.dart
    └── user_test.dart

οΏ½ Architecture Benefits

Why Unified API Architecture?

Traditional Clean Architecture Problems:

  • ❌ 12+ files per API endpoint
  • ❌ Repetitive boilerplate code
  • ❌ Complex folder structures
  • ❌ Difficult to maintain consistency
  • ❌ Slow feature development

Unified Architecture Solutions:

  • βœ… 2 files per API endpoint (90% reduction!)
  • βœ… Generic base classes eliminate repetition
  • βœ… Centralized provider management
  • βœ… Consistent error handling and UX
  • βœ… Rapid feature development

Real Performance Metrics:

  • Development Speed: 5x faster API integration
  • Code Maintainability: 90% less boilerplate to maintain
  • Learning Curve: New developers productive in hours, not days
  • Bug Reduction: Centralized patterns reduce common errors
  • Type Safety: Full generic type safety with IntelliSense support

οΏ½πŸ“± Platform Support

  • βœ… Android - Full native Android app support
  • βœ… iOS - Full native iOS app support
  • βœ… Web - Progressive Web App (PWA) support

πŸ”„ Using as Template

This repository showcases the future of Flutter architecture:

  1. For new projects: Clone and adapt the unified patterns
  2. For learning: Study how to eliminate architectural complexity
  3. For teams: Establish consistent, maintainable development patterns

Template Benefits

  • ⚑ Lightning-fast setup - Complete API integration in minutes
  • 🎯 Proven patterns - Battle-tested unified architecture
  • πŸ”’ Production ready - Comprehensive error handling and testing
  • πŸ“š Extensive documentation - Multiple guides and examples
  • πŸ§ͺ Test coverage - 30+ tests covering all scenarios
  • 🎨 Modern UI - Material 3 with Facebook-inspired theming

πŸ“š Documentation & Guides

  • SIMPLIFIED_API_GUIDE.md - Complete guide to the unified API system
  • NEW_VS_OLD_ARCHITECTURE.md - Detailed comparison with traditional approaches
  • TEST_DOCUMENTATION.md - Comprehensive test suite documentation

🀝 Contributing

This unified architecture template welcomes improvements and enhancements:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/UnifiedImprovement)
  3. Commit your changes (git commit -m 'Add unified architecture enhancement')
  4. Push to the branch (git push origin feature/UnifiedImprovement)
  5. Open a Pull Request

Areas for Contribution

  • Additional API patterns and examples
  • Enhanced error handling strategies
  • Performance optimizations
  • Additional platform integrations
  • Documentation improvements

🌟 Why This Matters

This project represents a paradigm shift in Flutter development:

Instead of fighting complexity, we eliminated it.

Traditional Clean Architecture, while well-intentioned, often creates more problems than it solves for typical API-driven applications. This unified approach maintains all the benefits (testability, maintainability, scalability) while eliminating the pain points (boilerplate, complexity, slow development).

Perfect for:

  • βœ… API-driven mobile applications
  • βœ… Teams wanting rapid development without sacrificing quality
  • βœ… Projects requiring consistent error handling and UX
  • βœ… Developers who prefer working with real code over abstract patterns

πŸ“„ License

This project template is open source and available under the MIT License.


πŸš€ Ready to experience the future of Flutter architecture?
Clone this repository and build your next API-driven application in record time!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages