Skip to content

koniz-dev/flutter-starter

Repository files navigation

πŸš€ Flutter Starter

A production-ready Flutter starter project with Clean Architecture, enterprise-grade configuration management, and comprehensive developer tooling.

Flutter Dart License Tests Architecture

✨ Features

πŸ—οΈ Architecture & Code Quality

  • βœ… Clean Architecture - Separation of concerns with Domain, Data, and Presentation layers
  • βœ… State Management - Riverpod for reactive state management
  • βœ… Code Generation - Freezed for immutable classes and JSON serialization
  • βœ… Linting - Very Good Analysis for comprehensive code quality checks
  • βœ… Testing - Mocktail for unit testing with comprehensive test coverage

βš™οΈ Configuration & Environment

  • βœ… Multi-Environment Support - Development, Staging, Production
  • βœ… Flexible Configuration - .env files for local dev, --dart-define for CI/CD
  • βœ… Feature Flags - Local and remote (Firebase Remote Config) feature flags
  • βœ… Environment-Aware Defaults - Smart defaults based on environment
  • βœ… Type-Safe Configuration - Typed getters with fallback chain

🌐 Internationalization

  • βœ… Multi-Language Support - Flutter localization with ARB files
  • βœ… RTL Support - Right-to-left language support
  • βœ… Locale Persistence - Save and restore user language preference

πŸ” Security & Storage

  • βœ… Secure Storage - Flutter Secure Storage for sensitive data
  • βœ… Shared Preferences - Simple key-value storage for non-sensitive data
  • βœ… Storage Migration - Version-based storage migration system
  • βœ… Error Handling - Comprehensive error handling with custom exceptions

🌐 Network Layer

  • βœ… HTTP Client - Dio with interceptors support
  • βœ… Configurable Timeouts - Environment-based timeout configuration
  • βœ… Request/Response Logging - Debug-friendly HTTP logging
  • βœ… Error Interceptors - Automatic error handling and conversion
  • βœ… Auth Interceptors - Automatic token injection and refresh

🎨 UI & UX

  • βœ… Material Design - Material 3 theme support
  • βœ… Dark Mode - Built-in dark theme support
  • βœ… Accessibility - Semantic labels and accessibility support
  • βœ… Responsive Design - Adaptive layouts for different screen sizes

🧭 Routing & Navigation

  • βœ… Type-Safe Routing - GoRouter with type-safe route definitions
  • βœ… Deep Linking - Support for deep links and URL navigation
  • βœ… Auth-Based Routing - Protected routes with authentication redirects
  • βœ… Navigation Logging - Automatic route tracking and logging

πŸ“Š Logging & Monitoring

  • βœ… Comprehensive Logging - Multi-level logging with file and console output
  • βœ… Log Rotation - Automatic log file rotation
  • βœ… Structured Logging - JSON formatting for production
  • βœ… Performance Monitoring - Firebase Performance integration
  • βœ… Screen Tracking - Automatic screen load time tracking

πŸš€ Deployment & CI/CD

  • βœ… Multi-Platform - Android, iOS, Web, Linux, macOS, Windows support
  • βœ… CI/CD Ready - GitHub Actions workflows included (disabled by default, uncomment triggers to enable)
  • βœ… Version Management - Automated version bumping scripts
  • βœ… Fastlane Integration - iOS and Android deployment automation

πŸ“š Documentation

  • βœ… Comprehensive Docs - Architecture, guides, API documentation
  • βœ… Migration Guides - From MVC, GetX, Bloc, and other architectures
  • βœ… Best Practices - Code examples and patterns
  • βœ… API Documentation - Complete API reference
  • βœ… Example Features - 3 complete example features (Auth, Feature Flags, Tasks)

πŸ§ͺ Testing

  • βœ… 66 Test Files - Comprehensive test coverage
  • βœ… Unit Tests - Domain and data layer testing
  • βœ… Widget Tests - UI component testing
  • βœ… Integration Tests - End-to-end flow testing
  • βœ… Test Helpers - Reusable test utilities and fixtures

πŸ› οΈ Tech Stack

Core Dependencies

  • Flutter - UI framework
  • Riverpod - State management
  • Dio - HTTP client
  • Freezed - Code generation for immutable classes
  • Equatable - Value equality comparison

