diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 894298ad..00000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,9 +0,0 @@ -# Changelog - -## 1.1.0 - 2025-10-17 -- **feat**: allow configuration of saved headlines feed filters limits by user role and update dependencies - - -## 1.0.0 - 2025-10-13 - -- **BREAKING** feat!: migrated from date based versioning to semantic versioning. \ No newline at end of file diff --git a/README.md b/README.md index cfb21617..56edb1f0 100644 --- a/README.md +++ b/README.md @@ -107,9 +107,10 @@ Developed with best practices for a maintainable and scalable codebase: --- -### 🛠️ Flexible Environment Configuration -Switch between development (in-memory data or local API) and production environments with a simple code change. -> **🚀 Your Advantage:** This setup speeds up the development cycle and simplifies deployment. +### 🛠️ Production-Ready Environment Tooling +Utilizes compile-time variables (`--dart-define`) to seamlessly switch between `production`, `development`, and `demo` environments. +- **Error-Proof Configuration:** This approach ensures environment-specific settings like API endpoints are set at build time, preventing accidental release of development configurations. +> **Your Advantage:** A robust, professional environment setup that streamlines the development-to-production pipeline and prevents common configuration mistakes. --- diff --git a/lib/app/config/app_config.dart b/lib/app/config/app_config.dart index 1c1f793d..9fd4c666 100644 --- a/lib/app/config/app_config.dart +++ b/lib/app/config/app_config.dart @@ -1,19 +1,49 @@ import 'package:flutter_news_app_web_dashboard_full_source_code/app/config/app_environment.dart'; +/// A class to hold all environment-specific configurations. +/// +/// This class is instantiated in `main.dart` based on the compile-time +/// environment variable. It provides a type-safe way to access +/// environment-specific values like API base URLs. class AppConfig { - const AppConfig({required this.environment, required this.baseUrl}); + /// Creates a new [AppConfig]. + AppConfig({ + required this.environment, + required this.baseUrl, + // Add other environment-specific configs here (e.g., analytics keys) + }); - factory AppConfig.production() => const AppConfig( - environment: AppEnvironment.production, - baseUrl: 'http://api.yourproductiondomain.com', - ); + /// A factory constructor for the production environment. + /// + /// Reads the `BASE_URL` from a compile-time variable. Throws an exception + /// if the URL is not provided, ensuring a production build cannot proceed + /// with a missing configuration. This is a critical safety check. + factory AppConfig.production() { + const baseUrl = String.fromEnvironment('BASE_URL'); + if (baseUrl.isEmpty) { + // This check is crucial for production builds. + throw StateError( + 'FATAL: The BASE_URL compile-time variable was not provided for this ' + 'production build. Ensure the build command includes ' + '--dart-define=BASE_URL=https://your.api.com', + ); + } + return AppConfig(environment: AppEnvironment.production, baseUrl: baseUrl); + } - factory AppConfig.demo() => - const AppConfig(environment: AppEnvironment.demo, baseUrl: ''); + /// A factory constructor for the demo environment. + factory AppConfig.demo() => AppConfig( + environment: AppEnvironment.demo, + baseUrl: '', // No API access needed for in-memory demo + ); - factory AppConfig.development() => const AppConfig( + /// A factory constructor for the development environment. + factory AppConfig.development() => AppConfig( environment: AppEnvironment.development, - baseUrl: 'http://localhost:8080', + baseUrl: const String.fromEnvironment( + 'BASE_URL', + defaultValue: 'http://localhost:8080', + ), ); final AppEnvironment environment; diff --git a/lib/main.dart b/lib/main.dart index 340698d1..798864f8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,8 +5,14 @@ import 'package:flutter/material.dart'; import 'package:flutter_news_app_web_dashboard_full_source_code/app/config/config.dart'; import 'package:flutter_news_app_web_dashboard_full_source_code/bootstrap.dart'; -// Define the current application environment (production/development/demo). -const AppEnvironment appEnvironment = AppEnvironment.demo; +// Determine the current application environment from compile-time variables. +// Defaults to 'demo' if no environment is specified. +const AppEnvironment appEnvironment = + String.fromEnvironment('APP_ENVIRONMENT') == 'production' + ? AppEnvironment.production + : (String.fromEnvironment('APP_ENVIRONMENT') == 'development' + ? AppEnvironment.development + : AppEnvironment.demo); @JS('removeSplashFromWeb') external void removeSplashFromWeb();