Files
fcs/lib/config.dart

56 lines
1.6 KiB
Dart
Raw Normal View History

2020-05-29 07:45:27 +06:30
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
2021-08-25 19:00:04 +06:30
enum Flavor { UNSET, DEV, STAGING, PRODUCTION, LOCAL }
const FlavorNames = ["Unset", "Development", "Staging", "Production", "Local"];
2020-05-29 07:45:27 +06:30
class Config {
2021-08-25 19:00:04 +06:30
static Config _instance = Config(
flavor: Flavor.UNSET,
apiURL: "",
bucketName: "",
reportProjectID: "",
reportURL: "");
2020-05-29 07:45:27 +06:30
final Flavor flavor;
final String name;
final Color color;
final String apiURL;
final String reportURL;
final Level level;
final String reportProjectID;
2021-01-05 18:03:51 +06:30
final String bucketName;
2020-05-29 07:45:27 +06:30
factory Config(
2021-08-25 19:00:04 +06:30
{required Flavor flavor,
required String apiURL,
required String reportURL,
required String reportProjectID,
required String bucketName,
2020-05-29 07:45:27 +06:30
Color color: Colors.blue,
Level level: Level.SEVERE}) {
2021-08-25 19:00:04 +06:30
_instance = Config._internal(flavor, FlavorNames[flavor.index], color,
2021-01-05 18:03:51 +06:30
apiURL, reportURL, level, reportProjectID, bucketName);
2020-05-29 07:45:27 +06:30
Logger.root.level = level;
Logger.root.onRecord.listen((record) {
print(
'${record.level.name}: ${record.time}: ${record.loggerName}: ${record.message}');
});
return _instance;
}
Config._internal(this.flavor, this.name, this.color, this.apiURL,
2021-01-05 18:03:51 +06:30
this.reportURL, this.level, this.reportProjectID, this.bucketName);
2020-05-29 07:45:27 +06:30
static Config get instance {
return _instance;
}
static bool isProduction() => _instance.flavor == Flavor.PRODUCTION;
static bool isDevelopment() => _instance.flavor == Flavor.DEV;
static bool isStaging() => _instance.flavor == Flavor.STAGING;
static bool isLocal() => _instance.flavor == Flavor.LOCAL;
}