pikapika/lib/basic/config/Quality.dart

83 lines
1.9 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
/// 图片质量
import 'package:flutter/material.dart';
import '../Method.dart';
2021-10-21 04:08:51 +00:00
const _ImageQualityOriginal = "original";
const _ImageQualityLow = "low";
const _ImageQualityMedium = "medium";
const _ImageQualityHigh = "high";
2021-09-29 23:57:09 +00:00
2021-10-21 04:08:51 +00:00
const _LabelOriginal = "原图";
const _LabelLow = "";
const _LabelMedium = "";
const _LabelHigh = "";
2021-09-29 23:57:09 +00:00
var _qualities = {
2021-10-21 04:08:51 +00:00
_LabelOriginal: _ImageQualityOriginal,
_LabelLow: _ImageQualityLow,
_LabelMedium: _ImageQualityMedium,
_LabelHigh: _ImageQualityHigh,
2021-09-29 23:57:09 +00:00
};
2021-11-04 05:56:25 +00:00
const _propertyName = "quality";
2021-10-21 04:08:51 +00:00
late String _currentQualityCode;
2021-11-04 05:56:25 +00:00
const _defaultValue = _ImageQualityOriginal;
Future<void> initQuality() async {
_currentQualityCode = await method.loadProperty(_propertyName, _defaultValue);
}
2021-10-21 04:08:51 +00:00
String currentQualityCode() {
return _currentQualityCode;
}
2021-12-03 10:08:12 +00:00
String currentQualityName() {
2021-10-21 04:08:51 +00:00
for (var e in _qualities.entries) {
if (e.value == _currentQualityCode) {
return e.key;
}
}
return '';
}
2021-12-03 10:08:12 +00:00
Future<void> chooseQuality(BuildContext context) async {
2021-09-29 23:57:09 +00:00
String? code = 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>[
..._qualities.entries.map(
(e) => SimpleDialogOption(
child: Text(e.key),
onPressed: () {
Navigator.of(context).pop(e.value);
},
),
),
],
);
},
);
if (code != null) {
2021-10-21 04:08:51 +00:00
method.saveProperty(_propertyName, code);
_currentQualityCode = code;
2021-09-29 23:57:09 +00:00
}
}
2021-10-21 04:08:51 +00:00
Widget qualitySetting() {
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-03 10:08:12 +00:00
subtitle: Text(currentQualityName()),
2021-10-21 04:08:51 +00:00
onTap: () async {
2021-12-03 10:08:12 +00:00
await chooseQuality(context);
2021-10-21 04:08:51 +00:00
setState(() {});
},
);
},
);
2021-09-29 23:57:09 +00:00
}