release
This commit is contained in:
@@ -85,14 +85,12 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
|
||||
) ??
|
||||
[];
|
||||
if (existingData.length >= 500) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text('缓存已达上限500条,请先清空缓存'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'提示',
|
||||
'缓存已达上限500条,请先清空缓存',
|
||||
colorText: themeController.currentThemeColor,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -100,23 +98,24 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
|
||||
if (_selectedCount == 100) {
|
||||
final isUserPlanJoined = await _checkUserPlanStatus();
|
||||
if (!isUserPlanJoined) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text('100条下载需要加入用户体验计划'),
|
||||
backgroundColor: Colors.orange,
|
||||
action: SnackBarAction(
|
||||
label: '去加入',
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const UserPlanPage()),
|
||||
);
|
||||
},
|
||||
),
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'提示',
|
||||
'100条下载需要加入用户体验计划',
|
||||
colorText: themeController.currentThemeColor,
|
||||
mainButton: TextButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const UserPlanPage()),
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
'去加入',
|
||||
style: TextStyle(color: themeController.currentThemeColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -149,14 +148,12 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
|
||||
// 取消时保存已下载的数据
|
||||
if (_downloadedCount > 0) {
|
||||
await prefs.setStringList(dataKey, currentData);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('已保存 $_downloadedCount 条数据'),
|
||||
backgroundColor: _themeController.currentThemeColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'提示',
|
||||
'已保存 $_downloadedCount 条数据',
|
||||
colorText: themeController.currentThemeColor,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -240,17 +237,15 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
|
||||
|
||||
// 检查总缓存数量
|
||||
if (currentData.length > 500) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text('缓存将超过500条上限,请先清空缓存'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'提示',
|
||||
'缓存将超过500条上限,请先清空缓存',
|
||||
colorText: themeController.currentThemeColor,
|
||||
);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -260,13 +255,12 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
|
||||
_cachedCount = currentData.length;
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'成功缓存 ${_selectedType == DownloadType.poetry ? '诗词' : '答题'} $_cachedCount 条数据',
|
||||
),
|
||||
backgroundColor: _themeController.currentThemeColor,
|
||||
),
|
||||
final themeController = Get.find<ThemeController>();
|
||||
final themeController2 = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'成功',
|
||||
'成功缓存 ${_selectedType == DownloadType.poetry ? '诗词' : '答题'} $_cachedCount 条数据',
|
||||
colorText: themeController2.currentThemeColor,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -275,8 +269,11 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
|
||||
_status = '下载失败: $e';
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('下载失败: $e'), backgroundColor: Colors.red),
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'错误',
|
||||
'下载失败: $e',
|
||||
colorText: themeController.currentThemeColor,
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
@@ -297,14 +294,12 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
|
||||
final quizCount = (prefs.getStringList('offline_quiz_data') ?? []).length;
|
||||
|
||||
if (poetryCount == 0 && quizCount == 0) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('暂无缓存数据'),
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
);
|
||||
}
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'提示',
|
||||
'暂无缓存数据',
|
||||
colorText: themeController.currentThemeColor,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -367,14 +362,12 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove(key);
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('已清空$typeName离线数据'),
|
||||
backgroundColor: _themeController.currentThemeColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'成功',
|
||||
'已清空$typeName离线数据',
|
||||
colorText: themeController.currentThemeColor,
|
||||
);
|
||||
|
||||
// 更新对应的计数
|
||||
if (key == 'offline_poetry_data') {
|
||||
@@ -399,14 +392,12 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
|
||||
await prefs.remove('offline_poetry_data');
|
||||
await prefs.remove('offline_quiz_data');
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text('已清空所有离线数据'),
|
||||
backgroundColor: _themeController.currentThemeColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'成功',
|
||||
'已清空所有离线数据',
|
||||
colorText: themeController.currentThemeColor,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
_poetryCount = 0;
|
||||
@@ -455,55 +446,47 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
|
||||
if (data['status'] == 'success') {
|
||||
_displayServerInfoDialog(data);
|
||||
} else {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('服务器返回错误状态: ${data['status']}'),
|
||||
backgroundColor: Colors.red,
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('解析服务器数据失败: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'错误',
|
||||
'服务器返回错误状态: ${data['status']}',
|
||||
colorText: themeController.currentThemeColor,
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mounted) {
|
||||
final errorMsg =
|
||||
'获取服务器信息失败\n'
|
||||
'状态码: ${response.statusCode}\n'
|
||||
'消息: ${response.message}';
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(errorMsg),
|
||||
backgroundColor: Colors.red,
|
||||
duration: const Duration(seconds: 5),
|
||||
),
|
||||
} catch (e) {
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'错误',
|
||||
'解析服务器数据失败: $e',
|
||||
colorText: themeController.currentThemeColor,
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
final errorMsg =
|
||||
'获取服务器信息失败\n'
|
||||
'状态码: ${response.statusCode}\n'
|
||||
'消息: ${response.message}';
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'错误',
|
||||
errorMsg,
|
||||
colorText: themeController.currentThemeColor,
|
||||
duration: const Duration(seconds: 5),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
|
||||
Navigator.of(context).pop();
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('获取服务器信息异常: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
duration: const Duration(seconds: 5),
|
||||
),
|
||||
);
|
||||
}
|
||||
final themeController = Get.find<ThemeController>();
|
||||
Get.snackbar(
|
||||
'错误',
|
||||
'获取服务器信息异常: $e',
|
||||
colorText: themeController.currentThemeColor,
|
||||
duration: const Duration(seconds: 5),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user