pikapika/lib/basic/config/ContentFailedReloadAction.dart

71 lines
1.9 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 ContentFailedReloadAction {
PULL_DOWN,
TOUCH_LOADER,
}
const _propertyName = "contentFailedReloadAction";
2021-11-04 05:56:25 +00:00
late ContentFailedReloadAction contentFailedReloadAction;
2021-09-29 23:57:09 +00:00
Future<void> initContentFailedReloadAction() async {
contentFailedReloadAction =
_contentFailedReloadActionFromString(await method.loadProperty(
_propertyName,
ContentFailedReloadAction.PULL_DOWN.toString(),
));
}
ContentFailedReloadAction _contentFailedReloadActionFromString(String string) {
for (var value in ContentFailedReloadAction.values) {
if (string == value.toString()) {
return value;
}
}
return ContentFailedReloadAction.PULL_DOWN;
}
2021-11-04 05:56:25 +00:00
Map<String, ContentFailedReloadAction> _contentFailedReloadActionMap = {
2021-09-29 23:57:09 +00:00
"下拉刷新": ContentFailedReloadAction.PULL_DOWN,
"点击屏幕刷新": ContentFailedReloadAction.TOUCH_LOADER,
};
2021-11-04 05:56:25 +00:00
String _currentContentFailedReloadActionName() {
for (var e in _contentFailedReloadActionMap.entries) {
2021-09-29 23:57:09 +00:00
if (e.value == contentFailedReloadAction) {
return e.key;
}
}
return '';
}
2021-11-04 05:56:25 +00:00
Future<void> _chooseContentFailedReloadAction(BuildContext context) async {
2021-09-29 23:57:09 +00:00
ContentFailedReloadAction? result =
await chooseMapDialog<ContentFailedReloadAction>(
2021-11-04 05:56:25 +00:00
context, _contentFailedReloadActionMap, "选择页面加载失败刷新的方式");
2021-09-29 23:57:09 +00:00
if (result != null) {
await method.saveProperty(_propertyName, result.toString());
contentFailedReloadAction = result;
}
}
2021-11-04 03:45:22 +00:00
2021-11-04 05:56:25 +00:00
Widget contentFailedReloadActionSetting() {
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setState) {
return ListTile(
title: Text("加载失败时"),
subtitle: Text(_currentContentFailedReloadActionName()),
onTap: () async {
await _chooseContentFailedReloadAction(context);
setState(() {});
},
);
},
);
}