Environment Configuration
Viax supports multiple environments with different backend configurations. Learn how to switch between local development, staging, and production setups.Environment Types
Development
Local development with Laragon
- Backend: localhost
- Database: Local MySQL
- Hot reload enabled
- Debug mode active
Staging
Testing environment
- Backend: Staging server
- Database: Test database
- Mirrors production
- Safe for testing
Production
Live environment
- Backend: VPS (76.13.114.194)
- Database: Production MySQL
- Optimized builds
- Real user data
Configuration Architecture
Viax uses a centralized configuration system that automatically detects the environment based on the API base URL.AppConfig Class
Location:lib/src/core/config/app_config.dart
Environment Setup
Development (Local)
- Android Emulator
- Physical Device
- iOS Simulator
- Web Browser
The Android emulator maps Full URL structure:
localhost to 10.0.2.2.- Base:
http://10.0.2.2/viax/backend - Auth:
http://10.0.2.2/viax/backend/auth - Conductor:
http://10.0.2.2/viax/backend/conductor - User:
http://10.0.2.2/viax/backend/user - Admin:
http://10.0.2.2/viax/backend/admin
Staging (Optional)
If you have a staging server:Production
Connect to the live VPS server:Backend Configuration
Development Backend (Laragon)
File:backend/config/database.php
Production Backend (VPS)
File:backend/config/database.php
Environment Variables
Flutter Environment Variables
Viax supports custom configuration through Dart defines:- API Configuration
- Map Services
- Feature Flags
Environment File (Recommended)
Create configuration files for different environments:config/dev.env:
config/prod.env:
VS Code Launch Configurations
Create.vscode/launch.json for easy environment switching:
- Press F5 in VS Code
- Select configuration from dropdown
- App launches with selected environment
Testing Configuration
Verify Backend Connection
Create a simple test to verify your configuration:Manual Health Check
Test backend endpoints directly:URL Structure Reference
Complete URL Mapping
- Development (Emulator)
- Production
Build Configurations
Development Build
Staging Build
Production Build
Environment-Specific Features
Debug Mode Features
Analytics Control
Troubleshooting
Connection Refused (Emulator)
Connection Refused (Emulator)
Problem: Canโt connect to
localhost from Android emulatorSolution:- Use
10.0.2.2instead oflocalhost - Verify Laragon/backend is running
- Check firewall settings
Connection Refused (Physical Device)
Connection Refused (Physical Device)
Problem: Canโt connect using local IPSolution:
- Verify same WiFi network
- Check IP address is correct
- Disable firewall temporarily to test
- Use explicit IP, not hostname
Environment Not Detected
Environment Not Detected
Problem: App using wrong environmentSolution:
- Verify
--dart-definesyntax - Check for typos in URL
- Print environment in app:
Cached Old Configuration
Cached Old Configuration
Problem: App still using old base URLSolution:
Best Practices
Never Hardcode URLs
Always use
AppConfig.baseUrl instead of hardcoded URLs in your code.Use Launch Configs
Set up VS Code launch configurations for quick environment switching.
Test All Environments
Test features in development before deploying to production.
Secure Production
Use HTTPS, strong passwords, and proper authentication in production.
Configuration Complete! You can now switch between environments seamlessly and configure Viax for any deployment scenario.