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";
|
2021-09-29 23:57:09 +00:00
|
|
|
const ImageQualityHigh = "high";
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
String _currentQualityName() {
|
|
|
|
for (var e in _qualities.entries) {
|
|
|
|
if (e.value == _currentQualityCode) {
|
|
|
|
return e.key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2021-11-04 05:56:25 +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(
|
|
|
|
title: Text("请选择图片质量"),
|
|
|
|
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(
|
|
|
|
title: Text("浏览时的图片质量"),
|
|
|
|
subtitle: Text(_currentQualityName()),
|
|
|
|
onTap: () async {
|
2021-11-04 05:56:25 +00:00
|
|
|
await _chooseQuality(context);
|
2021-10-21 04:08:51 +00:00
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2021-09-29 23:57:09 +00:00
|
|
|
}
|