feat: 全面迁移到 Flutter + 新增 GitHub 源与 CI 流水线

前端
- 移除全部 Avalonia 依赖,模型渲染与界面统一改用 Flutter
- 新增用户页:登录/注册(SHA-512 + 盐)、签到积分(30 天一循环)、
  主题色积分购买、二选一随机、今日人品
- 新增百宝箱页、模型内嵌渲染页、自绘标题栏(最小化/最大化/关闭)
- 下载页显示模型下载进度条,下载源读取加速
- 关于页新增「重新下载启动器」并在下载后做 sha256 完整性校验
- 修复浅色主题下标题栏不跟随主题色、无法连接后端等问题

后端
- 新增 UserService:.GC/user/<用户名>.yaml 存用户名/积分/SHA-512 口令,
  登录返回 session token,本地 .GC/user/user.yaml 保存登录态
- 新增 /api/user/{register,login,me,signin,theme} 接口
- 去掉 Avalonia 窗口宿主,后端只提供 HTTP API

下载源
- 新增 GitHub 镜像源(Morris-morris-cloud/GC),与 Xhmcl 并发测速
- 单源探测超时收紧到 2 秒,取最快且可用的源;GitHub 复用 GiteaRemote
  (contents 带 ref、releases 带 per_page=100)

构建与 CI
- macOS 上默认只出 macOS 包,Windows 交给原生 Windows 构建
- 修复 Windows 交叉编译中 flutter-cpp-client-wrapper 双层目录嵌套
- 新增 GitHub Actions:
  · nightly-prerelease:每天 21:00 编译三平台,发布 nightly 预发布
  · build-bot:Issue/PR 评论 @build-bot build <mac|win-amd|win-arm|all>,
    发布 ip-prerelease 预发布
  · pr-review:检查能否编译、静态分析、合并冲突、是否落后 main
- 忽略 79MB 课件产物等高线.html 与工具链临时备份
This commit is contained in:
Morris committed 2026-11-21 19:18:58 +08:00
1 parent b9cb56cb8b
commit ea1fa6b6d1
134 files changed
+4309 -16614

No files matched your search