Firebase

  • Firebase Core - Firebase initialization
  • Firebase Remote Config - Remote feature flags
  • Firebase Performance - Performance monitoring and tracking

Storage

  • flutter_secure_storage - Secure storage for sensitive data
  • shared_preferences - Simple key-value storage

Localization

  • flutter_localizations - Flutter localization support
  • intl - Internationalization utilities

Routing & Navigation

  • go_router - Declarative routing with deep linking

Logging & Monitoring

  • logger - Comprehensive logging solution
  • path_provider - File system access for log files

Development Tools

  • build_runner - Code generation runner
  • very_good_analysis - Linting rules
  • mocktail - Testing and mocking

πŸ“ Project Structure

lib/
β”œβ”€β”€ core/                    # Core infrastructure
β”‚   β”œβ”€β”€ config/             # Configuration system
β”‚   β”œβ”€β”€ constants/          # App constants
β”‚   β”œβ”€β”€ di/                 # Dependency injection (Riverpod providers)
β”‚   β”œβ”€β”€ errors/             # Error handling
β”‚   β”œβ”€β”€ feature_flags/      # Feature flags infrastructure
β”‚   β”œβ”€β”€ localization/       # Localization service
β”‚   β”œβ”€β”€ logging/            # Logging service
β”‚   β”œβ”€β”€ network/            # Network layer (Dio setup)
β”‚   β”œβ”€β”€ performance/        # Performance monitoring
β”‚   β”œβ”€β”€ routing/            # Routing system (go_router)
β”‚   β”œβ”€β”€ storage/            # Storage services (with migration)
β”‚   └── utils/              # Utility functions
β”‚
β”œβ”€β”€ features/                # Feature modules (Clean Architecture)
β”‚   β”œβ”€β”€ auth/               # Authentication feature example
β”‚   β”‚   β”œβ”€β”€ data/          # Data layer (models, data sources, repositories)
β”‚   β”‚   β”œβ”€β”€ domain/        # Domain layer (entities, use cases, repository interfaces)
β”‚   β”‚   └── presentation/  # Presentation layer (screens, widgets, providers)
β”‚   β”œβ”€β”€ feature_flags/      # Feature flags feature
β”‚   β”‚   └── presentation/   # Feature flags UI
β”‚   └── tasks/              # Tasks feature (CRUD example)
β”‚       β”œβ”€β”€ data/          # Data layer
β”‚       β”œβ”€β”€ domain/        # Domain layer
β”‚       └── presentation/  # Presentation layer
β”‚
β”œβ”€β”€ shared/                  # Shared resources
β”‚   β”œβ”€β”€ accessibility/      # Accessibility utilities
β”‚   β”œβ”€β”€ extensions/         # Dart extensions
β”‚   β”œβ”€β”€ theme/              # App theme configuration
β”‚   └── widgets/            # Reusable widgets
β”‚
β”œβ”€β”€ l10n/                   # Localization files (generated)
└── main.dart               # App entry point

πŸš€ Getting Started

Prerequisites

  • Flutter SDK (>=3.0.0)
  • Dart SDK (>=3.0.0)
  • Android Studio / VS Code with Flutter extensions
  • Xcode (for iOS development on macOS)

Installation

  1. Create repository from template (if using GitHub template)

    • Click "Use this template" button on GitHub
    • Create a new repository from this template
    • Clone your new repository:
    git clone <your-repository-url>
    cd <your-project-name>

    OR clone directly (if not using template):

    git clone <repository-url>
    cd flutter_starter
  2. Install dependencies

    flutter pub get
  3. Generate code (Freezed, JSON serialization)

    flutter pub run build_runner build --delete-conflicting-outputs
  4. Set up environment configuration

    # Copy the example environment file
    cp .env.example .env
    
    # Edit .env with your configuration
    # See Configuration System section below
  5. Set up Git hooks (optional but recommended)

    ./scripts/setup-git-hooks.sh

    This will install Git hooks for:

    • Code formatting checks (pre-commit)
    • Commit message validation (commit-msg)
    • Test execution (pre-push)
  6. Run the app

    flutter run

