2021-11-30 02:23:49 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-03-23 09:44:42 +00:00
|
|
|
import 'package:path/path.dart';
|
2021-11-30 02:23:49 +00:00
|
|
|
|
|
|
|
import '../Method.dart';
|
2023-03-23 09:44:42 +00:00
|
|
|
import 'Address.dart';
|
2021-11-30 02:23:49 +00:00
|
|
|
|
|
|
|
var _imageAddresses = {
|
|
|
|
"0": "不分流",
|
2023-03-23 09:44:42 +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",
|
2021-11-30 02:23:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
late String _currentImageAddress;
|
|
|
|
|
|
|
|
Future<void> initImageAddress() async {
|
|
|
|
_currentImageAddress = await method.getImageSwitchAddress();
|
|
|
|
}
|
|
|
|
|
2021-11-30 11:34:26 +00:00
|
|
|
int currentImageAddress() {
|
|
|
|
return int.parse(_currentImageAddress);
|
|
|
|
}
|
|
|
|
|
2021-12-09 00:08:01 +00:00
|
|
|
String currentImageAddressName() => _imageAddresses[_currentImageAddress] ?? "";
|
2021-11-30 02:23:49 +00:00
|
|
|
|
2021-12-04 01:06:52 +00:00
|
|
|
Future<void> chooseImageAddress(BuildContext context) async {
|
2021-11-30 02:23:49 +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-11-30 02:23:49 +00:00
|
|
|
children: <Widget>[
|
|
|
|
..._imageAddresses.entries.map(
|
|
|
|
(e) => SimpleDialogOption(
|
2023-03-23 09:44:42 +00:00
|
|
|
child: ApiOptionRowImg(
|
|
|
|
e.value,
|
|
|
|
e.key,
|
|
|
|
key: Key("API:${e.key}"),
|
|
|
|
),
|
2021-11-30 02:23:49 +00:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop(e.key);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
if (choose != null) {
|
|
|
|
await method.setImageSwitchAddress(choose);
|
|
|
|
_currentImageAddress = choose;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget imageSwitchAddressSetting() {
|
|
|
|
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(currentImageAddressName()),
|
2021-11-30 02:23:49 +00:00
|
|
|
onTap: () async {
|
2021-12-04 01:06:52 +00:00
|
|
|
await chooseImageAddress(context);
|
2021-11-30 02:23:49 +00:00
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2023-03-23 09:44:42 +00:00
|
|
|
|
|
|
|
class ApiOptionRowImg extends StatefulWidget {
|
|
|
|
final String title;
|
|
|
|
final String value;
|
|
|
|
|
|
|
|
const ApiOptionRowImg(this.title, this.value, {Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _ApiOptionRowImgState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ApiOptionRowImgState extends State<ApiOptionRowImg> {
|
|
|
|
late Future<int> _feature;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
if ("0" != widget.value) {
|
|
|
|
_feature = method.pingImg(widget.value);
|
|
|
|
}else{
|
|
|
|
_feature = method.ping(currentAddress());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
Text(widget.title),
|
|
|
|
Expanded(child: Container()),
|
|
|
|
FutureBuilder(
|
|
|
|
future: _feature,
|
|
|
|
builder: (
|
|
|
|
BuildContext context,
|
|
|
|
AsyncSnapshot<int> snapshot,
|
|
|
|
) {
|
|
|
|
if (snapshot.connectionState != ConnectionState.done) {
|
|
|
|
return const PingStatus(
|
|
|
|
"测速中",
|
|
|
|
Colors.blue,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
return const PingStatus(
|
|
|
|
"失败",
|
|
|
|
Colors.red,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
int ping = snapshot.requireData;
|
|
|
|
if (ping <= 200) {
|
|
|
|
return PingStatus(
|
|
|
|
"${ping}ms",
|
|
|
|
Colors.green,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (ping <= 500) {
|
|
|
|
return PingStatus(
|
|
|
|
"${ping}ms",
|
|
|
|
Colors.yellow,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return PingStatus(
|
|
|
|
"${ping}ms",
|
|
|
|
Colors.orange,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|