pikapika/lib/basic/config/KeyboardController.dart

50 lines
1.3 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
/// 上下键翻页
2021-10-13 13:57:35 +00:00
import 'dart:io';
2021-09-29 23:57:09 +00:00
import 'package:flutter/material.dart';
import '../Common.dart';
import '../Method.dart';
const _propertyName = "keyboardController";
2021-09-29 23:57:09 +00:00
late bool keyboardController;
Future<void> initKeyboardController() async {
keyboardController =
(await method.loadProperty(_propertyName, "false")) == "true";
2021-09-29 23:57:09 +00:00
}
String keyboardControllerName() {
return keyboardController ? "" : "";
}
Future<void> chooseKeyboardController(BuildContext context) async {
String? result =
await chooseListDialog<String>(context, "键盘控制翻页", ["", ""]);
if (result != null) {
var target = result == "";
await method.saveProperty(_propertyName, "$target");
2021-09-29 23:57:09 +00:00
keyboardController = target;
}
}
2021-10-13 13:57:35 +00:00
Widget keyboardControllerSetting() {
if (Platform.isWindows || Platform.isMacOS || Platform.isLinux) {
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setState) {
return ListTile(
title: Text("阅读器键盘翻页(仅PC)"),
subtitle: Text(keyboardControllerName()),
onTap: () async {
await chooseKeyboardController(context);
setState(() {});
},
);
},
);
}
return Container();
}