-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added flavor config to the application
- Loading branch information
Showing
7 changed files
with
129 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/// Enum to define available app flavors | ||
/// | ||
/// This is used to differentiate between different versions of the app, | ||
/// such as development, staging, and production environments. | ||
enum Flavor { dev, staging, production } | ||
|
||
/// Class to manage flavor configurations | ||
/// | ||
/// This class provides a structure for managing different app flavors, | ||
/// allowing you to specify flavor-specific properties like the app name | ||
/// and API base URL. It includes helpers to determine the current flavor. | ||
class FlavorConfig { | ||
/// The current app flavor | ||
/// | ||
/// Defines whether the app is running in development, staging, or production. | ||
final Flavor flavor; | ||
|
||
/// The name of the application | ||
/// | ||
/// This can be used for display purposes to indicate the current flavor of the app. | ||
final String appName; | ||
|
||
/// The base URL for API calls | ||
/// | ||
/// This allows you to configure different backend environments for each flavor. | ||
final String apiBaseUrl; | ||
|
||
/// The human-readable name of the current flavor | ||
/// | ||
/// This is derived from the `Flavor` enum and is primarily used for logging or debugging. | ||
final String flavorName; | ||
|
||
/// Constructor | ||
/// | ||
/// Creates an instance of `FlavorConfig` with the specified properties. | ||
/// | ||
/// * [flavor] - The app flavor (e.g., `Flavor.dev` for development). | ||
/// * [appName] - The name of the app for the specified flavor. | ||
/// * [apiBaseUrl] - The API base URL for the specified flavor. | ||
FlavorConfig({ | ||
required this.flavor, | ||
required this.appName, | ||
required this.apiBaseUrl, | ||
}) : flavorName = flavor.name; | ||
|
||
/// Checks if the current flavor is development | ||
/// | ||
/// Returns `true` if the app is running in the development environment. | ||
bool get isDevelopment => flavor == Flavor.dev; | ||
|
||
/// Checks if the current flavor is staging | ||
/// | ||
/// Returns `true` if the app is running in the staging environment. | ||
bool get isStaging => flavor == Flavor.staging; | ||
|
||
/// Checks if the current flavor is production | ||
/// | ||
/// Returns `true` if the app is running in the production environment. | ||
bool get isProduction => flavor == Flavor.production; | ||
} | ||
|
||
/// Example of how to use this class with `get_it` for dependency injection: | ||
/// | ||
/// ```dart | ||
/// final getIt = GetIt.instance; | ||
/// getIt.registerSingleton<FlavorConfig>( | ||
/// FlavorConfig( | ||
/// flavor: Flavor.dev, | ||
/// appName: "My App Dev", | ||
/// apiBaseUrl: "https://api.dev.myapp.com", | ||
/// ), | ||
/// ); | ||
/// ``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import 'package:academia/app.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:academia/configs/configs.dart'; | ||
|
||
// Development's entry point | ||
void main() { | ||
runApp(const Academia(flavor: "development")); | ||
GetIt.instance.registerSingleton<FlavorConfig>( | ||
FlavorConfig( | ||
flavor: Flavor.dev, | ||
appName: "Academia - Dev", | ||
apiBaseUrl: "http://127.0.0.1:8000", | ||
), | ||
); | ||
runApp(const Academia()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import 'package:academia/app.dart'; | ||
import 'package:academia/configs/configs.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
|
||
// Production's entry point | ||
void main() { | ||
runApp(const Academia(flavor: "production")); | ||
GetIt.instance.registerSingleton<FlavorConfig>( | ||
FlavorConfig( | ||
flavor: Flavor.dev, | ||
appName: "Academia", | ||
apiBaseUrl: "http://127.0.0.1:8000", | ||
), | ||
); | ||
|
||
runApp(const Academia()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import 'package:academia/app.dart'; | ||
import 'package:academia/configs/configs.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
|
||
// Staging's entry point | ||
void main(List<String> args) { | ||
runApp(const Academia(flavor: "staging")); | ||
GetIt.instance.registerSingleton<FlavorConfig>( | ||
FlavorConfig( | ||
flavor: Flavor.dev, | ||
appName: "Academia - Staging", | ||
apiBaseUrl: "http://127.0.0.1:8000", | ||
), | ||
); | ||
|
||
runApp(const Academia()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters