2021-09-29 23:57:09 +00:00
|
|
|
/// 分流地址
|
|
|
|
|
|
|
|
// addr = "172.67.7.24:443"
|
|
|
|
// addr = "104.20.180.50:443"
|
|
|
|
// addr = "172.67.208.169:443"
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2022-07-12 07:28:47 +00:00
|
|
|
import 'package:pikapika/basic/Common.dart';
|
2021-09-29 23:57:09 +00:00
|
|
|
|
|
|
|
import '../Method.dart';
|
|
|
|
|
|
|
|
var _addresses = {
|
2021-11-30 02:23:49 +00:00
|
|
|
"0": "不分流",
|
2023-01-21 16:38:09 +00:00
|
|
|
"1": "分流1",
|
2021-11-30 02:23:49 +00:00
|
|
|
"2": "分流2",
|
2023-01-21 16:38:09 +00:00
|
|
|
"3": "分流3 (推荐)",
|
|
|
|
"4": "分流4",
|
|
|
|
"5": "分流5",
|
|
|
|
"6": "分流6",
|
|
|
|
"7": "分流7",
|
|
|
|
"8": "分流8",
|
2021-09-29 23:57:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
late String _currentAddress;
|
|
|
|
|
|
|
|
Future<void> initAddress() async {
|
|
|
|
_currentAddress = await method.getSwitchAddress();
|
|
|
|
}
|
|
|
|
|
2021-12-09 00:08:01 +00:00
|
|
|
String currentAddressName() => _addresses[_currentAddress] ?? "";
|
2021-09-29 23:57:09 +00:00
|
|
|
|
2021-12-04 01:06:52 +00:00
|
|
|
Future<void> chooseAddress(BuildContext context) async {
|
2021-09-29 23:57:09 +00:00
|
|
|
String? choose = await showDialog<String>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return SimpleDialog(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text('选择分流'),
|
2021-09-29 23:57:09 +00:00
|
|
|
children: <Widget>[
|
|
|
|
..._addresses.entries.map(
|
|
|
|
(e) => SimpleDialogOption(
|
2021-11-30 02:23:49 +00:00
|
|
|
child: Text(e.value),
|
2021-09-29 23:57:09 +00:00
|
|
|
onPressed: () {
|
2021-11-30 02:23:49 +00:00
|
|
|
Navigator.of(context).pop(e.key);
|
2021-09-29 23:57:09 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
if (choose != null) {
|
|
|
|
await method.setSwitchAddress(choose);
|
|
|
|
_currentAddress = choose;
|
|
|
|
}
|
|
|
|
}
|
2021-11-30 02:23:49 +00:00
|
|
|
|
|
|
|
Widget switchAddressSetting() {
|
|
|
|
return StatefulBuilder(
|
|
|
|
builder: (BuildContext context, void Function(void Function()) setState) {
|
|
|
|
return ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("分流"),
|
2021-12-04 01:06:52 +00:00
|
|
|
subtitle: Text(currentAddressName()),
|
2021-11-30 02:23:49 +00:00
|
|
|
onTap: () async {
|
2021-12-04 01:06:52 +00:00
|
|
|
await chooseAddress(context);
|
2021-11-30 02:23:49 +00:00
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2022-07-12 07:28:47 +00:00
|
|
|
|
|
|
|
Widget reloadSwitchAddressSetting() {
|
|
|
|
return StatefulBuilder(
|
|
|
|
builder: (BuildContext context, void Function(void Function()) setState) {
|
|
|
|
return ListTile(
|
|
|
|
title: const Text("==== 分流 ===="),
|
|
|
|
onTap: () async {
|
|
|
|
String? choose = await chooseListDialog(context, "==== 分流 ====", [
|
|
|
|
"从服务器获取最新的分流地址",
|
|
|
|
"重制分流为默认值",
|
|
|
|
]);
|
|
|
|
if (choose != null) {
|
|
|
|
if (choose == "从服务器获取最新的分流地址") {
|
|
|
|
try {
|
|
|
|
await method.reloadSwitchAddress();
|
|
|
|
defaultToast(context, "分流2/3已同步");
|
|
|
|
} catch (e, s) {
|
|
|
|
print("$e\$s");
|
|
|
|
defaultToast(context, "分流同步失败");
|
|
|
|
}
|
|
|
|
} else if (choose == "重制分流为默认值") {
|
|
|
|
try {
|
|
|
|
await method.resetSwitchAddress();
|
|
|
|
defaultToast(context, "分流2/3已重制为默认值");
|
|
|
|
} catch (e, s) {
|
|
|
|
print("$e\$s");
|
|
|
|
defaultToast(context, "分流重制失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|