flavor_config.dart 577 B

123456789101112131415161718192021
  1. /// Flavor 环境标识
  2. /// 通过 --dart-define=FLAVOR=dev|staging|prod 注入
  3. enum Flavor { dev, staging, prod }
  4. abstract class FlavorConfig {
  5. static const _raw = String.fromEnvironment('FLAVOR', defaultValue: 'dev');
  6. static Flavor get current {
  7. return switch (_raw) {
  8. 'prod' => Flavor.prod,
  9. 'staging' => Flavor.staging,
  10. _ => Flavor.dev,
  11. };
  12. }
  13. static bool get isDev => current == Flavor.dev;
  14. static bool get isStaging => current == Flavor.staging;
  15. static bool get isProd => current == Flavor.prod;
  16. static String get name => _raw;
  17. }