Skip to content

Commit 976fa5a

Browse files
committed
chore: create proxy settings
1 parent c145482 commit 976fa5a

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

lib/models/settings_model.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class SettingsModel {
1717
this.historyRetentionPeriod = HistoryRetentionPeriod.oneWeek,
1818
this.workspaceFolderPath,
1919
this.isSSLDisabled = false,
20+
this.isProxyEnabled = false,
21+
this.proxyHost = '',
22+
this.proxyPort = '',
23+
this.proxyUsername,
24+
this.proxyPassword,
2025
});
2126

2227
final bool isDark;
@@ -32,6 +37,13 @@ class SettingsModel {
3237
final String? workspaceFolderPath;
3338
final bool isSSLDisabled;
3439

40+
// Proxy settings
41+
final bool isProxyEnabled;
42+
final String proxyHost;
43+
final String proxyPort;
44+
final String? proxyUsername;
45+
final String? proxyPassword;
46+
3547
SettingsModel copyWith({
3648
bool? isDark,
3749
bool? alwaysShowCollectionPaneScrollbar,
@@ -45,6 +57,12 @@ class SettingsModel {
4557
HistoryRetentionPeriod? historyRetentionPeriod,
4658
String? workspaceFolderPath,
4759
bool? isSSLDisabled,
60+
// Proxy settings
61+
bool? isProxyEnabled,
62+
String? proxyHost,
63+
String? proxyPort,
64+
String? proxyUsername,
65+
String? proxyPassword,
4866
}) {
4967
return SettingsModel(
5068
isDark: isDark ?? this.isDark,

lib/providers/proxy_provider.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import 'package:flutter_riverpod/flutter_riverpod.dart';
2+
import '../models/proxy_config.dart';
3+
4+
final proxyConfigProvider = StateNotifierProvider<ProxyNotifier, ProxyConfig>((ref) {
5+
return ProxyNotifier();
6+
});
7+
8+
class ProxyNotifier extends StateNotifier<ProxyConfig> {
9+
ProxyNotifier() : super(ProxyConfig()) {
10+
_loadConfig();
11+
}
12+
13+
Future<void> _loadConfig() async {
14+
state = await ProxyConfig.load();
15+
}
16+
17+
Future<void> updateConfig({
18+
bool? isEnabled,
19+
String? host,
20+
String? port,
21+
String? username,
22+
String? password,
23+
}) async {
24+
state = ProxyConfig(
25+
isEnabled: isEnabled ?? state.isEnabled,
26+
host: host ?? state.host,
27+
port: port ?? state.port,
28+
username: username ?? state.username,
29+
password: password ?? state.password,
30+
);
31+
await ProxyConfig.save(state);
32+
}
33+
34+
String? getProxyUrl() {
35+
if (!state.isEnabled || state.host.isEmpty || state.port.isEmpty) {
36+
return null;
37+
}
38+
final auth = (state.username?.isNotEmpty ?? false) && (state.password?.isNotEmpty ?? false)
39+
? '${state.username}:${state.password}@'
40+
: '';
41+
return 'http://$auth${state.host}:${state.port}';
42+
}
43+
44+
// Debug method to print proxy configuration
45+
void printProxyConfig() {
46+
print('Proxy Configuration:');
47+
print('Enabled: ${state.isEnabled}');
48+
print('Host: ${state.host}');
49+
print('Port: ${state.port}');
50+
print('Username: ${state.username != null ? '***' : null}');
51+
print('Password: ${state.password != null ? '***' : null}');
52+
print('Proxy URL: ${getProxyUrl() ?? 'Not configured'}');
53+
}
54+
}

lib/providers/settings_providers.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ 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,
3641
}) async {
3742
state = state.copyWith(
3843
isDark: isDark,
@@ -47,6 +52,11 @@ class ThemeStateNotifier extends StateNotifier<SettingsModel> {
4752
historyRetentionPeriod: historyRetentionPeriod,
4853
workspaceFolderPath: workspaceFolderPath,
4954
isSSLDisabled: isSSLDisabled,
55+
isProxyEnabled: isProxyEnabled,
56+
proxyHost: proxyHost,
57+
proxyPort: proxyPort,
58+
proxyUsername: proxyUsername,
59+
proxyPassword: proxyPassword,
5060
);
5161
await setSettingsToSharedPrefs(state);
5262
}

lib/screens/settings_page.dart

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,65 @@ class SettingsPage extends ConsumerWidget {
5050
ref.read(settingsProvider.notifier).update(isDark: value);
5151
},
5252
),
53+
// Proxy Settings Section
54+
SwitchListTile(
55+
hoverColor: kColorTransparent,
56+
title: const Text('Enable Proxy'),
57+
subtitle: const Text('Configure HTTP proxy settings'),
58+
value: settings.isProxyEnabled,
59+
onChanged: (bool? value) {
60+
ref.read(settingsProvider.notifier).update(isProxyEnabled: value);
61+
},
62+
),
63+
if (settings.isProxyEnabled) ...[
64+
ListTile(
65+
title: TextField(
66+
decoration: const InputDecoration(
67+
labelText: 'Proxy Host',
68+
hintText: 'e.g., localhost',
69+
),
70+
controller: TextEditingController(text: settings.proxyHost),
71+
onChanged: (value) {
72+
ref.read(settingsProvider.notifier).update(proxyHost: value);
73+
},
74+
),
75+
),
76+
ListTile(
77+
title: TextField(
78+
decoration: const InputDecoration(
79+
labelText: 'Proxy Port',
80+
hintText: 'e.g., 8080',
81+
),
82+
controller: TextEditingController(text: settings.proxyPort),
83+
onChanged: (value) {
84+
ref.read(settingsProvider.notifier).update(proxyPort: value);
85+
},
86+
),
87+
),
88+
ListTile(
89+
title: TextField(
90+
decoration: const InputDecoration(
91+
labelText: 'Username (Optional)',
92+
),
93+
controller: TextEditingController(text: settings.proxyUsername),
94+
onChanged: (value) {
95+
ref.read(settingsProvider.notifier).update(proxyUsername: value);
96+
},
97+
),
98+
),
99+
ListTile(
100+
title: TextField(
101+
decoration: const InputDecoration(
102+
labelText: 'Password (Optional)',
103+
),
104+
obscureText: true,
105+
controller: TextEditingController(text: settings.proxyPassword),
106+
onChanged: (value) {
107+
ref.read(settingsProvider.notifier).update(proxyPassword: value);
108+
},
109+
),
110+
),
111+
],
53112
SwitchListTile(
54113
hoverColor: kColorTransparent,
55114
title: const Text('Collection Pane Scrollbar Visiblity'),

0 commit comments

Comments
 (0)