Skip to content

Commit 11ee7f2

Browse files
committed
fix: remove reinitialization of SettingsModel
1 parent f27817d commit 11ee7f2

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

lib/models/settings_model.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SettingsModel {
1717
this.historyRetentionPeriod = HistoryRetentionPeriod.oneWeek,
1818
this.workspaceFolderPath,
1919
this.isSSLDisabled = false,
20-
this.isProxyEnabled = false,
20+
this.proxySettings = const ProxySettings(),
2121
});
2222

2323
final bool isDark;
@@ -34,7 +34,7 @@ class SettingsModel {
3434
final bool isSSLDisabled;
3535

3636
// Proxy settings
37-
final bool isProxyEnabled;
37+
final ProxySettings proxySettings;
3838

3939
SettingsModel copyWith({
4040
bool? isDark,
@@ -49,7 +49,7 @@ class SettingsModel {
4949
HistoryRetentionPeriod? historyRetentionPeriod,
5050
String? workspaceFolderPath,
5151
bool? isSSLDisabled,
52-
bool? isProxyEnabled,
52+
ProxySettings? proxySettings,
5353
}) {
5454
return SettingsModel(
5555
isDark: isDark ?? this.isDark,
@@ -66,7 +66,7 @@ class SettingsModel {
6666
historyRetentionPeriod ?? this.historyRetentionPeriod,
6767
workspaceFolderPath: workspaceFolderPath ?? this.workspaceFolderPath,
6868
isSSLDisabled: isSSLDisabled ?? this.isSSLDisabled,
69-
isProxyEnabled: isProxyEnabled ?? this.isProxyEnabled,
69+
proxySettings: proxySettings ?? this.proxySettings,
7070
);
7171
}
7272

@@ -86,7 +86,7 @@ class SettingsModel {
8686
historyRetentionPeriod: historyRetentionPeriod,
8787
workspaceFolderPath: workspaceFolderPath,
8888
isSSLDisabled: isSSLDisabled,
89-
isProxyEnabled: isProxyEnabled,
89+
proxySettings: proxySettings,
9090
);
9191
}
9292

@@ -141,7 +141,6 @@ class SettingsModel {
141141
}
142142
final workspaceFolderPath = data["workspaceFolderPath"] as String?;
143143
final isSSLDisabled = data["isSSLDisabled"] as bool?;
144-
final isProxyEnabled = data["isProxyEnabled"] as bool?;
145144

146145
const sm = SettingsModel();
147146

@@ -159,7 +158,7 @@ class SettingsModel {
159158
historyRetentionPeriod ?? HistoryRetentionPeriod.oneWeek,
160159
workspaceFolderPath: workspaceFolderPath,
161160
isSSLDisabled: isSSLDisabled,
162-
isProxyEnabled: isProxyEnabled,
161+
proxySettings: ProxySettings.fromJson(data["proxySettings"]),
163162
);
164163
}
165164

@@ -179,7 +178,7 @@ class SettingsModel {
179178
"historyRetentionPeriod": historyRetentionPeriod.name,
180179
"workspaceFolderPath": workspaceFolderPath,
181180
"isSSLDisabled": isSSLDisabled,
182-
"isProxyEnabled": isProxyEnabled,
181+
"proxySettings": proxySettings,
183182
};
184183
}
185184

@@ -205,7 +204,7 @@ class SettingsModel {
205204
other.historyRetentionPeriod == historyRetentionPeriod &&
206205
other.workspaceFolderPath == workspaceFolderPath &&
207206
other.isSSLDisabled == isSSLDisabled &&
208-
other.isProxyEnabled == isProxyEnabled;
207+
other.proxySettings == proxySettings;
209208
}
210209

211210
@override
@@ -224,7 +223,7 @@ class SettingsModel {
224223
historyRetentionPeriod,
225224
workspaceFolderPath,
226225
isSSLDisabled,
227-
isProxyEnabled,
226+
proxySettings,
228227
);
229228
}
230229
}

lib/providers/collection_providers.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,7 @@ class CollectionStateNotifier
295295
substitutedHttpRequestModel,
296296
defaultUriScheme: defaultUriScheme,
297297
noSSL: noSSL,
298-
isProxyEnabled: ref.read(settingsProvider).isProxyEnabled,
299-
proxyHost: ref.read(settingsProvider).proxyHost,
300-
proxyPort: ref.read(settingsProvider).proxyPort,
301-
proxyUsername: ref.read(settingsProvider).proxyUsername,
302-
proxyPassword: ref.read(settingsProvider).proxyPassword,
298+
proxySettings: ref.read(settingsProvider).proxySettings,
303299
);
304300

305301
late final RequestModel newRequestModel;

lib/providers/settings_providers.dart

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,9 @@ class ThemeStateNotifier extends StateNotifier<SettingsModel> {
3333
HistoryRetentionPeriod? historyRetentionPeriod,
3434
String? workspaceFolderPath,
3535
bool? isSSLDisabled,
36-
bool? isProxyEnabled,
37-
String? proxyHost,
38-
String? proxyPort,
39-
String? proxyUsername,
40-
String? proxyPassword,
41-
bool? useSystemProxy,
42-
String? proxyBypassRules,
36+
ProxySettings? proxySettings,
4337
}) async {
44-
state = SettingsModel(
38+
state = state.copyWith(
4539
isDark: isDark ?? state.isDark,
4640
alwaysShowCollectionPaneScrollbar: alwaysShowCollectionPaneScrollbar ?? state.alwaysShowCollectionPaneScrollbar,
4741
size: size ?? state.size,
@@ -54,11 +48,7 @@ class ThemeStateNotifier extends StateNotifier<SettingsModel> {
5448
historyRetentionPeriod: historyRetentionPeriod ?? state.historyRetentionPeriod,
5549
workspaceFolderPath: workspaceFolderPath ?? state.workspaceFolderPath,
5650
isSSLDisabled: isSSLDisabled ?? state.isSSLDisabled,
57-
isProxyEnabled: isProxyEnabled ?? state.isProxyEnabled,
58-
proxyHost: proxyHost ?? state.proxyHost,
59-
proxyPort: proxyPort ?? state.proxyPort,
60-
proxyUsername: proxyUsername ?? state.proxyUsername,
61-
proxyPassword: proxyPassword ?? state.proxyPassword,
51+
proxySettings: proxySettings ?? state.proxySettings,
6252
);
6353
await setSettingsToSharedPrefs(state);
6454
}

0 commit comments

Comments
 (0)