pikapika/lib/basic/config/ImageAddress.dart

65 lines
1.5 KiB
Dart
Raw Normal View History

2021-11-30 02:23:49 +00:00
import 'package:flutter/material.dart';
import '../Method.dart';
var _imageAddresses = {
2023-01-21 09:53:22 +00:00
"-3": "CDN-3",
"-2": "CDN-2",
"-1": "CDN-1",
2021-11-30 02:23:49 +00:00
"0": "不分流",
2023-01-21 09:53:22 +00:00
"1": "分流1",
2021-11-30 02:23:49 +00:00
"2": "分流2",
};
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(
child: Text(e.value),
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(() {});
},
);
},
);
}