2021-09-29 23:57:09 +00:00
|
|
|
/// 阅读器的方向
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pikapi/basic/Method.dart';
|
|
|
|
|
|
|
|
enum ReaderDirection {
|
|
|
|
TOP_TO_BOTTOM,
|
|
|
|
LEFT_TO_RIGHT,
|
|
|
|
RIGHT_TO_LEFT,
|
|
|
|
}
|
|
|
|
|
2021-11-04 05:56:25 +00:00
|
|
|
const _types = {
|
|
|
|
'从上到下': ReaderDirection.TOP_TO_BOTTOM,
|
|
|
|
'从左到右': ReaderDirection.LEFT_TO_RIGHT,
|
|
|
|
'从右到左': ReaderDirection.RIGHT_TO_LEFT,
|
|
|
|
};
|
2021-09-29 23:57:09 +00:00
|
|
|
|
|
|
|
const _propertyName = "readerDirection";
|
2021-11-04 05:56:25 +00:00
|
|
|
late ReaderDirection gReaderDirection;
|
2021-09-29 23:57:09 +00:00
|
|
|
|
|
|
|
Future<void> initReaderDirection() async {
|
|
|
|
gReaderDirection = _pagerDirectionFromString(await method.loadProperty(
|
|
|
|
_propertyName, ReaderDirection.TOP_TO_BOTTOM.toString()));
|
|
|
|
}
|
|
|
|
|
|
|
|
ReaderDirection _pagerDirectionFromString(String pagerDirectionString) {
|
|
|
|
for (var value in ReaderDirection.values) {
|
|
|
|
if (pagerDirectionString == value.toString()) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ReaderDirection.TOP_TO_BOTTOM;
|
|
|
|
}
|
|
|
|
|
2021-11-04 05:56:25 +00:00
|
|
|
String _currentReaderDirectionName() {
|
2021-09-29 23:57:09 +00:00
|
|
|
for (var e in _types.entries) {
|
|
|
|
if (e.value == gReaderDirection) {
|
|
|
|
return e.key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2021-11-04 05:56:25 +00:00
|
|
|
/// ?? to ActionButton And Event ??
|
2021-09-29 23:57:09 +00:00
|
|
|
Future<void> choosePagerDirection(BuildContext buildContext) async {
|
|
|
|
ReaderDirection? choose = await showDialog<ReaderDirection>(
|
|
|
|
context: buildContext,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return SimpleDialog(
|
|
|
|
title: Text("选择翻页方向"),
|
|
|
|
children: _types.entries
|
|
|
|
.map((e) => SimpleDialogOption(
|
|
|
|
child: Text(e.key),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop(e.value);
|
|
|
|
},
|
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
if (choose != null) {
|
|
|
|
await method.saveProperty(_propertyName, choose.toString());
|
|
|
|
gReaderDirection = choose;
|
|
|
|
}
|
|
|
|
}
|
2021-11-04 03:45:22 +00:00
|
|
|
|
|
|
|
Widget readerDirectionSetting() {
|
|
|
|
return StatefulBuilder(
|
|
|
|
builder: (BuildContext context, void Function(void Function()) setState) {
|
|
|
|
return ListTile(
|
|
|
|
title: Text("阅读器方向"),
|
2021-11-04 05:56:25 +00:00
|
|
|
subtitle: Text(_currentReaderDirectionName()),
|
2021-11-04 03:45:22 +00:00
|
|
|
onTap: () async {
|
|
|
|
await choosePagerDirection(context);
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|