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';
|
|
|
|
|
|
|
|
import '../Method.dart';
|
|
|
|
|
|
|
|
var _addresses = {
|
2021-11-30 02:23:49 +00:00
|
|
|
"0": "不分流",
|
|
|
|
"1": "分流1 (推荐)",
|
|
|
|
"2": "分流2",
|
|
|
|
"3": "分流3",
|
2021-09-29 23:57:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
late String _currentAddress;
|
|
|
|
|
|
|
|
Future<void> initAddress() async {
|
|
|
|
_currentAddress = await method.getSwitchAddress();
|
|
|
|
}
|
|
|
|
|
2021-11-30 02:23:49 +00:00
|
|
|
String _currentAddressName() {
|
|
|
|
return _addresses[_currentAddress] ?? "";
|
2021-09-29 23:57:09 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 02:23:49 +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(
|
|
|
|
title: Text('选择分流'),
|
|
|
|
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(
|
|
|
|
title: Text("分流"),
|
|
|
|
subtitle: Text(_currentAddressName()),
|
|
|
|
onTap: () async {
|
|
|
|
await _chooseAddress(context);
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|