Skip to content

A comprehensive Flutter boilerplate project using Getx for state management, themes, multi-language support, and custom widgets.

Notifications You must be signed in to change notification settings

KishanBusa8/flutter-getx-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Getx BoilerPlate

A Flutter application built with GetX for state management, featuring comprehensive theming, localization, and API services.

Features

  • 🎨 Dynamic Theming: Light and dark mode support with automatic color adaptation
  • 🌍 Multi-language Support: Support for multiple languages with RTL support
  • πŸ”„ GetX State Management: Complete state management solution
  • 🌐 API Service: Comprehensive HTTP client with error handling
  • πŸ“± Responsive Design: Adaptive UI for different screen sizes
  • 🎯 Type Safety: Full TypeScript-like type safety with Dart
  • πŸ›  Modular Architecture: Clean and scalable project structure

Project Structure

lib/
β”œβ”€β”€ core/
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ theme_controller.dart      # Theme management (dark/light mode)
β”‚   β”‚   └── language_controller.dart   # Language/localization management
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── api_service.dart          # HTTP client and API handling
β”‚   β”œβ”€β”€ theme/
β”‚   β”‚   β”œβ”€β”€ app_colors.dart           # Color scheme (light/dark)
β”‚   β”‚   β”œβ”€β”€ app_text_styles.dart      # Text styles with theme adaptation
β”‚   β”‚   └── app_theme.dart            # Complete theme configuration
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── app_routes.dart           # Route definitions and navigation
β”‚   β”œβ”€β”€ constants/
β”‚   β”‚   └── api_constants.dart        # API endpoints and constants
β”‚   └── utils/
β”‚       └── app_utils.dart            # Utility functions and widgets
β”œβ”€β”€ features/                         # Feature-based modules (to be added)
β”‚   β”œβ”€β”€ auth/
β”‚   β”œβ”€β”€ home/
β”‚   β”œβ”€β”€ profile/
β”‚   └── settings/
└── main.dart                         # App entry point

Getting Started

Prerequisites

  • Flutter SDK (3.6.2 or higher)
  • Dart SDK
  • Android Studio / VS Code
  • Git

Installation

  1. Clone the repository:
git clone <repository-url>
cd flutter-getx-boilerplate
  1. Install dependencies:
flutter pub get
  1. Run the app:
flutter run

Dependencies

Core Dependencies

  • get: ^4.6.6 - State management, routing, and dependency injection
  • shared_preferences: ^2.2.2 - Local data persistence
  • http: ^1.1.0 - HTTP client for API calls
  • flutter_localizations: SDK - Internationalization support

Architecture

State Management with GetX

The app uses GetX for comprehensive state management:

  • Controllers: Manage business logic and state
  • Reactive Programming: Automatic UI updates with .obs variables
  • Dependency Injection: Automatic controller lifecycle management

Theme System

The theme system automatically adapts to light/dark mode:

// Colors automatically adapt to theme
Color primaryColor = AppColors.primary;

// Text styles automatically use correct colors
TextStyle titleStyle = AppTextStyles.titleLarge;

API Service

The API service provides a clean interface for HTTP requests:

// GET request
final response = await ApiService.to.get('/users');

// POST request
final response = await ApiService.to.post('/users', body: userData);

// Handle response
if (response.isSuccess) {
  final data = response.data;
} else {
  print(response.message);
}

Usage Examples

Theme Management

// Get theme controller
final themeController = Get.find<ThemeController>();

// Toggle theme
themeController.toggleTheme();

// Set specific theme
themeController.setThemeMode(ThemeMode.dark);

// Check current theme
bool isDark = themeController.isDarkMode;

Language Management

// Get language controller
final languageController = Get.find<LanguageController>();

// Change language
languageController.changeLanguage('es', 'ES');

// Get current language
String languageName = languageController.getCurrentLanguageName();

// Check RTL support
bool isRTL = languageController.isRTL();

Using Colors and Text Styles

// Colors automatically adapt to theme
Container(
  color: AppColors.primary,
  child: Text(
    'Hello World',
    style: AppTextStyles.headlineLarge,
  ),
)

// Custom text style
Text(
  'Custom Text',
  style: AppTextStyles.custom(
    fontSize: 18,
    fontWeight: FontWeight.bold,
  ),
)

API Calls

// Simple GET request
final response = await ApiService.to.get('/api/users');

// POST with body
final response = await ApiService.to.post(
  '/api/users',
  body: {
    'name': 'John Doe',
    'email': '[email protected]',
  },
);

// Handle response
if (response.isSuccess) {
  AppUtils.showSuccess('Data loaded successfully');
  final data = response.data;
} else {
  AppUtils.showError(response.message);
}

Utility Functions

// Show loading
AppUtils.showLoading('Loading data...');

// Hide loading
AppUtils.hideLoading();

// Show snackbars
AppUtils.showSuccess('Operation successful');
AppUtils.showError('Something went wrong');
AppUtils.showWarning('Please check your input');
AppUtils.showInfo('New feature available');

// Show confirmation dialog
final confirmed = await AppUtils.showConfirmation(
  title: 'Delete Item',
  message: 'Are you sure you want to delete this item?',
);

Adding New Features

1. Create Feature Structure

lib/features/your_feature/
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ repositories/
β”‚   └── datasources/
β”œβ”€β”€ domain/
β”‚   β”œβ”€β”€ entities/
β”‚   β”œβ”€β”€ repositories/
β”‚   └── usecases/
└── presentation/
    β”œβ”€β”€ controllers/
    β”œβ”€β”€ pages/
    └── widgets/

2. Add Routes

// In app_routes.dart
static const String yourFeature = '/your-feature';

// Add to getPages list
GetPage(
  name: yourFeature,
  page: () => const YourFeaturePage(),
  transition: Transition.rightToLeft,
),

3. Create Controller

class YourFeatureController extends GetxController {
  final _data = <String>[].obs;
  
  List<String> get data => _data;
  
  @override
  void onInit() {
    super.onInit();
    loadData();
  }
  
  Future<void> loadData() async {
    // Your logic here
  }
}

Configuration

API Configuration

Update the base URL in lib/core/constants/api_constants.dart:

static const String baseUrl = 'https://your-api-url.com/v1';

Theme Customization

Modify colors in lib/core/theme/app_colors.dart:

static Color get primary => _themeController.isDarkMode 
  ? const Color(0xFF64B5F6) 
  : const Color(0xFF1976D2);

Adding New Languages

Add new locales in lib/core/controllers/language_controller.dart:

final _supportedLocales = <Locale>[
  const Locale('en', 'US'),
  const Locale('es', 'ES'),
  // Add your new locale here
  const Locale('your', 'CODE'),
].obs;

Best Practices

  1. Use GetX Controllers: Always use GetX controllers for state management
  2. Theme-Aware Colors: Always use AppColors instead of hardcoded colors
  3. Consistent Text Styles: Use AppTextStyles for consistent typography
  4. Error Handling: Always handle API errors gracefully
  5. Loading States: Show loading indicators for async operations
  6. Type Safety: Use proper types for all variables and functions

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

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

Support

For support and questions, please open an issue in the repository or contact the development team.


Note: This is a template project structure. You can modify and extend it according to your specific requirements.

About

A comprehensive Flutter boilerplate project using Getx for state management, themes, multi-language support, and custom widgets.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published