-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment_store.dart
80 lines (68 loc) · 2.17 KB
/
environment_store.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// ignore_for_file: do_not_use_environment
import 'package:flutter/foundation.dart';
/// Application environments.
abstract interface class IEnvironmentStore {
const IEnvironmentStore();
/// The current [EnvironmentFlavor] of a running application.
abstract final EnvironmentFlavor flavor;
/// Getting restrictions for the [scaleFactor] from the config.
abstract final ({double min, double max}) scaleFactor;
}
/// {@template IEnvironmentStore}
/// Implementation of a [IEnvironmentStore].
/// {@endtemplate}
final class EnvironmentStore implements IEnvironmentStore {
/// {@macro IEnvironmentStore}
const EnvironmentStore();
@override
EnvironmentFlavor get flavor => EnvironmentFlavor.fromString(
const String.fromEnvironment(
'ENVIRONMENT',
defaultValue: 'PRODUCTION',
),
);
@override
({double min, double max}) get scaleFactor => (
min: double.parse(
const String.fromEnvironment(
'MIN_SCALE_FACTOR',
defaultValue: '0.8',
),
),
max: double.parse(
const String.fromEnvironment(
'MAX_SCALE_FACTOR',
defaultValue: '1.4',
),
),
);
}
/// A list of flavors for the app.
///
/// You can track them in launch.json
enum EnvironmentFlavor {
/// Production flavor. Used by default.
production,
/// Development flavor.
///
/// It is expected to be used exclusively by developers and testers.
development;
/// The constructor for [EnvironmentFlavor] from String.
/// It will take values that will match in value.
/// Otherwise, it will take production flavor if the launch mod
/// is a release, or the development option if the mod is not a release one.
static EnvironmentFlavor fromString(final String value) {
switch (value) {
case 'PRODUCTION':
return production;
case 'DEVELOPMENT':
return development;
case _:
return kReleaseMode ? production : development;
}
}
/// Whether the environment is production.
bool get isProduction => this == production;
/// Whether the environment is development.
bool get isDevelopment => this == development;
}