-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Expand file tree
/
Copy pathapp_setting.dart
More file actions
75 lines (70 loc) · 2.75 KB
/
Copy pathapp_setting.dart
File metadata and controls
75 lines (70 loc) · 2.75 KB
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
class AppSetting {
final String locale;
final String themeMode;
final String environment;
final bool userLoggedIn;
final bool showSplashScreen;
final bool telemetryDialogDismissed;
final bool successfulConnection;
final String dataCapThreshold;
final bool onboardingCompleted;
const AppSetting({
this.themeMode = 'system',
this.environment = 'prod',
this.userLoggedIn = false,
this.locale = 'en_US',
this.showSplashScreen = true,
this.telemetryDialogDismissed = false,
this.successfulConnection = false,
this.dataCapThreshold = '',
this.onboardingCompleted = false,
});
/// Whether the app points at the staging backend. The notifier writes
/// 'stage'; 'staging' is accepted for older stored settings.
bool get isStaging => environment == 'stage' || environment == 'staging';
AppSetting copyWith({
String? newLocale,
String? themeMode,
String? environment,
bool? userLoggedIn,
bool? showSplashScreen,
bool? showTelemetryDialog,
bool? successfulConnection,
String? dataCapThreshold,
bool? onboardingCompleted,
}) {
return AppSetting(
locale: newLocale ?? locale,
themeMode: themeMode ?? this.themeMode,
environment: environment ?? this.environment,
userLoggedIn: userLoggedIn ?? this.userLoggedIn,
showSplashScreen: showSplashScreen ?? this.showSplashScreen,
telemetryDialogDismissed: showTelemetryDialog ?? telemetryDialogDismissed,
successfulConnection: successfulConnection ?? this.successfulConnection,
dataCapThreshold: dataCapThreshold ?? this.dataCapThreshold,
onboardingCompleted: onboardingCompleted ?? this.onboardingCompleted,
);
}
Map<String, dynamic> toJson() => {
'themeMode': themeMode,
'environment': environment,
'userLoggedIn': userLoggedIn,
'locale': locale,
'showSplashScreen': showSplashScreen,
'telemetryDialogDismissed': telemetryDialogDismissed,
'successfulConnection': successfulConnection,
'dataCapThreshold': dataCapThreshold,
'onboardingCompleted': onboardingCompleted,
};
factory AppSetting.fromJson(Map<String, dynamic> json) => AppSetting(
themeMode: (json['themeMode'] ?? 'system').toString(),
environment: (json['environment'] ?? 'prod').toString(),
userLoggedIn: json['userLoggedIn'] == true,
locale: (json['locale'] ?? 'en_US').toString(),
showSplashScreen: json['showSplashScreen'] != false,
telemetryDialogDismissed: json['telemetryDialogDismissed'] == true,
successfulConnection: json['successfulConnection'] == true,
dataCapThreshold: (json['dataCapThreshold'] ?? '').toString(),
onboardingCompleted: json['onboardingCompleted'] == true,
);
}