-
Notifications
You must be signed in to change notification settings - Fork 12
/
remote_config_service.dart
129 lines (108 loc) · 3.49 KB
/
remote_config_service.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//SERVICE
// Package imports:
import 'package:firebase_remote_config/firebase_remote_config.dart';
// Project imports:
import 'package:notredame/core/services/analytics_service.dart';
import 'package:notredame/locator.dart';
//OTHERS
/// Manage the analytics of the application
class RemoteConfigService {
static const String tag = "RemoteConfigService";
static const _serviceIsDown = "service_is_down";
// Privacy policy
static const _privacyPolicyToggle = "privacy_policy_toggle";
static const _privacyPolicyURL = "privacy_policy_url";
// dashboard message remote config keys
static const _dashboardMsgToggle = "dashboard_message_toggle";
static const _dashboardMsgFr = "dashboard_message_fr";
static const _dashboardMsgEn = "dashboard_message_en";
static const _dashboardMsgTitleFr = "dashboard_message_title_fr";
static const _dashboardMsgTitleEn = "dashboard_message_title_en";
static const _dashboardMsgColor = "dashboard_message_color";
static const _dashboardMsgUrl = "dashboard_message_url";
static const _dashboardMsgType = "dashboard_message_type";
static const _scheduleListViewDefault = "schedule_list_view_default";
final FirebaseRemoteConfig _remoteConfig = FirebaseRemoteConfig.instance;
final defaults = <String, dynamic>{
_serviceIsDown: false,
_privacyPolicyURL: "",
_dashboardMsgFr: "",
_dashboardMsgEn: "",
_dashboardMsgTitleFr: "",
_dashboardMsgTitleEn: "",
_dashboardMsgColor: "",
_dashboardMsgUrl: "",
_dashboardMsgType: "",
_privacyPolicyToggle: true,
_scheduleListViewDefault: true
};
Future initialize() async {
await _remoteConfig.setDefaults(defaults);
await _fetchAndActivate();
}
bool get outage {
fetch();
return _remoteConfig.getBool(_serviceIsDown);
}
bool get dashboardMessageActive {
fetch();
return _remoteConfig.getBool(_dashboardMsgToggle);
}
bool get scheduleListViewDefault {
fetch();
return _remoteConfig.getBool(_scheduleListViewDefault);
}
bool get privacyPolicyToggle {
fetch();
return _remoteConfig.getBool(_privacyPolicyToggle);
}
String get privacyPolicyUrl {
fetch();
return _remoteConfig.getString(_privacyPolicyURL);
}
String get dashboardMessageFr {
fetch();
return _remoteConfig.getString(_dashboardMsgFr);
}
String get dashboardMessageEn {
fetch();
return _remoteConfig.getString(_dashboardMsgEn);
}
String get dashboardMessageTitleFr {
fetch();
return _remoteConfig.getString(_dashboardMsgTitleFr);
}
String get dashboardMessageTitleEn {
fetch();
return _remoteConfig.getString(_dashboardMsgTitleEn);
}
String get dashboardMsgColor {
fetch();
return _remoteConfig.getString(_dashboardMsgColor);
}
String get dashboardMsgUrl {
fetch();
return _remoteConfig.getString(_dashboardMsgUrl);
}
String get dashboardMsgType {
fetch();
return _remoteConfig.getString(_dashboardMsgType);
}
Future<void> fetch() async {
final AnalyticsService analyticsService = locator<AnalyticsService>();
try {
await _remoteConfig.fetch();
await _remoteConfig.fetchAndActivate();
} on Exception catch (exception) {
analyticsService.logError(
tag, "Exception raised during fetching: $exception", exception);
}
}
Future _fetchAndActivate() async {
fetch();
_remoteConfig.setConfigSettings(RemoteConfigSettings(
fetchTimeout: const Duration(seconds: 30),
minimumFetchInterval: const Duration(minutes: 1),
));
}
}