-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Expand file tree
/
Copy pathapp_setting.dart
More file actions
109 lines (105 loc) · 4.49 KB
/
Copy pathapp_setting.dart
File metadata and controls
109 lines (105 loc) · 4.49 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
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
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;
// Unbounded preferences. autoEnable: turn the peer share on whenever
// the VPN connects (defaults on per the Figma spec). hideTab: hide
// the Unbounded tab + collapse the tab bar when the user doesn't
// want to see it. welcomeSeen: tracks the first-visit info popup so
// we only show it once. All persisted across launches.
final bool unboundedAutoEnable;
final bool unboundedHidden;
final bool unboundedWelcomeSeen;
// Lifetime running total of peers this device has helped. Survives
// restarts so the "Total people helped to date" stat in the
// Unbounded tab can keep climbing — that's the spec wording in the
// Figma. ShareNotifier seeds totalCount from this on build, and
// writes back each time the count increments.
final int unboundedTotalHelped;
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,
this.unboundedAutoEnable = true,
this.unboundedHidden = false,
this.unboundedWelcomeSeen = false,
this.unboundedTotalHelped = 0,
});
AppSetting copyWith({
String? newLocale,
String? themeMode,
String? environment,
bool? userLoggedIn,
bool? showSplashScreen,
bool? showTelemetryDialog,
bool? successfulConnection,
String? dataCapThreshold,
bool? onboardingCompleted,
bool? unboundedAutoEnable,
bool? unboundedHidden,
bool? unboundedWelcomeSeen,
int? unboundedTotalHelped,
}) {
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,
unboundedAutoEnable: unboundedAutoEnable ?? this.unboundedAutoEnable,
unboundedHidden: unboundedHidden ?? this.unboundedHidden,
unboundedWelcomeSeen: unboundedWelcomeSeen ?? this.unboundedWelcomeSeen,
unboundedTotalHelped:
unboundedTotalHelped ?? this.unboundedTotalHelped,
);
}
Map<String, dynamic> toJson() => {
'themeMode': themeMode,
'environment': environment,
'userLoggedIn': userLoggedIn,
'locale': locale,
'showSplashScreen': showSplashScreen,
'telemetryDialogDismissed': telemetryDialogDismissed,
'successfulConnection': successfulConnection,
'dataCapThreshold': dataCapThreshold,
'onboardingCompleted': onboardingCompleted,
'unboundedAutoEnable': unboundedAutoEnable,
'unboundedHidden': unboundedHidden,
'unboundedWelcomeSeen': unboundedWelcomeSeen,
'unboundedTotalHelped': unboundedTotalHelped,
};
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,
// Default to true when missing (first-time post-upgrade users
// should get the auto-enable behaviour the spec calls for).
unboundedAutoEnable: json['unboundedAutoEnable'] != false,
unboundedHidden: json['unboundedHidden'] == true,
unboundedWelcomeSeen: json['unboundedWelcomeSeen'] == true,
unboundedTotalHelped:
(json['unboundedTotalHelped'] as num?)?.toInt() ?? 0,
);
}