First Steps

  1. Rename the project (if needed) - Update package name from flutter_starter to your project name
  2. Configure your environment - See Configuration System below
  3. Set up Firebase (optional) - For remote feature flags and performance monitoring
    • Add google-services.json (Android) and GoogleService-Info.plist (iOS)
    • Initialize Firebase in your app
  4. Customize the theme - Edit lib/shared/theme/app_theme.dart
  5. Explore example features - Check out lib/features/ for examples:
    • Auth - Authentication flow example
    • Feature Flags - Feature flags UI example
    • Tasks - Complete CRUD example with local storage
  6. Add your first feature - Follow the pattern in example features
  7. Read the documentation - Check out docs/ folder for detailed guides

βš™οΈ Configuration System

This project includes a production-ready, multi-environment configuration system that supports:

  • Local Development: .env files for easy local configuration
  • CI/CD: --dart-define flags for build-time configuration
  • Fallback Chain: .env β†’ --dart-define β†’ defaults
  • Environment-Aware Defaults: Different configurations per environment
  • Feature Flags: Enable/disable features per environment
  • Network Configuration: Timeout settings for API calls
  • Debug Utilities: Tools for inspecting configuration

Architecture

The configuration system consists of two main classes:

  1. EnvConfig (lib/core/config/env_config.dart): Low-level environment variable loader

    • Loads from .env files using flutter_dotenv
    • Reads from --dart-define flags
    • Provides fallback chain: .env β†’ --dart-define β†’ defaults
  2. AppConfig (lib/core/config/app_config.dart): High-level application configuration

    • Uses EnvConfig to get values
    • Provides typed getters (String, bool, int)
    • Environment-aware defaults
    • Feature flags
    • Network timeout configuration
    • Debug utilities

Setup

1. Create .env file for local development

# Copy the example file
cp .env.example .env

# Edit .env with your values
# The .env file is gitignored and won't be committed

2. Configure your environment variables

Edit .env with your configuration:

ENVIRONMENT=development
BASE_URL=http://localhost:3000
ENABLE_LOGGING=true
ENABLE_ANALYTICS=false

Usage Examples

Local Development (using .env file)

  1. Create .env file from .env.example
  2. Fill in your values
  3. Run the app normally:
flutter run

The app will automatically load values from .env.

Staging Build (using --dart-define)

For CI/CD or when you don't want to use .env files:

flutter run \
  --dart-define=ENVIRONMENT=staging \
  --dart-define=BASE_URL=https://api-staging.example.com \
  --dart-define=ENABLE_ANALYTICS=true

Production Build (using --dart-define)

flutter build apk \
  --dart-define=ENVIRONMENT=production \
  --dart-define=BASE_URL=https://api.example.com \
  --dart-define=ENABLE_ANALYTICS=true \
  --dart-define=ENABLE_CRASH_REPORTING=true

Using Configuration in Code

Basic Usage

import 'package:flutter_starter/core/config/app_config.dart';

// Get environment
final env = AppConfig.environment; // 'development', 'staging', or 'production'

// Check environment
if (AppConfig.isDevelopment) {
  // Development-specific code
}

// Get API base URL
final baseUrl = AppConfig.baseUrl;

// Check feature flags
if (AppConfig.enableLogging) {
  logger.info('App started');
}

if (AppConfig.enableAnalytics) {
  analytics.trackEvent('app_opened');
}

Network Configuration

import 'package:flutter_starter/core/config/app_config.dart';
import 'package:dio/dio.dart';

final dio = Dio(
  BaseOptions(
    baseUrl: AppConfig.baseUrl,
    connectTimeout: Duration(seconds: AppConfig.apiConnectTimeout),
    receiveTimeout: Duration(seconds: AppConfig.apiReceiveTimeout),
    sendTimeout: Duration(seconds: AppConfig.apiSendTimeout),
  ),
);

Debug Utilities

import 'package:flutter_starter/core/config/app_config.dart';

// Print configuration to console (only in debug mode)
AppConfig.printConfig();

// Get configuration as a map
final config = AppConfig.getDebugInfo();
print(config);

Available Configuration Options

Environment Variables

