mod: 代理设置

This commit is contained in:
guozhigq
2023-11-06 00:04:54 +08:00
parent 1c370fb224
commit 13ce50f730
4 changed files with 180 additions and 0 deletions

View File

@ -16,8 +16,12 @@ class ExtraSetting extends StatefulWidget {
class _ExtraSettingState extends State<ExtraSetting> {
Box setting = GStrorage.setting;
static Box localCache = GStrorage.localCache;
late dynamic defaultReplySort;
late dynamic defaultDynamicType;
late dynamic enableSystemProxy;
late String defaultSystemProxyHost;
late String defaultSystemProxyPort;
@override
void initState() {
@ -28,6 +32,86 @@ class _ExtraSettingState extends State<ExtraSetting> {
// 优先展示全部动态 all
defaultDynamicType =
setting.get(SettingBoxKey.defaultDynamicType, defaultValue: 0);
enableSystemProxy =
setting.get(SettingBoxKey.enableSystemProxy, defaultValue: false);
defaultSystemProxyHost =
localCache.get(LocalCacheKey.systemProxyHost, defaultValue: '');
defaultSystemProxyPort =
localCache.get(LocalCacheKey.systemProxyPort, defaultValue: '');
}
// 设置代理
void twoFADialog() {
var systemProxyHost = '';
var systemProxyPort = '';
SmartDialog.show(
useSystem: true,
animationType: SmartAnimationType.centerFade_otherSlide,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('设置代理'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 6),
TextField(
decoration: InputDecoration(
isDense: true,
labelText: defaultSystemProxyHost != ''
? defaultSystemProxyHost
: '请输入Host使用 . 分割',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
),
hintText: defaultSystemProxyHost,
),
onChanged: (e) {
systemProxyHost = e;
},
),
const SizedBox(height: 10),
TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
isDense: true,
labelText: defaultSystemProxyPort != ''
? defaultSystemProxyPort
: '请输入Port',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
),
hintText: defaultSystemProxyPort,
),
onChanged: (e) {
systemProxyPort = e;
},
),
],
),
actions: [
TextButton(
onPressed: () async {
SmartDialog.dismiss();
},
child: Text(
'取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
),
),
TextButton(
onPressed: () async {
localCache.put(LocalCacheKey.systemProxyHost, systemProxyHost);
localCache.put(LocalCacheKey.systemProxyPort, systemProxyPort);
SmartDialog.dismiss();
// Request.dio;
},
child: const Text('确认'),
)
],
);
},
);
}
@override
@ -135,6 +219,33 @@ class _ExtraSettingState extends State<ExtraSetting> {
],
),
),
ListTile(
enableFeedback: true,
onTap: () => twoFADialog(),
title: Text('设置代理', style: titleStyle),
subtitle: Text('设置代理 host:port', style: subTitleStyle),
trailing: Transform.scale(
scale: 0.8,
child: Switch(
thumbIcon: MaterialStateProperty.resolveWith<Icon?>(
(Set<MaterialState> states) {
if (states.isNotEmpty &&
states.first == MaterialState.selected) {
return const Icon(Icons.done);
}
return null; // All other states will use the default thumbIcon.
}),
value: enableSystemProxy,
onChanged: (val) {
setting.put(
SettingBoxKey.enableSystemProxy, !enableSystemProxy);
setState(() {
enableSystemProxy = !enableSystemProxy;
});
},
),
),
),
const SetSwitchItem(
title: '检查更新',
subTitle: '每次启动时检查是否需要更新',