pikapika/lib/basic/config/ReaderDirection.dart

84 lines
2.2 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
/// 阅读器的方向
import 'package:flutter/material.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/Method.dart';
2021-09-29 23:57:09 +00:00
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-12-03 10:08:12 +00:00
var gReaderDirectionName = _currentReaderDirectionName;
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(
2022-03-19 04:12:27 +00:00
title: const Text("选择翻页方向"),
2021-09-29 23:57:09 +00:00
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(
2022-03-19 04:12:27 +00:00
title: const 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(() {});
},
);
},
);
}