import 'dart:async'; import 'package:flutter/material.dart'; import '../api_client.dart'; import '../controller.dart'; import '../i18n.dart'; import '../theme.dart'; // --------------------------------------------------------------------------- // 关于页(从原 pages.dart 拆出,公开类名不变) // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- // 关于页 // --------------------------------------------------------------------------- class AboutPageView extends StatefulWidget { const AboutPageView({super.key, required this.controller, this.initialAbout}); final ShellController controller; /// 预置数据(仅用于测试 / 截图,正常运行时为 null,由后端提供)。 final AboutInfo? initialAbout; @override State createState() => _AboutPageViewState(); } class _AboutPageViewState extends State { AboutInfo? _about; bool _loading = true; String? _error; /// 重新下载启动器的进行状态与结果 bool _redownloading = false; String? _redownloadMsg; bool? _redownloadOk; @override void initState() { super.initState(); final preset = widget.initialAbout; if (preset != null) { _about = preset; _loading = false; return; } _load(); } Future _load() async { setState(() { _loading = true; _error = null; }); try { final about = await widget.controller.api.about(); if (!mounted) return; setState(() { _about = about; _loading = false; }); } catch (error) { if (!mounted) return; setState(() { _error = error.toString(); _loading = false; }); } } /// 重新下载启动器包:后端下完会用清单里的 sha256 逐块校验, /// 校验不过会直接返回失败,不会留下半个坏包。 Future _redownloadLauncher() async { setState(() { _redownloading = true; _redownloadMsg = null; _redownloadOk = null; }); try { final result = await widget.controller.api.redownloadLauncher(); if (!mounted) return; setState(() { _redownloading = false; _redownloadOk = result.ok; _redownloadMsg = result.ok ? T('about.redownloadOk', [result.version]) : (result.message.isEmpty ? T('about.redownloadFail') : result.message); }); } catch (error) { if (!mounted) return; setState(() { _redownloading = false; _redownloadOk = false; _redownloadMsg = error.toString(); }); } } @override Widget build(BuildContext context) { return ListView( padding: const EdgeInsets.fromLTRB( GcSpace.xxl, GcSpace.xxl, GcSpace.xxl, GcSpace.xxxl, ), children: [ GcPageHeader( title: T('nav.about'), subtitle: T('app.tagline'), ), const SizedBox(height: GcSpace.xxl), if (_loading) const Padding( padding: EdgeInsets.symmetric(vertical: 48), child: Center( child: SizedBox( width: 22, height: 22, child: CircularProgressIndicator(strokeWidth: 2), ), ), ) else if (_error != null) GcMessage( title: T('common.error'), message: _error, icon: Icons.error_outline_rounded, color: GcColors.danger, action: OutlinedButton( onPressed: _load, child: Text(T('common.retry')), ), ) else ...[ _versionCard(), const SizedBox(height: GcSpace.lg), _contributorsCard(), const SizedBox(height: GcSpace.lg), _thanksCard(), ], ], ); } Widget _versionCard() { final about = _about; // 左边身份卡、右边信息表:宽屏两栏,窄屏自动堆叠。 final identity = Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Row( children: [ Container( width: 44, height: 44, alignment: Alignment.center, decoration: BoxDecoration( color: GcColors.accentSoft, borderRadius: BorderRadius.circular(GcRadius.card), ), child: Text( '◎', style: TextStyle( fontSize: 22, height: 1.1, color: GcColors.accent), ), ), const SizedBox(width: GcSpace.lg), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text( about?.appName ?? 'Morris GC', style: TextStyle( fontSize: 20, height: 1.3, fontWeight: FontWeight.w600, color: GcColors.ink, ), ), const SizedBox(height: 2), Text( T('app.tagline'), style: TextStyle( fontSize: 12.5, height: 1.5, color: GcColors.faint, ), ), ], ), ), ], ), const SizedBox(height: GcSpace.lg), Wrap( spacing: GcSpace.sm, runSpacing: GcSpace.sm, children: [ GcPill('v${about?.version ?? '—'}', color: GcColors.accent), ], ), const SizedBox(height: GcSpace.lg), Wrap( spacing: GcSpace.sm, runSpacing: GcSpace.sm, children: [ OutlinedButton( onPressed: () async { final url = about?.repository; if (url == null || url.isEmpty) return; try { await widget.controller.api.openUrl(url); } catch (_) { // 忽略 } }, child: Text(T('about.openRepository')), ), OutlinedButton.icon( onPressed: _redownloading ? null : _redownloadLauncher, icon: _redownloading ? const SizedBox( width: 14, height: 14, child: CircularProgressIndicator(strokeWidth: 2), ) : const Icon(Icons.refresh_rounded, size: 16), label: Text( _redownloading ? T('about.redownloading') : T('about.redownload'), ), ), ], ), if (_redownloadMsg != null) ...[ const SizedBox(height: GcSpace.md), Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Icon( _redownloadOk == true ? Icons.verified_rounded : Icons.error_outline_rounded, size: 16, color: _redownloadOk == true ? GcColors.ok : GcColors.danger, ), const SizedBox(width: GcSpace.xs + 2), Expanded( child: Text( _redownloadMsg!, style: TextStyle( fontSize: 12, height: 1.45, color: _redownloadOk == true ? GcColors.muted : GcColors.danger, ), ), ), ], ), ], ], ); final details = Column( crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisSize: MainAxisSize.min, children: [ GcFieldRow( label: T('set.platform'), value: about?.platform ?? '—', ), GcFieldRow( label: T('about.architecture'), value: T('about.architectureValue'), ), GcFieldRow( label: T('about.sourceLanguage'), value: about?.sourceLanguage ?? 'C#', ), GcFieldRow( label: T('about.frontend'), value: about?.frontend ?? 'Flutter', ), GcFieldRow( label: T('about.gitService'), value: 'itxiaohui', ), GcFieldRow( label: T('set.license'), value: T('set.licenseValue'), ), ], ); return GcCard( padding: const EdgeInsets.all(GcSpace.xxl), child: LayoutBuilder( builder: (context, constraints) { if (constraints.maxWidth < 720) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ identity, const GcDivider(verticalPadding: GcSpace.lg), details, ], ); } return Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded(flex: 4, child: identity), const SizedBox(width: GcSpace.xxxl), Expanded(flex: 5, child: details), ], ); }, ), ); } Widget _contributorsCard() { final contributors = _about?.contributors ?? const []; return GcCard( padding: const EdgeInsets.all(GcSpace.xxl), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ GcSectionTitle( T('about.developers'), subtitle: T('about.contributorsHint'), ), const SizedBox(height: GcSpace.lg), if (contributors.isEmpty) GcHint(T('about.noContributors')) else Wrap( spacing: GcSpace.xl, runSpacing: GcSpace.md, children: [ for (final contributor in contributors) SizedBox( width: 220, child: Row( children: [ CircleAvatar( radius: 18, backgroundColor: GcColors.surfaceAlt, backgroundImage: contributor.avatarUrl == null ? null : NetworkImage(contributor.avatarUrl!), child: contributor.avatarUrl == null ? Text( '◎', style: TextStyle( fontSize: 14, color: GcColors.accent, ), ) : null, ), const SizedBox(width: GcSpace.md), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text( contributor.name, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 13, height: 1.4, fontWeight: FontWeight.w600, color: GcColors.ink, ), ), Text( T( 'about.contributions', [contributor.contributions], ), style: TextStyle( fontSize: 11.5, height: 1.4, color: GcColors.faint, ), ), ], ), ), ], ), ), ], ), ], ), ); } /// 特别感谢:与「开发者」分开列 —— 提供 Git 服务不等于往仓库提交代码, /// 混进贡献者列表会让提交数失去意义。 Widget _thanksCard() { return GcCard( padding: const EdgeInsets.all(GcSpace.xxl), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ GcSectionTitle( T('about.thanks'), subtitle: T('about.thanksHint'), ), const SizedBox(height: GcSpace.lg), Wrap( spacing: GcSpace.xl, runSpacing: GcSpace.md, children: [ _creditTile('地理洪老师', 'about.thanksGeo'), _creditTile('itxiaohui', 'about.thanksGit'), ], ), ], ), ); } Widget _creditTile(String name, String roleKey) { return SizedBox( width: 220, child: Row( children: [ CircleAvatar( radius: 18, backgroundColor: GcColors.surfaceAlt, child: Text( '◎', style: TextStyle(fontSize: 14, color: GcColors.accent), ), ), const SizedBox(width: GcSpace.md), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text( name, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 13, height: 1.4, fontWeight: FontWeight.w600, color: GcColors.ink, ), ), Text( T(roleKey), maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 11.5, height: 1.4, color: GcColors.faint, ), ), ], ), ), ], ), ); } }