更新readme

This commit is contained in:
DelLevin-Home
2026-06-19 19:16:32 +08:00
parent 631c532269
commit 5a6bd51864
23 changed files with 669 additions and 180 deletions

View File

@@ -4,10 +4,12 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'pages/home_page.dart';
import 'utils/theme/app_theme.dart';
import 'utils/app_router.dart';
import 'utils/user_prefs.dart';
import 'utils/changelog_service.dart';
import 'utils/sync/auto_backup_service.dart';
import 'utils/sync/server_sync_service.dart';
import 'utils/usage_stats_service.dart';
@@ -101,6 +103,8 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
ThemeMode? _lastAppliedTheme;
bool _updateCheckDone = false;
final GlobalKey<NavigatorState> _navigatorKey = GlobalKey<NavigatorState>();
@override
void initState() {
@@ -108,8 +112,76 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
WidgetsBinding.instance.addObserver(this);
widget.appProvider.loadThemeMode();
widget.appProvider.addListener(_onThemeChanged);
// 延迟到首帧后确保生效
WidgetsBinding.instance.addPostFrameCallback((_) => _applySystemUI());
WidgetsBinding.instance.addPostFrameCallback((_) {
_applySystemUI();
_checkUpdate(); // 不阻塞,完成后自行弹窗
});
}
/// 延迟到首页渲染后再检查版本更新,确保 context 已就绪
Future<void> _checkUpdate() async {
if (_updateCheckDone) return;
_updateCheckDone = true;
await Future.delayed(const Duration(milliseconds: 500));
var ctx = _navigatorKey.currentContext;
if (ctx == null || !ctx.mounted) return;
try {
final hasUpdate = await ChangelogService.hasUpdate();
if (!hasUpdate) return;
final latestVersion = await ChangelogService.fetchLatestVersion();
if (latestVersion == null) return;
final dismissed = UserPrefs().dismissedVersion;
if (dismissed == latestVersion) return;
ctx = _navigatorKey.currentContext;
if (ctx == null || !ctx.mounted) return;
_showUpdateDialog(ctx, latestVersion);
} catch (_) {}
}
void _showUpdateDialog(BuildContext context, String version) {
if (!context.mounted) return;
final colors = Theme.of(context).colorScheme;
showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: colors.surface,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
title: Row(children: [
Icon(Icons.system_update_outlined, color: colors.primary, size: 24),
const SizedBox(width: 10),
Text('发现新版本', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
]),
content: Text('新版本 $version 已发布,是否下载更新?',
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.5)),
actions: [
TextButton(
onPressed: () {
UserPrefs().setDismissedVersion(version);
Navigator.pop(ctx);
},
child: Text('不再显示', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.5))),
),
const SizedBox(width: 8),
FilledButton.icon(
onPressed: () async {
Navigator.pop(ctx);
try {
await launchUrl(Uri.parse('https://mooknote.iletter.top/#/'),
mode: LaunchMode.externalApplication);
} catch (_) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('链接失效')));
}
}
},
icon: const Icon(Icons.open_in_browser, size: 18),
label: const Text('去官网下载'),
),
],
actionsPadding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
),
);
}
void _onThemeChanged() {
@@ -160,7 +232,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
theme: AppTheme.lightTheme,
darkTheme: AppTheme.darkTheme,
themeMode: provider.themeMode,
localizationsDelegates: [
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
@@ -170,6 +242,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
Locale('en', 'US'),
],
home: const HomePage(),
navigatorKey: _navigatorKey,
onGenerateRoute: AppRouter.generateRoute,
builder: (context, child) {
return _AppIconWrapper(iconName: iconName, child: child!);

View File

@@ -629,7 +629,7 @@ class _BookDetailPageState extends State<BookDetailPage> {
final isOverlay = _detailStyle == 1;
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: isOverlay ? 5 : 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -662,7 +662,7 @@ class _BookDetailPageState extends State<BookDetailPage> {
final isOverlay = _detailStyle == 1;
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: isOverlay ? 5 : 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -695,7 +695,7 @@ class _BookDetailPageState extends State<BookDetailPage> {
final isOverlay = _detailStyle == 1;
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: isOverlay ? 5 : 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -728,7 +728,7 @@ class _BookDetailPageState extends State<BookDetailPage> {
final isOverlay = _detailStyle == 1;
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: isOverlay ? 5 : 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -760,7 +760,7 @@ class _BookDetailPageState extends State<BookDetailPage> {
Widget _buildGenresSection(Book book) {
final isOverlay = _detailStyle == 1;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: isOverlay ? 5 : 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [

View File

@@ -0,0 +1,306 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:url_launcher/url_launcher.dart';
import '../utils/changelog_service.dart';
/// 更新日志页面
class ChangelogPage extends StatefulWidget {
const ChangelogPage({super.key});
@override
State<ChangelogPage> createState() => _ChangelogPageState();
}
class _ChangelogPageState extends State<ChangelogPage> {
List<ChangelogItem>? _items;
bool _loading = true;
bool _checking = false;
static const _websiteUrl = 'https://mooknote.iletter.top/#/';
@override
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
final items = await ChangelogService.fetchChangelog();
if (mounted) setState(() { _items = items; _loading = false; });
}
Future<void> _checkUpdate() async {
setState(() => _checking = true);
try {
final hasUpdate = await ChangelogService.hasUpdate();
if (!mounted) return;
final info = await PackageInfo.fromPlatform();
final localVersion = 'v${info.version}';
if (!mounted) return;
if (hasUpdate) {
final latest = _items != null && _items!.isNotEmpty
? _items!.first.version
: '新版本';
final latestVersion = await ChangelogService.fetchLatestVersion();
_showUpdateDialog(
version: latestVersion ?? latest,
localVersion: localVersion,
);
} else {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('已是最新版本(当前 $localVersion'),
duration: const Duration(seconds: 2),
));
}
} catch (_) {}
if (mounted) setState(() => _checking = false);
}
void _showUpdateDialog({required String version, String? localVersion}) {
final colors = Theme.of(context).colorScheme;
showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: colors.surface,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
title: Row(children: [
Icon(Icons.system_update_outlined, color: colors.primary, size: 24),
const SizedBox(width: 10),
Text('发现新版本', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
]),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (localVersion != null) ...[
Text('当前版本:$localVersion',
style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.35))),
const SizedBox(height: 6),
],
Text('最新版本 $version 已发布,是否下载更新?',
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.5)),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: Text('稍后再说', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.5))),
),
const SizedBox(width: 8),
FilledButton.icon(
onPressed: () async {
Navigator.pop(ctx);
try {
await launchUrl(Uri.parse(_websiteUrl), mode: LaunchMode.externalApplication);
} catch (_) {}
},
icon: const Icon(Icons.open_in_browser, size: 18),
label: const Text('去官网下载'),
),
],
actionsPadding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
),
);
}
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: colors.surface,
appBar: AppBar(
title: const Text('更新日志'),
actions: [
_checking
? const Padding(
padding: EdgeInsets.only(right: 16),
child: SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2)))
: IconButton(
icon: const Icon(Icons.refresh, size: 20),
tooltip: '检查更新',
onPressed: _checkUpdate,
),
],
),
body: _loading
? const Center(child: CircularProgressIndicator())
: _items == null || _items!.isEmpty
? Center(
child: Text('暂无更新日志',
style: TextStyle(color: colors.onSurface.withValues(alpha: 0.4))))
: ListView(
padding: const EdgeInsets.all(20),
children: [
_buildWebsiteCard(colors),
const SizedBox(height: 20),
..._items!.map((item) => Padding(
padding: const EdgeInsets.only(bottom: 16),
child: _buildCard(item, colors),
)),
],
),
);
}
Widget _buildWebsiteCard(ColorScheme colors) {
return Container(
decoration: BoxDecoration(
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(12),
),
clipBehavior: Clip.antiAlias,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(18, 16, 18, 12),
child: Row(
children: [
Icon(Icons.language, size: 18, color: colors.primary),
const SizedBox(width: 8),
Text('官方网站',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: colors.onSurface)),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 18),
child: GestureDetector(
onTap: () async {
try {
await launchUrl(Uri.parse(_websiteUrl), mode: LaunchMode.externalApplication);
} catch (_) {}
},
child: Text(_websiteUrl,
style: TextStyle(fontSize: 13, color: colors.primary)),
),
),
const SizedBox(height: 14),
Divider(height: 1, color: colors.outlineVariant),
Row(
children: [
Expanded(
child: InkWell(
onTap: () {
Clipboard.setData(const ClipboardData(text: _websiteUrl));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('已复制到剪贴板'),
duration: Duration(seconds: 1),
));
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 12),
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.copy, size: 16, color: colors.onSurface.withValues(alpha: 0.5)),
const SizedBox(width: 6),
Text('复制链接',
style: TextStyle(fontSize: 13, color: colors.onSurface.withValues(alpha: 0.5))),
],
),
),
),
),
Container(width: 1, height: 24, color: colors.outlineVariant),
Expanded(
child: InkWell(
onTap: () async {
try {
await launchUrl(Uri.parse(_websiteUrl), mode: LaunchMode.externalApplication);
} catch (_) {}
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 12),
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.open_in_browser, size: 16, color: colors.primary),
const SizedBox(width: 6),
Text('浏览器打开',
style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: colors.primary)),
],
),
),
),
),
],
),
],
),
);
}
Widget _buildCard(ChangelogItem item, ColorScheme colors) {
return Container(
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: colors.primary,
borderRadius: BorderRadius.circular(12),
),
child: Text(
item.version,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: colors.onPrimary,
),
),
),
const SizedBox(width: 10),
Text(
item.date,
style: TextStyle(
fontSize: 13,
color: colors.onSurface.withValues(alpha: 0.5),
),
),
],
),
const SizedBox(height: 14),
...item.features.map((f) => Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(top: 6),
width: 6,
height: 6,
decoration: BoxDecoration(
color: colors.primary.withValues(alpha: 0.4),
shape: BoxShape.circle,
),
),
const SizedBox(width: 10),
Expanded(
child: Text(
f,
style: TextStyle(
fontSize: 14,
color: colors.onSurface.withValues(alpha: 0.75),
height: 1.5,
),
),
),
],
),
)),
],
),
);
}
}