Variable Type Default Description
ENVIRONMENT String development Environment name: development, staging, or production
BASE_URL String Environment-aware API base URL (see defaults below)
API_TIMEOUT int 30 API timeout in seconds
API_CONNECT_TIMEOUT int 10 API connect timeout in seconds
API_RECEIVE_TIMEOUT int 30 API receive timeout in seconds
API_SEND_TIMEOUT int 30 API send timeout in seconds
ENABLE_LOGGING bool Environment-aware Enable logging (default: true in dev/staging)
ENABLE_ANALYTICS bool Environment-aware Enable analytics (default: true in staging/prod)
ENABLE_CRASH_REPORTING bool Environment-aware Enable crash reporting (default: true in staging/prod)
ENABLE_PERFORMANCE_MONITORING bool Environment-aware Enable performance monitoring (default: true in staging/prod)
ENABLE_DEBUG_FEATURES bool Environment-aware Enable debug features (default: true in dev)
ENABLE_HTTP_LOGGING bool Environment-aware Enable HTTP request/response logging (default: true in dev)
APP_VERSION String 1.0.0 App version
APP_BUILD_NUMBER String 1 App build number

Environment-Aware Defaults

BASE_URL defaults:

  • Development: http://localhost:3000
  • Staging: https://api-staging.example.com
  • Production: https://api.example.com

Feature Flag defaults:

  • Logging: Enabled in development and staging
  • Analytics: Enabled in staging and production
  • Crash Reporting: Enabled in staging and production
  • Performance Monitoring: Enabled in staging and production
  • Debug Features: Enabled in development only
  • HTTP Logging: Enabled in development only

Best Practices

  1. Never commit .env files: They contain sensitive information and are gitignored
  2. Use .env.example as a template: Commit this file with placeholder values
  3. Use .env for local development: Easy to change values without rebuilding
  4. Use --dart-define for CI/CD: More secure and doesn't require file management
  5. Set environment-specific defaults: Let the system handle defaults based on environment
  6. Use feature flags: Enable/disable features per environment without code changes

Troubleshooting

Configuration not loading

  1. Ensure EnvConfig.load() is called in main() before runApp()
  2. Check that .env file exists in the project root
  3. Verify pubspec.yaml includes .env in assets
  4. Run flutter pub get after adding flutter_dotenv

Values not updating

  1. Hot reload doesn't reload environment variables - do a full restart
  2. For --dart-define values, rebuild the app
  3. Check that you're using the correct variable name (case-sensitive)

Debug configuration

Use AppConfig.printConfig() in debug mode to see all configuration values:

if (AppConfig.isDebugMode) {
  AppConfig.printConfig();
}

This will print all configuration values to the console, helping you verify what values are being used.

πŸ§ͺ Testing

Run Tests

# Run all tests
flutter test

# Run tests with coverage
flutter test --coverage

# Run specific test file
flutter test test/features/auth/domain/usecases/login_test.dart

Test Structure

Tests follow the same structure as the source code:

  • 66 test files with comprehensive coverage
  • Unit tests for use cases and utilities
  • Widget tests for UI components
  • Integration tests for end-to-end flows
  • Test helpers and fixtures for reusable test utilities

Test Coverage

The project includes:

  • βœ… Domain layer tests (use cases, entities)
  • βœ… Data layer tests (repositories, data sources, models)
  • βœ… Presentation layer tests (screens, widgets, providers)
  • βœ… Core infrastructure tests (config, network, storage, logging, performance)
  • βœ… Integration tests for complete flows

πŸ—οΈ Building

Android

# Debug APK
flutter build apk --debug

# Release APK
flutter build apk --release

# App Bundle (for Play Store)
flutter build appbundle --release

iOS

# Debug
flutter build ios --debug

# Release
flutter build ios --release

Web

# Debug
flutter build web --debug

# Release
flutter build web --release

πŸ“š Documentation

Architecture

Guides

Migration Guides

Features

Deployment

API Documentation

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details on:

  • How to report bugs
  • How to suggest enhancements
  • Development setup and workflow
  • Coding standards and guidelines
  • Testing requirements
  • Commit message conventions

Quick Start

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes following our coding standards
  4. Write or update tests
  5. Commit your changes using conventional commits
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

For detailed guidelines, please read CONTRIBUTING.md.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support

For questions, issues, or contributions, please open an issue on GitHub.


Made with ❀️ using Flutter

About

A production-ready Flutter starter project.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published