Skip to content

Instantly share code, notes, and snippets.

@yarn-rp
Last active October 21, 2022 22:01
Show Gist options
  • Save yarn-rp/df24a67b3ad75aef1feb40517724cafa to your computer and use it in GitHub Desktop.
Save yarn-rp/df24a67b3ad75aef1feb40517724cafa to your computer and use it in GitHub Desktop.
import 'package:injectable/injectable.dart';
/// {@template app_environment}
/// Use [AppEnvironment] to provide/access some information about the Environment app is
/// running.
///
/// Access [AppEnvironment] name with the [name] property.
///
/// Currently has supported 3 environments:
/// 1. [AppEnvironment.development] : Use it for develop dependencies. This is
/// the one you should use to inject dependencies in `main_development.dart`
/// file. Typically you want to use it to do development phase stuff like a
/// different backend url, or some very dev dependencies like a console logger.
/// 2. [AppEnvironment.staging] : Use it for staging dependencies. This is
/// the one you should use to inject dependencies in `main_staging.dart` file.
/// 3. [AppEnvironment.production] : Use if for production dependencies.
/// This file is the one you should use to inject dependencies in
/// `main_production.dart` file. Typically, you want to use it
/// to avoid development and staging dependencies.
/// {@endtemplate}
class AppEnvironment implements Environment {
/// {@macro app_environment}
const AppEnvironment(this.name);
static const AppEnvironment development = AppEnvironment('dev');
static const AppEnvironment production = AppEnvironment('prod');
static const AppEnvironment staging = AppEnvironment('stg');
@override
final String name;
}
/// Decorator for dependencies that are meant to run in `development`
/// environment.
const development = AppEnvironment.development;
/// Decorator for dependencies that are meant to run in `production`
/// environment.
const production = AppEnvironment.production;
/// Decorator for dependencies that are meant to run in `staging`
/// environment.
///
/// Annotate a class with `@staging` to mark it as a `staging`
/// dependency.
const staging = AppEnvironment.staging;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment