pikapika/lib/basic/config/VolumeController.dart

43 lines
1.1 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';
2021-11-04 05:56:25 +00:00
const _propertyName = "volumeController";
2021-09-29 23:57:09 +00:00
late bool volumeController;
Future<void> initVolumeController() async {
2021-10-13 13:57:35 +00:00
volumeController =
2021-11-04 05:56:25 +00:00
(await method.loadProperty(_propertyName, "false")) == "true";
2021-09-29 23:57:09 +00:00
}
2021-11-04 05:56:25 +00:00
Future<void> _chooseVolumeController(BuildContext context) async {
2021-09-29 23:57:09 +00:00
String? result =
await chooseListDialog<String>(context, "音量键控制翻页", ["", ""]);
if (result != null) {
var target = result == "";
2021-11-04 05:56:25 +00:00
await method.saveProperty(_propertyName, "$target");
2021-09-29 23:57:09 +00:00
volumeController = target;
}
}
2021-10-13 13:57:35 +00:00
Widget volumeControllerSetting() {
if (Platform.isAndroid) {
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(volumeController ? "" : ""),
2021-10-13 13:57:35 +00:00
onTap: () async {
2021-11-04 05:56:25 +00:00
await _chooseVolumeController(context);
2021-10-13 13:57:35 +00:00
setState(() {});
});
});
}
return Container();
}