+93 -11
View File
@@ -32,6 +32,11 @@ class _AboutPageViewState extends State<AboutPageView> {
bool _loading = true;
String? _error;
/// 重新下载启动器的进行状态与结果
bool _redownloading = false;
String? _redownloadMsg;
bool? _redownloadOk;
@override
void initState() {
super.initState();
@@ -65,6 +70,34 @@ class _AboutPageViewState extends State<AboutPageView> {
}
}
/// 重新下载启动器包:后端下完会用清单里的 sha256 逐块校验,
/// 校验不过会直接返回失败,不会留下半个坏包。
Future<void> _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', <Object?>[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(
@@ -175,18 +208,67 @@ class _AboutPageViewState extends State<AboutPageView> {
],
),
const SizedBox(height: GcSpace.lg),
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')),
Wrap(
spacing: GcSpace.sm,
runSpacing: GcSpace.sm,
children: <Widget>[
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) ...<Widget>[
const SizedBox(height: GcSpace.md),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
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,
),
),
),
],
),
],
],
);
+111 -14
View File
@@ -114,25 +114,41 @@ class _DownloadPageViewState extends State<DownloadPageView> {
_error = null;
});
try {
final sources = await widget.controller.api.sources();
// 三个请求互不依赖,一起发出去:
// 源列表(本地,几乎即时)、任务列表、模型索引(要打远端,最慢)
// 以前是 sources → models → jobs 串行等三轮,进页面白等多一秒。
final sourcesFuture = widget.controller.api.sources();
final jobsFuture = widget.controller.api.jobs();
final indexFuture = widget.controller.api.remoteModels(
sourceId: _selectedSourceId,
);
final sources = await sourcesFuture;
final preferred = sources.where((s) => s.enabled).toList();
final selected = _selectedSourceId ??
(preferred.isNotEmpty
? preferred.first.id
: (sources.isNotEmpty ? sources.first.id : ''));
final index = selected.isEmpty
? null
: await widget.controller.api.remoteModels(sourceId: selected);
// 源列表是本地的,先画出来:右侧模型列表还在等远端索引,左侧不必陪着转圈
if (mounted) {
setState(() {
_sources = sources;
_selectedSourceId = selected;
});
}
final index = await indexFuture;
final jobs = await jobsFuture;
if (!mounted) return;
setState(() {
_sources = sources;
_selectedSourceId = selected;
_index = index;
_jobs = jobs;
_loading = false;
});
await _refreshJobs();
} catch (error) {
if (!mounted) return;
setState(() {
@@ -440,16 +456,97 @@ class _DownloadPageViewState extends State<DownloadPageView> {
),
),
const SizedBox(width: GcSpace.lg),
if (model.installed)
OutlinedButton(
onPressed: () => _download(model),
child: Text(T('dl.reinstall')),
)
else
FilledButton(
onPressed: () => _download(model),
child: Text(T('dl.download')),
_downloadAction(model),
],
),
);
}
/// 该模型是否有进行中的下载任务。
JobInfo? _activeJobFor(String modelId) {
for (final job in _jobs) {
if (job.isActive && job.modelId == modelId) return job;
}
return null;
}
/// 按钮位:空闲时是「下载 / 重新下载」,下载中就变成这一行的进度条。
Widget _downloadAction(RemoteModelInfo model) {
final job = _activeJobFor(model.id);
if (job == null) {
if (model.installed) {
return OutlinedButton(
onPressed: () => _download(model),
child: Text(T('dl.reinstall')),
);
}
return FilledButton(
onPressed: () => _download(model),
child: Text(T('dl.download')),
);
}
final value = job.progress.clamp(0.0, 1.0).toDouble();
final percent = (value * 100).round();
final detail = job.detailText.isNotEmpty ? job.detailText : job.statusText;
return SizedBox(
width: 148,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Row(
children: <Widget>[
Text(
'$percent%',
style: TextStyle(
fontSize: 12.5,
height: 1.2,
fontWeight: FontWeight.w600,
color: GcColors.accent,
),
),
const SizedBox(width: GcSpace.xs + 2),
if (detail.isNotEmpty)
Expanded(
child: Text(
detail,
maxLines: 1,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.right,
style: TextStyle(
fontSize: 11,
height: 1.2,
color: GcColors.faint,
),
),
),
TextButton(
onPressed: () =>
_jobAction(widget.controller.api.cancelJob, job.id),
style: TextButton.styleFrom(
minimumSize: const Size(0, 22),
padding: const EdgeInsets.symmetric(horizontal: GcSpace.sm),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: Text(
T('dl.cancel'),
style: const TextStyle(fontSize: 11.5),
),
),
],
),
const SizedBox(height: 3),
ClipRRect(
borderRadius: BorderRadius.circular(3),
child: LinearProgressIndicator(
// 还没拿到进度时走不确定态,避免显示 0% 让人以为卡住
value: value > 0 ? value : null,
minHeight: 6,
backgroundColor: GcColors.surfaceAlt,
),
),
],
),
);
+119
View File
@@ -0,0 +1,119 @@
import 'package:flutter/material.dart';
import '../i18n.dart';
import '../models/base.dart';
import '../models/lookup.dart';
import '../theme.dart';
/// 模型视图:在壳内直接渲染 Flutter 模型。
///
/// 以前「启动模型」是让后端另开一个 Avalonia 窗口;现在模型全部是 Flutter 实现,
/// 直接换掉内容区即可 —— 不会多出一个窗口,也不用跨进程传状态。
class ModelViewPage extends StatelessWidget {
const ModelViewPage({
super.key,
required this.modelId,
required this.onClose,
});
final String modelId;
final VoidCallback onClose;
@override
Widget build(BuildContext context) {
final model = flutterModelFor(modelId);
if (model == null) {
return Center(
child: GcCard(
padding: const EdgeInsets.all(GcSpace.xxl),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
T('model.missing'),
style: TextStyle(
fontSize: 15,
height: 1.35,
fontWeight: FontWeight.w600,
color: GcColors.ink,
),
),
const SizedBox(height: GcSpace.sm),
GcHint(T('model.missingHint')),
const SizedBox(height: GcSpace.lg),
OutlinedButton(
onPressed: onClose,
child: Text(T('model.back')),
),
],
),
),
);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(
GcSpace.xxl,
GcSpace.lg,
GcSpace.xxl,
GcSpace.sm,
),
child: Row(
children: <Widget>[
OutlinedButton.icon(
onPressed: onClose,
icon: const Icon(Icons.arrow_back_rounded, size: 16),
label: Text(T('model.back')),
),
const SizedBox(width: GcSpace.lg),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
model.name(),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16,
height: 1.3,
fontWeight: FontWeight.w600,
color: GcColors.ink,
),
),
const SizedBox(height: 2),
Text(
model.description(),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12,
height: 1.4,
color: GcColors.faint,
),
),
],
),
),
],
),
),
Expanded(child: ClipRect(child: _body(model))),
],
);
}
Widget _body(GcModel model) {
// 模型视图自己管状态(动画、视角),换 id 时必须重建,不能复用 State
return KeyedSubtree(
key: ValueKey<String>(model.id),
child: Builder(builder: (context) => model.buildView(context)),
);
}
}
+163
View File
@@ -0,0 +1,163 @@
import 'dart:math';
import 'package:flutter/material.dart';
import '../controller.dart';
import '../theme.dart';
import '../i18n.dart';
/// 百宝箱页:今日人品、随机运势等小玩意。
class TreasurePage extends StatefulWidget {
const TreasurePage({super.key, required this.controller});
final ShellController controller;
@override
State<TreasurePage> createState() => _TreasurePageState();
}
class _TreasurePageState extends State<TreasurePage> {
String _fortune = '';
String _luckyColor = '';
String _luckyNumber = '';
bool _loading = false;
final Random _rand = Random();
@override
void initState() {
super.initState();
_refresh();
}
void _refresh() {
setState(() => _loading = true);
// 模拟计算延迟
Future.delayed(const Duration(milliseconds: 400), () {
if (!mounted) return;
final fortunes = <String>[
'今日宜:尝试新事物,突破舒适区。',
'运气不错,适合做重要的决定。',
'财运旺盛,可能会有意外收获。',
'人际和谐,适合合作与沟通。',
'专注当下,好运自然来。',
'保持乐观,今天会有好消息。',
'灵感涌现,适合创作和思考。',
'脚踏实地,一步一个脚印。',
'贵人运旺,多与他人交流。',
'健康第一,注意休息和锻炼。',
];
final colors = <String>[
'红色', '蓝色', '绿色', '金色', '紫色', '橙色', '粉色', '青色',
];
setState(() {
_fortune = fortunes[_rand.nextInt(fortunes.length)];
_luckyColor = colors[_rand.nextInt(colors.length)];
_luckyNumber = '${(_rand.nextInt(99)) + 1}';
_loading = false;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: GcColors.appBg,
body: _loading
? const Center(child: CircularProgressIndicator())
: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 480),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
// 今日人品卡片
GcCard(
padding: const EdgeInsets.all(GcSpace.xxl),
child: Column(
children: <Widget>[
Icon(
Icons.star_rounded,
size: 48,
color: GcColors.accent,
),
const SizedBox(height: GcSpace.lg),
Text(
T('treasure.fortuneTitle'),
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: GcSpace.md),
Text(
_fortune,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
height: 1.5,
color: GcColors.muted,
),
),
],
),
),
const SizedBox(height: GcSpace.lg),
// 幸运信息
Wrap(
spacing: GcSpace.md,
runSpacing: GcSpace.md,
children: <Widget>[
_buildStatCard(
icon: Icons.check_circle_outline_rounded,
label: T('treasure.luckyColor'),
value: _luckyColor,
),
_buildStatCard(
icon: Icons.numbers_rounded,
label: T('treasure.luckyNumber'),
value: _luckyNumber,
),
],
),
const SizedBox(height: GcSpace.xl),
// 刷新按钮
FilledButton.icon(
onPressed: _refresh,
icon: const Icon(Icons.refresh_rounded, size: 18),
label: Text(T('treasure.refresh')),
),
],
),
),
),
);
}
Widget _buildStatCard({
required IconData icon,
required String label,
required String value,
}) {
return GcCard(
padding: const EdgeInsets.all(GcSpace.lg),
child: Column(
children: <Widget>[
Icon(icon, size: 28, color: GcColors.accent),
const SizedBox(height: GcSpace.sm),
Text(
label,
style: TextStyle(fontSize: 12, color: GcColors.muted),
),
const SizedBox(height: GcSpace.xs),
Text(
value,
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
),
),
],
),
);
}
}
+404
View File
@@ -0,0 +1,404 @@
import 'package:flutter/material.dart';
import 'dart:math';
import '../controller.dart';
import '../theme.dart';
import '../i18n.dart';
import '../models/user.dart';
/// 用户页面:登录/注册、签到、主题颜色、二选一
class UserPage extends StatefulWidget {
const UserPage({super.key, required this.controller});
final ShellController controller;
@override
State<UserPage> createState() => _UserPageState();
}
class _UserPageState extends State<UserPage> {
UserRecord? _user;
bool _loading = true;
String? _error;
// 登录/注册表单
final _usernameCtrl = TextEditingController();
final _passwordCtrl = TextEditingController();
bool _isLogin = true;
// 二选一
final _option1Ctrl = TextEditingController();
final _option2Ctrl = TextEditingController();
String? _randomResult;
@override
void initState() {
super.initState();
_loadUser();
}
@override
void dispose() {
_usernameCtrl.dispose();
_passwordCtrl.dispose();
_option1Ctrl.dispose();
_option2Ctrl.dispose();
super.dispose();
}
Future<void> _loadUser() async {
setState(() {
_loading = true;
_error = null;
});
try {
await widget.controller.api.initUserSession();
final resp = await widget.controller.api.me();
if (!mounted) return;
if (resp != null) {
setState(() {
_user = UserRecord.fromJson(resp);
_loading = false;
});
} else {
setState(() {
_loading = false;
});
}
} catch (e) {
if (!mounted) return;
setState(() {
_loading = false;
_error = e.toString();
});
}
}
Future<void> _loginOrRegister() async {
final username = _usernameCtrl.text.trim();
final password = _passwordCtrl.text;
if (username.isEmpty || password.isEmpty) {
_showError(T('user.fillAll'));
return;
}
try {
Map<String, dynamic> resp;
if (_isLogin) {
resp = await widget.controller.api.login(username, password);
} else {
resp = await widget.controller.api.register(username, password);
if (!mounted) return;
// 注册成功后自动登录
resp = await widget.controller.api.login(username, password);
}
if (!mounted) return;
setState(() {
_user = UserRecord.fromJson(resp);
_usernameCtrl.clear();
_passwordCtrl.clear();
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(_isLogin ? T('user.loginSuccess') : T('user.registerSuccess'))),
);
} catch (e) {
if (!mounted) return;
_showError(e.toString());
}
}
Future<void> _signin() async {
try {
final resp = await widget.controller.api.signin();
if (!mounted) return;
if (resp.containsKey('message') && resp['message'] == '今日已签到') {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(T('user.alreadySigned'))),
);
return;
}
setState(() {
_user = UserRecord.fromJson({
...resp,
'username': _user?.username ?? '',
});
});
final reward = resp['reward'] as int? ?? 0;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('${T('user.signinSuccess')} +$reward ${T('user.points')}')),
);
} catch (e) {
if (!mounted) return;
_showError(e.toString());
}
}
void _pickRandom() {
final opt1 = _option1Ctrl.text.trim();
final opt2 = _option2Ctrl.text.trim();
if (opt1.isEmpty || opt2.isEmpty) {
_showError(T('user.fillOptions'));
return;
}
final result = Random().nextBool() ? opt1 : opt2;
setState(() => _randomResult = result);
}
Future<void> _changeTheme(String hex, int cost) async {
if (_user == null) {
_showError(T('user.loginFirst'));
return;
}
try {
final resp = await widget.controller.api.changeTheme(hex, cost);
if (!mounted) return;
if (resp.containsKey('message')) {
setState(() {
_user = UserRecord(
username: _user!.username,
points: resp['points'] as int? ?? _user!.points,
consecutiveDays: _user!.consecutiveDays,
lastSignIn: _user!.lastSignIn,
themeColor: '0x${resp['theme_color'] ?? hex}',
);
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('主题已更新')),
);
}
} catch (e) {
if (!mounted) return;
_showError(e.toString());
}
}
void _showError(String msg) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(msg)),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: GcColors.appBg,
body: _loading
? const Center(child: CircularProgressIndicator())
: SingleChildScrollView(
padding: const EdgeInsets.all(GcSpace.xxl),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
// 用户信息卡片
if (_user != null) ...[
GcCard(
padding: const EdgeInsets.all(GcSpace.lg),
child: Row(
children: <Widget>[
Icon(Icons.person_rounded, size: 40, color: GcColors.accent),
const SizedBox(width: GcSpace.md),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_user!.username,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 4),
Text(
'${T('user.points')}: ${_user!.points}',
style: TextStyle(color: GcColors.muted),
),
Text(
'${T('user.days')}: ${_user!.consecutiveDays}',
style: TextStyle(color: GcColors.muted),
),
],
),
),
FilledButton(
onPressed: _signin,
child: Text(T('user.signin')),
),
],
),
),
const SizedBox(height: GcSpace.lg),
],
// 登录/注册表单
GcCard(
padding: const EdgeInsets.all(GcSpace.lg),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_isLogin ? T('user.login') : T('user.register'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: GcSpace.md),
TextField(
controller: _usernameCtrl,
decoration: InputDecoration(
labelText: T('user.username'),
border: const OutlineInputBorder(),
),
),
const SizedBox(height: GcSpace.md),
TextField(
controller: _passwordCtrl,
decoration: InputDecoration(
labelText: T('user.password'),
border: const OutlineInputBorder(),
),
obscureText: true,
),
const SizedBox(height: GcSpace.md),
FilledButton(
onPressed: _loginOrRegister,
child: Text(_isLogin ? T('user.login') : T('user.register')),
),
TextButton(
onPressed: () => setState(() => _isLogin = !_isLogin),
child: Text(_isLogin ? T('user.switchToRegister') : T('user.switchToLogin')),
),
],
),
),
const SizedBox(height: GcSpace.lg),
// 二选一
GcCard(
padding: const EdgeInsets.all(GcSpace.lg),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
T('user.pick'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: GcSpace.md),
TextField(
controller: _option1Ctrl,
decoration: InputDecoration(
labelText: T('user.option1'),
border: const OutlineInputBorder(),
),
),
const SizedBox(height: GcSpace.md),
TextField(
controller: _option2Ctrl,
decoration: InputDecoration(
labelText: T('user.option2'),
border: const OutlineInputBorder(),
),
),
const SizedBox(height: GcSpace.md),
FilledButton(
onPressed: _pickRandom,
child: Text(T('user.pickRandom')),
),
if (_randomResult != null) ...[
const SizedBox(height: GcSpace.md),
GcCard(
child: Text(
_randomResult!,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
),
],
],
),
),
const SizedBox(height: GcSpace.lg),
// 主题颜色
GcCard(
padding: const EdgeInsets.all(GcSpace.lg),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
T('user.theme'),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: GcSpace.md),
Wrap(
spacing: GcSpace.md,
runSpacing: GcSpace.md,
children: ThemeColor.predefined.map((c) {
final canAfford = _user == null || _user!.points >= c.cost;
final isCurrent = _user?.themeColor == '0x$c.hex';
return InkWell(
onTap: canAfford ? () => _changeTheme(c.hex, c.cost) : null,
borderRadius: BorderRadius.circular(8),
child: Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Color(int.parse('0xFF${c.hex}')),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: isCurrent ? GcColors.accent : GcColors.line,
width: isCurrent ? 2 : 1,
),
),
child: Stack(
children: <Widget>[
if (c.cost > 0 && !_canAfford(c.cost))
Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
borderRadius: BorderRadius.circular(8),
),
child: Center(
child: Text(
'${c.cost}',
style: const TextStyle(color: Colors.white, fontSize: 12),
),
),
),
if (isCurrent)
const Positioned(
bottom: 2,
right: 2,
child: Icon(Icons.check_rounded, size: 16, color: Colors.white),
),
],
),
),
);
}).toList(),
),
],
),
),
if (_error != null) ...[
const SizedBox(height: GcSpace.md),
Text(_error!, style: const TextStyle(color: Colors.red)),
],
],
),
),
);
}
bool _canAfford(int cost) {
if (cost <= 0) return true;
if (_user == null) return false;
return _user!.points >= cost;
}
}