View File

@@ -222,59 +222,45 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
);
}
/// 叠层模式:封面小图 + 标题/评分(毛玻璃卡片)
/// 叠层模式:封面小图 + 标题/评分
Widget _buildOverlayHeader(Movie movie) {
final hasPoster = movie.posterPath != null && movie.posterPath!.isNotEmpty;
return ClipRRect(
borderRadius: BorderRadius.circular(16),
child: BackdropFilter(
filter: ui.ImageFilter.blur(sigmaX: 15, sigmaY: 15),
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 100, height: 140,
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.08),
borderRadius: BorderRadius.circular(16),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 100, height: 140,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.3), blurRadius: 12, offset: const Offset(0, 4))],
),
clipBehavior: Clip.antiAlias,
child: hasPoster
? FadeInLocalImage(path: movie.posterPath, fit: BoxFit.cover)
: Container(color: Colors.white24, child: const Icon(Icons.movie_outlined, color: Colors.white38, size: 32)),
),
const SizedBox(width: 16),
Expanded(
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
const SizedBox(height: 4),
Text(movie.title, style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: Colors.white)),
if (movie.directors.isNotEmpty) ...[
const SizedBox(height: 6),
Text('导演:${movie.directors.join(' / ')}', style: TextStyle(fontSize: 14, color: Colors.white.withValues(alpha: 0.6))),
],
const SizedBox(height: 12),
Row(children: [
if (movie.rating != null && movie.rating! > 0) ...[
const Icon(Icons.star, size: 16, color: Color(0xFFFFB800)),
const SizedBox(width: 4),
Text(movie.rating!.toStringAsFixed(1), style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: Color(0xFFFFB800))),
const SizedBox(width: 16),
],
_statusChip(movie.status),
]),
]),
),
],
borderRadius: BorderRadius.circular(8),
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.3), blurRadius: 12, offset: const Offset(0, 4))],
),
clipBehavior: Clip.antiAlias,
child: hasPoster
? FadeInLocalImage(path: movie.posterPath, fit: BoxFit.cover)
: Container(color: Colors.white24, child: const Icon(Icons.movie_outlined, color: Colors.white38, size: 32)),
),
),
const SizedBox(width: 16),
Expanded(
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
const SizedBox(height: 4),
Text(movie.title, style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: Colors.white)),
if (movie.directors.isNotEmpty) ...[
const SizedBox(height: 6),
Text('导演:${movie.directors.join(' / ')}', style: TextStyle(fontSize: 14, color: Colors.white.withValues(alpha: 0.6))),
],
const SizedBox(height: 12),
Row(children: [
if (movie.rating != null && movie.rating! > 0) ...[
const Icon(Icons.star, size: 16, color: Color(0xFFFFB800)),
const SizedBox(width: 4),
Text(movie.rating!.toStringAsFixed(1), style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: Color(0xFFFFB800))),
const SizedBox(width: 16),
],
_statusChip(movie.status),
]),
]),
),
],
);
}
@@ -660,7 +646,7 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
final isOverlay = _detailStyle == 1;
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: isOverlay ? 5 : 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -693,7 +679,7 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
final isOverlay = _detailStyle == 1;
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: isOverlay ? 5 : 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -726,7 +712,7 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
final isOverlay = _detailStyle == 1;
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: isOverlay ? 5 : 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -758,7 +744,7 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
Widget _buildGenresSection(Movie movie) {
final isOverlay = _detailStyle == 1;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: isOverlay ? 5 : 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [

View File

@@ -12,6 +12,7 @@ import 'recycle_bin_page.dart';
import 'sync/backup_page.dart';
import '../widgets/fade_in_local_image.dart';
import 'statistics_page.dart';
import 'changelog_page.dart';
import 'sync/cloud_sync_page.dart';
import 'app_icon_picker_page.dart';
import 'tag_management_page.dart';
@@ -498,6 +499,13 @@ class _SettingsPageState extends State<SettingsPage> {
url: 'https://mooknote.iletter.top/#/guide',
),
Divider(height: 0.5, indent: 24, endIndent: 24, color: colors.outlineVariant),
_buildActionItem(
icon: Icons.update_outlined,
title: '更新日志',
subtitle: '查看版本更新内容',
onTap: () => Navigator.push(context, MaterialPageRoute(builder: (_) => const ChangelogPage())),
),
Divider(height: 0.5, indent: 24, endIndent: 24, color: colors.outlineVariant),
],
),
);

