pikapika/lib/basic/config/PagerAction.dart

71 lines
1.6 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
/// 列表页下一页的行为
import 'package:flutter/material.dart';
import '../Common.dart';
import '../Method.dart';
enum PagerAction {
CONTROLLER,
STREAM,
}
2021-11-04 05:56:25 +00:00
Map<String, PagerAction> _pagerActionMap = {
"使用按钮": PagerAction.CONTROLLER,
"瀑布流": PagerAction.STREAM,
};
2021-09-29 23:57:09 +00:00
const _propertyName = "pagerAction";
2021-11-04 05:56:25 +00:00
late PagerAction _pagerAction;
2021-09-29 23:57:09 +00:00
Future<void> initPagerAction() async {
2021-11-04 05:56:25 +00:00
_pagerAction = _pagerActionFromString(await method.loadProperty(
2021-09-29 23:57:09 +00:00
_propertyName, PagerAction.CONTROLLER.toString()));
}
2021-11-04 05:56:25 +00:00
PagerAction currentPagerAction() {
return _pagerAction;
}
2021-09-29 23:57:09 +00:00
PagerAction _pagerActionFromString(String string) {
for (var value in PagerAction.values) {
if (string == value.toString()) {
return value;
}
}
return PagerAction.CONTROLLER;
}
2021-11-04 05:56:25 +00:00
String _currentPagerActionName() {
2021-09-29 23:57:09 +00:00
for (var e in _pagerActionMap.entries) {
2021-11-04 05:56:25 +00:00
if (e.value == _pagerAction) {
2021-09-29 23:57:09 +00:00
return e.key;
}
}
return '';
}
2021-11-04 05:56:25 +00:00
Future<void> _choosePagerAction(BuildContext context) async {
2021-09-29 23:57:09 +00:00
PagerAction? result =
await chooseMapDialog<PagerAction>(context, _pagerActionMap, "选择列表页加载方式");
if (result != null) {
await method.saveProperty(_propertyName, result.toString());
2021-11-04 05:56:25 +00:00
_pagerAction = result;
2021-09-29 23:57:09 +00:00
}
}
2021-11-04 03:45:22 +00:00
Widget pagerActionSetting() {
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(_currentPagerActionName()),
2021-11-04 03:45:22 +00:00
onTap: () async {
2021-11-04 05:56:25 +00:00
await _choosePagerAction(context);
2021-11-04 03:45:22 +00:00
setState(() {});
},
);
},
);
}