import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../core/api/api_client.dart'; /// 更新日志条目(GET /public/release 的 changelog 数组,源自 version.yaml, /// 与官网下载页时间线同源)。 class ChangelogEntry { final String version; final String date; final String intro; final List<({String type, List items})> sections; const ChangelogEntry({ required this.version, required this.date, this.intro = '', this.sections = const [], }); factory ChangelogEntry.fromJson(Map json) => ChangelogEntry( version: json['version'] as String? ?? '', date: json['date'] as String? ?? '', intro: json['intro'] as String? ?? '', sections: [ for (final s in (json['sections'] as List? ?? const [])) if (s is Map) ( type: s['type'] as String? ?? '', items: [ for (final it in (s['items'] as List? ?? const [])) '$it', ], ), ], ); } /// 关于页更新日志(接口不可达时返回空列表,页面回退只显当前版本)。 final changelogProvider = FutureProvider>((ref) async { try { final resp = await ref.watch(apiClientProvider).get('/public/release'); final data = resp.data as Map; return [ for (final e in (data['changelog'] as List? ?? const [])) ChangelogEntry.fromJson(e as Map), ]; } catch (_) { return const []; } });