View File

@@ -0,0 +1,91 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:package_info_plus/package_info_plus.dart';
/// 更新日志数据模型
class ChangelogItem {
final String version;
final String date;
final List<String> features;
ChangelogItem({
required this.version,
required this.date,
required this.features,
});
factory ChangelogItem.fromJson(Map<String, dynamic> json) {
return ChangelogItem(
version: json['version'] ?? '',
date: json['date'] ?? '',
features: (json['features'] as List<dynamic>?)
?.map((e) => e.toString())
.toList() ??
[],
);
}
}
/// 版本更新检查服务
class ChangelogService {
static const _apiUrl = 'https://api.mooknote.iletter.top/api/changelog';
/// 获取更新日志列表
static Future<List<ChangelogItem>> fetchChangelog() async {
try {
final resp = await http
.get(Uri.parse(_apiUrl))
.timeout(const Duration(seconds: 5));
if (resp.statusCode == 200) {
final data = jsonDecode(resp.body);
final items = (data['items'] as List<dynamic>?)
?.map((e) => ChangelogItem.fromJson(e as Map<String, dynamic>))
.toList() ??
[];
return items;
}
} catch (_) {}
return [];
}
/// 获取最新版本号
static Future<String?> fetchLatestVersion() async {
final items = await fetchChangelog();
if (items.isNotEmpty) return items.first.version;
return null;
}
/// 比较两版本号a > b 则返回 1a < b 返回 -1相等返回 0
/// v0.1.9 → 当成数字 "0.19" = 0.190.1.88 → "0.188" = 0.188,所以 0.19 > 0.188
/// 实现方式:去掉 v把第一个点后的数字拼接再转 double 比较
static int compareVersion(String a, String b) {
double toNum(String v) {
final s = v.replaceFirst('v', '');
final dot = s.indexOf('.');
if (dot == -1) return double.tryParse(s) ?? 0;
// "0.1.9" → "0." + "19" = "0.19""0.1.88" → "0." + "188" = "0.188"
final major = s.substring(0, dot + 1); // "0."
final rest = s.substring(dot + 1).replaceAll('.', ''); // "19" 或 "188"
return double.tryParse('$major$rest') ?? 0;
}
final aVal = toNum(a);
final bVal = toNum(b);
debugPrint('[Update] compare: "$a"→$aVal vs "$b"→$bVal');
if (aVal > bVal) return 1;
if (aVal < bVal) return -1;
return 0;
}
/// 检查是否有新版本(远程 > 本地)
static Future<bool> hasUpdate() async {
final latest = await fetchLatestVersion();
if (latest == null) return false;
final info = await PackageInfo.fromPlatform();
final local = 'v${info.version}';
debugPrint('[Update] 远程: $latest, 本地: $local');
final result = compareVersion(latest, local) > 0;
debugPrint('[Update] 远程 > 本地? $result');
return result;
}
}

View File

@@ -154,4 +154,10 @@ class UserPrefs {
/// 上次同步到的 entry id
int get syncLastEntryId => prefs.getInt('syncLastEntryId') ?? 0;
Future<bool> setSyncLastEntryId(int value) => prefs.setInt('syncLastEntryId', value);
// ========== 版本更新 ==========
/// 已忽略的版本号(不再提示更新)
String get dismissedVersion => prefs.getString('dismissedVersion') ?? '';
Future<bool> setDismissedVersion(String value) => prefs.setString('dismissedVersion', value);
}