feat: add elastic glass dock motion and Android tablet layouts
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
# TPSchedule
|
||||
|
||||
当前Android版本0.7.8+28:提前建立通知类别、区分通知总开关和类别状态,见[通知排查记录](docs/tpschedule-0.7.8-notification-permissions.md)。用户手机已通过开启通知权限并重测确认恢复后台通知。Dock乳白透光层和边缘折射继续保留,见[材质优化记录](docs/tpschedule-0.7.8-dock-refinement.md)。本科/研究生HTML反馈见[0.7.8功能记录](docs/tpschedule-0.7.8-validation.md)及[反馈服务说明](server/feedback/html-diagnostic-update.md),更新管理后台见[部署说明](server/updates/README.md)。
|
||||
当前Android版本0.7.8+29:Dock点按/拖动弹性与Android平板横竖屏、分屏适配,见[本次验证记录](docs/tpschedule-0.7.8-dock-tablet.md)。构建28已提前建立通知类别、区分通知总开关和类别状态,见[通知排查记录](docs/tpschedule-0.7.8-notification-permissions.md)。用户手机已通过开启通知权限并重测确认恢复后台通知。Dock乳白透光层和边缘折射继续保留,见[材质优化记录](docs/tpschedule-0.7.8-dock-refinement.md)。本科/研究生HTML反馈见[0.7.8功能记录](docs/tpschedule-0.7.8-validation.md)及[反馈服务说明](server/feedback/html-diagnostic-update.md),更新管理后台见[部署说明](server/updates/README.md)。
|
||||
|
||||
0.7.0补充:考试页查询类型与卡片保持16像素间距;反馈问题和建议可自选附带最近10分钟的登录/读取/提醒诊断日志。默认不发送,不含密码、Cookie或课表内容,单独作为邮件文本附件。服务端需按[日志附件更新说明](server/feedback/diagnostic-log-update.md)手动更新;真实学校登录及SMTP未由本次离线测试代替验证。玻璃取样偏移仍在调查,未纳入本次修复结论。
|
||||
|
||||
学生课表 APP,Flutter 实现,支持电子科技大学研究生和本科生系统。Android 0.7.8+28,Android 7.0 及以上。
|
||||
学生课表 APP,Flutter 实现,支持电子科技大学研究生和本科生系统。Android 0.7.8+29,Android 7.0 及以上。
|
||||
|
||||
使用用户提供的原始 SVG 图标,蓝色渐变、黄色日历框及白色笔画保持一致;启动画面使用相同配色。0.5.1修复重复启动页闪烁:初始化期间保留原生启动屏,数据就绪后直接显示课表首帧,不再叠加Flutter品牌页或淡出动画。Android12+ 原生启动屏使用同色纯蓝背景及图标,旧版采用蓝色渐变。
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Android 首版验证记录
|
||||
|
||||
当前版本为0.7.8+28,通知权限恢复、通道初始化及真实后台触发见[通知记录](tpschedule-0.7.8-notification-permissions.md)。Dock乳白透光材质见[优化记录](tpschedule-0.7.8-dock-refinement.md)。本科/研究生HTML反馈及签名、备案信息见[0.7.8功能记录](tpschedule-0.7.8-validation.md)。应用更新检查与后台说明见[0.7.6记录](tpschedule-0.7.6-updates.md)。本科考试兼容的验证见[0.7.5记录](tpschedule-0.7.5-validation.md)。两例真实课表缺失字段问题待新页面定位。本科接入记录见[0.7.0记录](tpschedule-0.7.0-validation.md)。下文为首版历史记录。
|
||||
当前版本为0.7.8+29,Dock弹性与Android平板验证见[本次记录](tpschedule-0.7.8-dock-tablet.md)。构建28的通知权限恢复、通道初始化及真实后台触发见[通知记录](tpschedule-0.7.8-notification-permissions.md)。Dock乳白透光材质见[优化记录](tpschedule-0.7.8-dock-refinement.md)。本科/研究生HTML反馈及签名、备案信息见[0.7.8功能记录](tpschedule-0.7.8-validation.md)。应用更新检查与后台说明见[0.7.6记录](tpschedule-0.7.6-updates.md)。本科考试兼容的验证见[0.7.5记录](tpschedule-0.7.5-validation.md)。两例真实课表缺失字段问题待新页面定位。本科接入记录见[0.7.0记录](tpschedule-0.7.0-validation.md)。下文为首版历史记录。
|
||||
|
||||
日期:2026-10-13。测试环境:Flutter 3.47.7 / Dart 3.13.5 / JDK 17;Android 16 API 36,Pixel 7 模拟器,1080×2400。首版版本 0.1.0+1,包 ID com.example.hepan_everyday,最低 Android 7.0(API 24)。
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Dock 与平板实现计划
|
||||
|
||||
本会话直接实现。版本保留0.7.8,构建号递增29。旧APK、登记备份和密钥保持原样。
|
||||
|
||||
1. 先修改点按动画测试为新需求,增加连续反向点击、外层联动和减少动画断言,运行并确认失败。
|
||||
2. 实现单一位置弹簧、短暂点按形变和外层独立布局形变,保留实时折射和稳定图标层。拖动速度和位移必须有界,父组件确认选中状态不能重启动画。
|
||||
3. 增加平板/分屏布局测试,覆盖七天同屏、宽屏文字、内容限宽、横竖屏切换与操作。实现共用AdaptivePage和宽屏课表文字、Dock宽度适配,并覆盖设置和反馈。
|
||||
4. 运行受影响测试、完整测试和静态分析;正式构建,检查Android模拟器手机/平板与动画关键帧,审查改动。保存版本化APK、源码、更新说明,校验签名/旧文件与登记备份。
|
||||
|
||||
审查重点:连续点击时位置连续;外层形变采样与实际布局一致;拖动取消无误切页;窗口缩放不重置标签/周;小窗口及大字体无溢出;减少动画无弹性。
|
||||
@@ -0,0 +1,13 @@
|
||||
# Dock 弹性与 Android 平板适配
|
||||
|
||||
用户要求参考本地视频 20261028-104403.mp4:点按和拖动均有弹性落位,拖动滑块带动外层 Dock,玻璃下内容可辨,图标文字清楚;同时支持平板。沿用用户已授权直接执行的工作方式,不追加确认流程。
|
||||
|
||||
采用现有 Flutter 弹簧动画和实时背景折射,不引入浏览器或新玻璃组件库。相比整体放大变换,这样能通过实际布局更新玻璃区域,避免非等比变换造成采样坐标偏移;相比仅加大模糊,可保留背景颜色与轮廓。
|
||||
|
||||
- 滑块:点按短促伸缩和轻微弹簧落位;连续点击从当前位置、速度接续;拖动仍放大,松手回弹,取消不换页。
|
||||
- 外层:按压与拖动引起小幅扩张,轻微向滑块所在侧延伸;文字和图标单独绘制,保持稳定清晰。静止仍为灰色滑块、浅白通透玻璃、蓝色图标白光。高度保持紧凑。
|
||||
- 无障碍:减少动态效果时直接落位,不播放放大、抖动或外层形变。
|
||||
- 平板:根据当前窗口宽度适配,兼容横竖屏和分屏。宽度不足600逻辑像素维持手机布局;宽屏课表最多1440,考试/个人页最多840,设置/反馈最多760,居中留边。课表保持七天同屏,并在宽列增大课程和时间文字。Dock 平板宽300、高58,手机264×58;不添加侧栏。
|
||||
- Android 沿用可旋转/可调整大小的默认 Activity,不改变签名、权限、包名及持久化格式。不宣称已验证 iPad。
|
||||
|
||||
验证:点按弹性、快速反向点按、按住/拖动外层变化、取消、减弱动态效果;手机与800×1280、1280×800平板和分屏布局无溢出,七天可见,切页/周状态保留,设置/反馈可用;完整测试、分析、正式签名APK和模拟器视觉检查。
|
||||
@@ -0,0 +1,25 @@
|
||||
# 0.7.8+29 Dock 弹性与 Android 平板适配
|
||||
|
||||
参考用户提供的 20261028-104403.mp4,保留浅白通透底座、灰色静止滑块、蓝色图标白光和课表/考试/我的文字。
|
||||
|
||||
点按改为弹簧移动,移动中短暂拉伸,落位有克制回弹。连续点按继承位置和速度,未结束的尺寸脉冲继续播放,避免重新开始导致边缘跳动。拖动滑块继续放大并变通透;底座随按压和拖动方向轻微扩张、偏移、回弹。通过调整玻璃实际布局范围实现,图标和文字保持独立,未对整个Dock做拉伸变换。沿用原折射着色器和轻模糊,不增加雾化程度。
|
||||
|
||||
当前窗口达到600逻辑像素时Dock宽300,高58;窄窗口保持264×58。课表区域最多1440宽,考试和我的最多840宽,设置和反馈最多760宽,居中留边。课表每列足够宽时使用更大字号,并用同样字号重新计算老师、教室的完整显示高度。仍为七天同屏和统一节次高度,课程名可省略并点开详情。横竖屏和分屏缩放保留当前标签、周次和滚动状态。
|
||||
|
||||
系统减少动画时直接落位,关闭形变;动画运行中开启该设置会清零尺寸脉冲,重新关闭也不会留下冻结形变。
|
||||
|
||||
## 验证
|
||||
|
||||
- 314项Flutter测试通过,静态分析无问题,正式APK构建成功。
|
||||
- 新增/更新行为测试覆盖:点按弹性和有界回弹,快速连续反向点按(90ms、230ms,检查位置与尺寸连续),拖动外框联动、取消归位、减少动画即时/运行中切换、Dock常驻。
|
||||
- 布局测试覆盖800×1280及1280×800,缩窄到480×800,七天可见、切换标签返回时周次不变、设置/反馈在1.5倍字号下无溢出并可输入。
|
||||
- 旧冲突卡片测试在更大字号下出现2.84e-14的浮点边界差异,改为0.001逻辑像素容差;课程仍为上下相接,无可见重叠。
|
||||
- Android16/API36测试模拟器安装正式APK成功;1920×1200和1200×1920物理尺寸、密度240分别对应1280×800和800×1280逻辑窗口。实际打开示例课表、切换页面、换周并改变屏幕方向,周次保留;恢复手机尺寸也正常。检查截图并录制点按/拖动动画,未发现Flutter或AndroidRuntime致命错误。
|
||||
- 模拟器原生页面检查使用兼容软件渲染,验证布局和动画;支持着色器的Flutter测试另行通过,包含背景颜色、柔化、边缘折射和坐标对齐测试。未在实体平板或iPad上验证,不把兼容渲染截图当作实体设备折射效果的证明。
|
||||
- 独立审查发现的两项动画边界问题均先用测试复现再修正:中途开关减少动画的冻结脉冲;连续点击重置脉冲/限速导致尺寸跳变。修正后全套314项测试通过。
|
||||
|
||||
## 交付
|
||||
|
||||
显示版本0.7.8,构建号29,包名com.tpschedule.app。APK、源码和截图按构建号保存于dist。签名MD5仍为78 DE 91 19 AD 14 72 7F A1 C5 E5 E4 E6 81 45 EE;证书和RSA公钥与28一致。密钥、旧版本安装包和0.5.4登记冻结资料保持原样。
|
||||
|
||||
这次只更新APP,不需要更新服务器。若使用更新后台推送,填写版本0.7.8、构建号29,并提供本次APK对应的HTTPS下载链接。
|
||||
@@ -1,3 +1,3 @@
|
||||
const appVersion = '0.7.8';
|
||||
const appBuildNumber = 28;
|
||||
const appBuildNumber = 29;
|
||||
const appFilingNumber = '蜀ICP备2025169276号-5A';
|
||||
|
||||
@@ -11,6 +11,7 @@ import '../features/timetable/course_details.dart';
|
||||
import 'app_controller.dart';
|
||||
import 'app_theme.dart';
|
||||
import '../widgets/glass_dock.dart';
|
||||
import '../widgets/adaptive_page.dart';
|
||||
import '../widgets/tab_deck.dart';
|
||||
import '../features/exams/exams_page.dart';
|
||||
import '../features/timetable/timetable_page.dart';
|
||||
@@ -439,46 +440,53 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
|
||||
child: TabDeck(
|
||||
index: _tab,
|
||||
children: [
|
||||
TimetablePage(
|
||||
controller: widget.controller,
|
||||
onSync: _school,
|
||||
AdaptivePage(
|
||||
maxWidth: 1440,
|
||||
child: TimetablePage(
|
||||
controller: widget.controller,
|
||||
onSync: _school,
|
||||
),
|
||||
),
|
||||
ExamsPage(
|
||||
controller: widget.controller,
|
||||
onSync: () {
|
||||
_school(exams: true);
|
||||
},
|
||||
onQueryOptions:
|
||||
_knownSchool ==
|
||||
SupportedSchool.uestcUndergraduate
|
||||
? () => _school(exams: true, chooseTerm: true)
|
||||
: null,
|
||||
AdaptivePage(
|
||||
child: ExamsPage(
|
||||
controller: widget.controller,
|
||||
onSync: () {
|
||||
_school(exams: true);
|
||||
},
|
||||
onQueryOptions:
|
||||
_knownSchool ==
|
||||
SupportedSchool.uestcUndergraduate
|
||||
? () => _school(exams: true, chooseTerm: true)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
ProfilePage(
|
||||
controller: widget.controller,
|
||||
feedbackSender: widget.feedbackSender,
|
||||
onCheckUpdates: widget.updateService == null
|
||||
? null
|
||||
: () => _checkUpdate(),
|
||||
checkingUpdates: _checkingUpdate,
|
||||
onLogin: () => _school(selectSchool: true),
|
||||
schoolName: _knownSchool?.label,
|
||||
onUpdateTerm: () => _school(chooseTerm: true),
|
||||
authStatus:
|
||||
_knownSchool ==
|
||||
SupportedSchool.uestcUndergraduate
|
||||
? widget.undergraduate?.statusLabel ?? '未登录'
|
||||
: widget.school?.statusLabel ?? '未登录',
|
||||
logoutLabel:
|
||||
widget.school?.logoutFailed == true ||
|
||||
widget.undergraduate?.logoutFailed == true
|
||||
? '重试退出学校登录'
|
||||
: '退出学校登录',
|
||||
onLogout:
|
||||
widget.school?.canLogout == true ||
|
||||
widget.undergraduate?.canLogout == true
|
||||
? _logout
|
||||
: null,
|
||||
AdaptivePage(
|
||||
child: ProfilePage(
|
||||
controller: widget.controller,
|
||||
feedbackSender: widget.feedbackSender,
|
||||
onCheckUpdates: widget.updateService == null
|
||||
? null
|
||||
: () => _checkUpdate(),
|
||||
checkingUpdates: _checkingUpdate,
|
||||
onLogin: () => _school(selectSchool: true),
|
||||
schoolName: _knownSchool?.label,
|
||||
onUpdateTerm: () => _school(chooseTerm: true),
|
||||
authStatus:
|
||||
_knownSchool ==
|
||||
SupportedSchool.uestcUndergraduate
|
||||
? widget.undergraduate?.statusLabel ?? '未登录'
|
||||
: widget.school?.statusLabel ?? '未登录',
|
||||
logoutLabel:
|
||||
widget.school?.logoutFailed == true ||
|
||||
widget.undergraduate?.logoutFailed == true
|
||||
? '重试退出学校登录'
|
||||
: '退出学校登录',
|
||||
onLogout:
|
||||
widget.school?.canLogout == true ||
|
||||
widget.undergraduate?.canLogout == true
|
||||
? _logout
|
||||
: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../../app/app_theme.dart';
|
||||
import '../../services/diagnostic_log.dart';
|
||||
import '../../services/school_page_diagnostic.dart';
|
||||
import 'feedback_submission.dart';
|
||||
import '../../widgets/adaptive_page.dart';
|
||||
|
||||
typedef FeedbackAttachmentPicker = Future<FeedbackAttachment?> Function();
|
||||
|
||||
@@ -170,287 +171,292 @@ class _FeedbackPageState extends State<FeedbackPage> {
|
||||
canPop: !_submitting,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(title: const Text('反馈与共建')),
|
||||
body: _success
|
||||
? _successView(context)
|
||||
: _uncertain
|
||||
? _uncertainView()
|
||||
: Form(
|
||||
key: _form,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(22),
|
||||
children: [
|
||||
SegmentedButton<FeedbackKind>(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
value: FeedbackKind.problem,
|
||||
label: Text('反馈问题和建议'),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: FeedbackKind.development,
|
||||
label: Text('我要参与开发'),
|
||||
),
|
||||
],
|
||||
selected: {_kind},
|
||||
showSelectedIcon: false,
|
||||
onSelectionChanged: _submitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_kind = value.single;
|
||||
_pendingSubmission = null;
|
||||
_error = null;
|
||||
});
|
||||
_form.currentState?.reset();
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_kind == FeedbackKind.problem
|
||||
? '告诉我们哪里需要改进'
|
||||
: '一起让课表变得更好',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
body: AdaptivePage(
|
||||
maxWidth: 760,
|
||||
child: _success
|
||||
? _successView(context)
|
||||
: _uncertain
|
||||
? _uncertainView()
|
||||
: Form(
|
||||
key: _form,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(22),
|
||||
children: [
|
||||
SegmentedButton<FeedbackKind>(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
value: FeedbackKind.problem,
|
||||
label: Text('反馈问题和建议'),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_kind == FeedbackKind.problem
|
||||
? '请描述遇到的问题或你的建议。联系方式和图片、视频都可以选填。'
|
||||
: '请留下你的学校和联系方式,方便开发者与你联系。',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.7,
|
||||
color: ink.withValues(alpha: 0.6),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: FeedbackKind.development,
|
||||
label: Text('我要参与开发'),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
if (_kind == FeedbackKind.problem)
|
||||
TextFormField(
|
||||
key: const Key('feedback-message'),
|
||||
controller: _message,
|
||||
enabled: !_submitting,
|
||||
minLines: 4,
|
||||
maxLines: 8,
|
||||
maxLength: 5000,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '问题或建议(必填)',
|
||||
alignLabelWithHint: true,
|
||||
],
|
||||
selected: {_kind},
|
||||
showSelectedIcon: false,
|
||||
onSelectionChanged: _submitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_kind = value.single;
|
||||
_pendingSubmission = null;
|
||||
_error = null;
|
||||
});
|
||||
_form.currentState?.reset();
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_kind == FeedbackKind.problem
|
||||
? '告诉我们哪里需要改进'
|
||||
: '一起让课表变得更好',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
onChanged: _changed,
|
||||
validator: (value) =>
|
||||
(value?.trim().isEmpty ?? true)
|
||||
? '请填写问题或建议'
|
||||
: null,
|
||||
)
|
||||
else
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_kind == FeedbackKind.problem
|
||||
? '请描述遇到的问题或你的建议。联系方式和图片、视频都可以选填。'
|
||||
: '请留下你的学校和联系方式,方便开发者与你联系。',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.7,
|
||||
color: ink.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
if (_kind == FeedbackKind.problem)
|
||||
TextFormField(
|
||||
key: const Key('feedback-message'),
|
||||
controller: _message,
|
||||
enabled: !_submitting,
|
||||
minLines: 4,
|
||||
maxLines: 8,
|
||||
maxLength: 5000,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '问题或建议(必填)',
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
onChanged: _changed,
|
||||
validator: (value) =>
|
||||
(value?.trim().isEmpty ?? true)
|
||||
? '请填写问题或建议'
|
||||
: null,
|
||||
)
|
||||
else
|
||||
TextFormField(
|
||||
key: const Key('feedback-school'),
|
||||
controller: _school,
|
||||
enabled: !_submitting,
|
||||
maxLength: 200,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '学校(必填)',
|
||||
),
|
||||
onChanged: _changed,
|
||||
validator: (value) =>
|
||||
(value?.trim().isEmpty ?? true)
|
||||
? '请填写学校'
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
TextFormField(
|
||||
key: const Key('feedback-school'),
|
||||
controller: _school,
|
||||
key: const Key('feedback-contact'),
|
||||
controller: _contact,
|
||||
enabled: !_submitting,
|
||||
maxLength: 200,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '学校(必填)',
|
||||
decoration: InputDecoration(
|
||||
labelText: _kind == FeedbackKind.problem
|
||||
? '联系方式(选填)'
|
||||
: '联系方式(必填)',
|
||||
hintText: '微信、QQ、邮箱等',
|
||||
),
|
||||
onChanged: _changed,
|
||||
validator: (value) =>
|
||||
(value?.trim().isEmpty ?? true)
|
||||
? '请填写学校'
|
||||
_kind == FeedbackKind.development &&
|
||||
(value?.trim().isEmpty ?? true)
|
||||
? '请填写联系方式'
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
TextFormField(
|
||||
key: const Key('feedback-contact'),
|
||||
controller: _contact,
|
||||
enabled: !_submitting,
|
||||
maxLength: 200,
|
||||
decoration: InputDecoration(
|
||||
labelText: _kind == FeedbackKind.problem
|
||||
? '联系方式(选填)'
|
||||
: '联系方式(必填)',
|
||||
hintText: '微信、QQ、邮箱等',
|
||||
),
|
||||
onChanged: _changed,
|
||||
validator: (value) =>
|
||||
_kind == FeedbackKind.development &&
|
||||
(value?.trim().isEmpty ?? true)
|
||||
? '请填写联系方式'
|
||||
: null,
|
||||
),
|
||||
if (_kind == FeedbackKind.problem) ...[
|
||||
CheckboxListTile(
|
||||
key: const Key('feedback-logs'),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('附带近10分钟诊断日志'),
|
||||
subtitle: const Text(
|
||||
'包含登录跳转、课表读取及错误状态,帮助排查问题;不包含密码、验证码或课表内容。',
|
||||
),
|
||||
value: _includeLogs,
|
||||
onChanged: _submitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_includeLogs = value ?? false;
|
||||
if (!_includeLogs) _includeHtml = false;
|
||||
_pendingSubmission = null;
|
||||
_error = null;
|
||||
});
|
||||
},
|
||||
),
|
||||
CheckboxListTile(
|
||||
key: const Key('feedback-html'),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('附带最近一次学校导入页面HTML'),
|
||||
subtitle: const Text(
|
||||
'适用于本科和研究生课表、考试导入。需先勾选日志。网页可能含姓名、学号、课程、教师和考场信息,仅保留最近10分钟,单独作为邮件附件发送。',
|
||||
),
|
||||
value: _includeHtml,
|
||||
onChanged: _submitting || !_includeLogs
|
||||
? null
|
||||
: (value) async {
|
||||
var accepted = value ?? false;
|
||||
if (accepted) {
|
||||
accepted =
|
||||
await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('附带网页排查资料?'),
|
||||
content: const Text(
|
||||
'附件可能包含你的姓名、学号、课程及考试信息,将发送给开发者用于排查导入问题。密码、验证码、Cookie和认证参数不会包含在附件中。',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.pop(
|
||||
context,
|
||||
false,
|
||||
),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () =>
|
||||
Navigator.pop(
|
||||
context,
|
||||
true,
|
||||
),
|
||||
child: const Text('同意附带'),
|
||||
),
|
||||
],
|
||||
),
|
||||
) ??
|
||||
false;
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_includeHtml = accepted;
|
||||
_pendingSubmission = null;
|
||||
_error = null;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Text(
|
||||
'图片或视频(选填)',
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'最多 ${widget.limits.maxAttachments} 个,每个 ${_mb(widget.limits.maxFileBytes)} MB,合计 ${_mb(widget.limits.maxTotalBytes)} MB',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: ink.withValues(alpha: 0.55),
|
||||
),
|
||||
),
|
||||
for (var i = 0; i < _attachments.length; i++)
|
||||
ListTile(
|
||||
if (_kind == FeedbackKind.problem) ...[
|
||||
CheckboxListTile(
|
||||
key: const Key('feedback-logs'),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(
|
||||
_attachments[i].contentType.startsWith('image/')
|
||||
? Icons.image_outlined
|
||||
: Icons.videocam_outlined,
|
||||
title: const Text('附带近10分钟诊断日志'),
|
||||
subtitle: const Text(
|
||||
'包含登录跳转、课表读取及错误状态,帮助排查问题;不包含密码、验证码或课表内容。',
|
||||
),
|
||||
title: Text(
|
||||
_attachments[i].filename,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: Text(
|
||||
'${(_attachments[i].size / 1024).toStringAsFixed(1)} KB',
|
||||
),
|
||||
trailing: IconButton(
|
||||
tooltip: '移除 ${_attachments[i].filename}',
|
||||
onPressed: _submitting
|
||||
? null
|
||||
: () => setState(() {
|
||||
_attachments.removeAt(i);
|
||||
value: _includeLogs,
|
||||
onChanged: _submitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_includeLogs = value ?? false;
|
||||
if (!_includeLogs) _includeHtml = false;
|
||||
_pendingSubmission = null;
|
||||
_error = null;
|
||||
}),
|
||||
icon: const Icon(Icons.close_rounded),
|
||||
});
|
||||
},
|
||||
),
|
||||
CheckboxListTile(
|
||||
key: const Key('feedback-html'),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('附带最近一次学校导入页面HTML'),
|
||||
subtitle: const Text(
|
||||
'适用于本科和研究生课表、考试导入。需先勾选日志。网页可能含姓名、学号、课程、教师和考场信息,仅保留最近10分钟,单独作为邮件附件发送。',
|
||||
),
|
||||
value: _includeHtml,
|
||||
onChanged: _submitting || !_includeLogs
|
||||
? null
|
||||
: (value) async {
|
||||
var accepted = value ?? false;
|
||||
if (accepted) {
|
||||
accepted =
|
||||
await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('附带网页排查资料?'),
|
||||
content: const Text(
|
||||
'附件可能包含你的姓名、学号、课程及考试信息,将发送给开发者用于排查导入问题。密码、验证码、Cookie和认证参数不会包含在附件中。',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.pop(
|
||||
context,
|
||||
false,
|
||||
),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () =>
|
||||
Navigator.pop(
|
||||
context,
|
||||
true,
|
||||
),
|
||||
child: const Text('同意附带'),
|
||||
),
|
||||
],
|
||||
),
|
||||
) ??
|
||||
false;
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_includeHtml = accepted;
|
||||
_pendingSubmission = null;
|
||||
_error = null;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Text(
|
||||
'图片或视频(选填)',
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'最多 ${widget.limits.maxAttachments} 个,每个 ${_mb(widget.limits.maxFileBytes)} MB,合计 ${_mb(widget.limits.maxTotalBytes)} MB',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: ink.withValues(alpha: 0.55),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
OutlinedButton.icon(
|
||||
key: const Key('feedback-add-media'),
|
||||
onPressed: _submitting || _picking
|
||||
? null
|
||||
: _addAttachment,
|
||||
icon: const Icon(Icons.attach_file_rounded),
|
||||
label: Text(_picking ? '正在读取附件…' : '添加图片或视频'),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (_error != null) ...[
|
||||
Text(
|
||||
_error!,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
semanticsLabel: _error,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
],
|
||||
FilledButton(
|
||||
key: const Key('feedback-submit'),
|
||||
onPressed: _submitting || _picking ? null : _submit,
|
||||
child: _submitting
|
||||
? const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
for (var i = 0; i < _attachments.length; i++)
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(
|
||||
_attachments[i].contentType.startsWith(
|
||||
'image/',
|
||||
)
|
||||
? Icons.image_outlined
|
||||
: Icons.videocam_outlined,
|
||||
),
|
||||
title: Text(
|
||||
_attachments[i].filename,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: Text(
|
||||
'${(_attachments[i].size / 1024).toStringAsFixed(1)} KB',
|
||||
),
|
||||
trailing: IconButton(
|
||||
tooltip: '移除 ${_attachments[i].filename}',
|
||||
onPressed: _submitting
|
||||
? null
|
||||
: () => setState(() {
|
||||
_attachments.removeAt(i);
|
||||
_pendingSubmission = null;
|
||||
_error = null;
|
||||
}),
|
||||
icon: const Icon(Icons.close_rounded),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
Text('正在提交…'),
|
||||
],
|
||||
)
|
||||
: const Text('提交'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'点击提交后,仅发送你在当前类型填写的内容和选择的附件。',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.6,
|
||||
color: ink.withValues(alpha: 0.5),
|
||||
const SizedBox(height: 8),
|
||||
OutlinedButton.icon(
|
||||
key: const Key('feedback-add-media'),
|
||||
onPressed: _submitting || _picking
|
||||
? null
|
||||
: _addAttachment,
|
||||
icon: const Icon(Icons.attach_file_rounded),
|
||||
label: Text(_picking ? '正在读取附件…' : '添加图片或视频'),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
if (_error != null) ...[
|
||||
Text(
|
||||
_error!,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
semanticsLabel: _error,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
],
|
||||
FilledButton(
|
||||
key: const Key('feedback-submit'),
|
||||
onPressed: _submitting || _picking ? null : _submit,
|
||||
child: _submitting
|
||||
? const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
Text('正在提交…'),
|
||||
],
|
||||
)
|
||||
: const Text('提交'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'点击提交后,仅发送你在当前类型填写的内容和选择的附件。',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.6,
|
||||
color: ink.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import '../../domain/app_settings.dart';
|
||||
import '../../domain/semester.dart';
|
||||
import '../../services/notification_service.dart';
|
||||
import 'reminder_tools.dart';
|
||||
import '../../widgets/adaptive_page.dart';
|
||||
|
||||
class SettingsPage extends StatefulWidget {
|
||||
const SettingsPage({
|
||||
@@ -146,362 +147,378 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
style: TextStyle(fontSize: 21, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
body: ListView(
|
||||
controller: _scroll,
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 40),
|
||||
children: [
|
||||
if (c.isDemo)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(bottom: 18),
|
||||
child: Text(
|
||||
'示例模式中,提醒与日历功能不会应用到示例课程。',
|
||||
style: TextStyle(fontSize: 12, color: river),
|
||||
),
|
||||
),
|
||||
_heading('课表配色'),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
label: const Text('多彩'),
|
||||
selected: s.colorMode == ColorMode.multicolor,
|
||||
onSelected: (_) => c.updateSettings(
|
||||
(current) =>
|
||||
current.copyWith(colorMode: ColorMode.multicolor),
|
||||
),
|
||||
),
|
||||
ChoiceChip(
|
||||
label: const Text('单色'),
|
||||
selected: s.colorMode == ColorMode.single,
|
||||
onSelected: (_) => c.updateSettings(
|
||||
(current) =>
|
||||
current.copyWith(colorMode: ColorMode.single),
|
||||
),
|
||||
),
|
||||
],
|
||||
body: AdaptivePage(
|
||||
maxWidth: 760,
|
||||
child: ListView(
|
||||
controller: _scroll,
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 40),
|
||||
children: [
|
||||
if (c.isDemo)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(bottom: 18),
|
||||
child: Text(
|
||||
'示例模式中,提醒与日历功能不会应用到示例课程。',
|
||||
style: TextStyle(fontSize: 12, color: river),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Wrap(
|
||||
spacing: 14,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
for (final color in [
|
||||
0xFF348F91,
|
||||
0xFF6E83B1,
|
||||
0xFFB18A6E,
|
||||
0xFF8C789E,
|
||||
])
|
||||
Semantics(
|
||||
label: '选择课表颜色',
|
||||
button: true,
|
||||
child: InkWell(
|
||||
onTap: () => c.updateSettings(
|
||||
(current) => current.copyWith(
|
||||
singleColorArgb: color,
|
||||
colorMode: ColorMode.single,
|
||||
),
|
||||
),
|
||||
_heading('课表配色'),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
label: const Text('多彩'),
|
||||
selected: s.colorMode == ColorMode.multicolor,
|
||||
onSelected: (_) => c.updateSettings(
|
||||
(current) => current.copyWith(
|
||||
colorMode: ColorMode.multicolor,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(color),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: s.singleColorArgb == color
|
||||
? ink
|
||||
: Colors.transparent,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
ChoiceChip(
|
||||
label: const Text('单色'),
|
||||
selected: s.colorMode == ColorMode.single,
|
||||
onSelected: (_) => c.updateSettings(
|
||||
(current) =>
|
||||
current.copyWith(colorMode: ColorMode.single),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Wrap(
|
||||
spacing: 14,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
for (final color in [
|
||||
0xFF348F91,
|
||||
0xFF6E83B1,
|
||||
0xFFB18A6E,
|
||||
0xFF8C789E,
|
||||
])
|
||||
Semantics(
|
||||
label: '选择课表颜色',
|
||||
button: true,
|
||||
child: InkWell(
|
||||
onTap: () => c.updateSettings(
|
||||
(current) => current.copyWith(
|
||||
singleColorArgb: color,
|
||||
colorMode: ColorMode.single,
|
||||
),
|
||||
),
|
||||
child: s.singleColorArgb == color
|
||||
? const Icon(
|
||||
Icons.check_rounded,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
_heading('课程条长度'),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${((_courseHeightDraft ?? s.courseHeightScale) * 100).round()}%',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: river,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _savingHeight
|
||||
? null
|
||||
: () => _saveCourseHeight(
|
||||
AppSettings.defaultCourseHeightScale,
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(color),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: s.singleColorArgb == color
|
||||
? ink
|
||||
: Colors.transparent,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: s.singleColorArgb == color
|
||||
? const Icon(
|
||||
Icons.check_rounded,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
child: const Text('恢复默认'),
|
||||
),
|
||||
],
|
||||
),
|
||||
Slider(
|
||||
key: const Key('course-height-slider'),
|
||||
value: _courseHeightDraft ?? s.courseHeightScale,
|
||||
min: AppSettings.minCourseHeightScale,
|
||||
max: AppSettings.maxCourseHeightScale,
|
||||
divisions: 24,
|
||||
label:
|
||||
'${((_courseHeightDraft ?? s.courseHeightScale) * 100).round()}%',
|
||||
semanticFormatterCallback: (value) =>
|
||||
'${(value * 100).round()}%',
|
||||
onChanged: _savingHeight
|
||||
? null
|
||||
: (value) => setState(() => _courseHeightDraft = value),
|
||||
onChangeEnd: _saveCourseHeight,
|
||||
),
|
||||
const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('较短', style: TextStyle(fontSize: 11)),
|
||||
Text('较长', style: TextStyle(fontSize: 11)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
'统一调整课程条长度,老师和教室始终完整显示。',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.6,
|
||||
color: ink.withValues(alpha: 0.55),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
_heading('课前提醒'),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SwitchListTile.adaptive(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('提醒我去上课', style: TextStyle(fontSize: 15)),
|
||||
value: s.remindersEnabled,
|
||||
onChanged: c.isDemo
|
||||
? null
|
||||
: (v) async {
|
||||
if (v) {
|
||||
await c.enableRemindersFromUserAction();
|
||||
} else {
|
||||
await c.updateSettings(
|
||||
(current) =>
|
||||
current.copyWith(remindersEnabled: false),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 7,
|
||||
children: [
|
||||
for (final minutes in AppSettings.allowedReminderMinutes)
|
||||
FilterChip(
|
||||
label: Text('$minutes 分钟'),
|
||||
selected: s.reminderOffsets.contains(minutes),
|
||||
onSelected: c.isDemo
|
||||
? null
|
||||
: (selected) {
|
||||
if (!selected &&
|
||||
s.reminderOffsets.length == 1) {
|
||||
_notice('请至少保留一个提醒时间');
|
||||
return;
|
||||
}
|
||||
c.updateSettings(
|
||||
(current) => current.copyWith(
|
||||
reminderOffsets: [
|
||||
for (final value
|
||||
in current.reminderOffsets)
|
||||
if (value != minutes) value,
|
||||
if (selected) minutes,
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
c.reminderResult.message.isNotEmpty
|
||||
? c.reminderResult.message
|
||||
: c.reminderResult.status ==
|
||||
ReminderStatus.permissionDenied
|
||||
? '尚未允许通知权限,点击下方按钮开启。'
|
||||
: '可多选提前时间,连续课程按每个选中的时间提醒。',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.6,
|
||||
color: ink.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
if (!c.isDemo && s.remindersEnabled)
|
||||
TextButton(
|
||||
onPressed: c.enableRemindersFromUserAction,
|
||||
child: const Text('允许课前提醒'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
if (!c.isDemo) ReminderTools(controller: c),
|
||||
if (!c.isDemo) const SizedBox(height: 22),
|
||||
_heading('手机日历'),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SwitchListTile.adaptive(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('导入手机日历', style: TextStyle(fontSize: 15)),
|
||||
subtitle: const Text(
|
||||
'按实际上课周次同步,不重复提醒',
|
||||
style: TextStyle(fontSize: 11),
|
||||
),
|
||||
value: s.calendarEnabled,
|
||||
onChanged: c.isDemo ? null : _calendar,
|
||||
),
|
||||
if (c.calendarSyncError != null)
|
||||
Text(
|
||||
c.calendarSyncError!,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFFB45D54),
|
||||
),
|
||||
),
|
||||
if (c.snapshot.calendarCleanupPending)
|
||||
TextButton(
|
||||
onPressed: c.retryCalendarCleanup,
|
||||
child: const Text('重试清理课程日程'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
_heading('学期安排'),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('学期开始日', style: TextStyle(fontSize: 15)),
|
||||
subtitle: Text(
|
||||
_start == null
|
||||
? '请选择学校实际开学日期'
|
||||
: '${_start!.year} 年 ${_start!.month} 月 ${_start!.day} 日',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
trailing: const Icon(
|
||||
Icons.date_range_outlined,
|
||||
color: river,
|
||||
),
|
||||
onTap: () async {
|
||||
final date = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _start ?? c.clock(),
|
||||
firstDate: DateTime(2020),
|
||||
lastDate: DateTime(2040),
|
||||
);
|
||||
if (date != null && mounted) {
|
||||
setState(() => _start = date);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_dateError != null)
|
||||
Text(
|
||||
_dateError!,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFFB45D54),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
key: const Key('semester-weeks'),
|
||||
controller: _weeks,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
LengthLimitingTextInputFormatter(2),
|
||||
],
|
||||
decoration: InputDecoration(
|
||||
labelText: '学期总周数',
|
||||
hintText: '1–30',
|
||||
errorText: _weeksError,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: FilledButton(
|
||||
onPressed: () async {
|
||||
final weeks = int.tryParse(_weeks.text);
|
||||
setState(() {
|
||||
_weeksError = weeks == null || weeks < 1 || weeks > 30
|
||||
? '周数应为 1–30'
|
||||
: null;
|
||||
_dateError = _start == null ? '请先选择学期开始日' : null;
|
||||
});
|
||||
if (_weeksError != null || _dateError != null) return;
|
||||
await c.updateSettings(
|
||||
(current) => current.copyWith(
|
||||
semester: Semester(
|
||||
startDate: _start!,
|
||||
totalWeeks: weeks!,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
_heading('课程条长度'),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${((_courseHeightDraft ?? s.courseHeightScale) * 100).round()}%',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: river,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _savingHeight
|
||||
? null
|
||||
: () => _saveCourseHeight(
|
||||
AppSettings.defaultCourseHeightScale,
|
||||
),
|
||||
child: const Text('恢复默认'),
|
||||
),
|
||||
],
|
||||
),
|
||||
Slider(
|
||||
key: const Key('course-height-slider'),
|
||||
value: _courseHeightDraft ?? s.courseHeightScale,
|
||||
min: AppSettings.minCourseHeightScale,
|
||||
max: AppSettings.maxCourseHeightScale,
|
||||
divisions: 24,
|
||||
label:
|
||||
'${((_courseHeightDraft ?? s.courseHeightScale) * 100).round()}%',
|
||||
semanticFormatterCallback: (value) =>
|
||||
'${(value * 100).round()}%',
|
||||
onChanged: _savingHeight
|
||||
? null
|
||||
: (value) =>
|
||||
setState(() => _courseHeightDraft = value),
|
||||
onChangeEnd: _saveCourseHeight,
|
||||
),
|
||||
const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('较短', style: TextStyle(fontSize: 11)),
|
||||
Text('较长', style: TextStyle(fontSize: 11)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
'统一调整课程条长度,老师和教室始终完整显示。',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.6,
|
||||
color: ink.withValues(alpha: 0.55),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
_heading('课前提醒'),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SwitchListTile.adaptive(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text(
|
||||
'提醒我去上课',
|
||||
style: TextStyle(fontSize: 15),
|
||||
),
|
||||
value: s.remindersEnabled,
|
||||
onChanged: c.isDemo
|
||||
? null
|
||||
: (v) async {
|
||||
if (v) {
|
||||
await c.enableRemindersFromUserAction();
|
||||
} else {
|
||||
await c.updateSettings(
|
||||
(current) =>
|
||||
current.copyWith(remindersEnabled: false),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 7,
|
||||
children: [
|
||||
for (final minutes
|
||||
in AppSettings.allowedReminderMinutes)
|
||||
FilterChip(
|
||||
label: Text('$minutes 分钟'),
|
||||
selected: s.reminderOffsets.contains(minutes),
|
||||
onSelected: c.isDemo
|
||||
? null
|
||||
: (selected) {
|
||||
if (!selected &&
|
||||
s.reminderOffsets.length == 1) {
|
||||
_notice('请至少保留一个提醒时间');
|
||||
return;
|
||||
}
|
||||
c.updateSettings(
|
||||
(current) => current.copyWith(
|
||||
reminderOffsets: [
|
||||
for (final value
|
||||
in current.reminderOffsets)
|
||||
if (value != minutes) value,
|
||||
if (selected) minutes,
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
c.reminderResult.message.isNotEmpty
|
||||
? c.reminderResult.message
|
||||
: c.reminderResult.status ==
|
||||
ReminderStatus.permissionDenied
|
||||
? '尚未允许通知权限,点击下方按钮开启。'
|
||||
: '可多选提前时间,连续课程按每个选中的时间提醒。',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.6,
|
||||
color: ink.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
if (!c.isDemo && s.remindersEnabled)
|
||||
TextButton(
|
||||
onPressed: c.enableRemindersFromUserAction,
|
||||
child: const Text('允许课前提醒'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
if (!c.isDemo) ReminderTools(controller: c),
|
||||
if (!c.isDemo) const SizedBox(height: 22),
|
||||
_heading('手机日历'),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SwitchListTile.adaptive(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text(
|
||||
'导入手机日历',
|
||||
style: TextStyle(fontSize: 15),
|
||||
),
|
||||
subtitle: const Text(
|
||||
'按实际上课周次同步,不重复提醒',
|
||||
style: TextStyle(fontSize: 11),
|
||||
),
|
||||
value: s.calendarEnabled,
|
||||
onChanged: c.isDemo ? null : _calendar,
|
||||
),
|
||||
if (c.calendarSyncError != null)
|
||||
Text(
|
||||
c.calendarSyncError!,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFFB45D54),
|
||||
),
|
||||
),
|
||||
if (c.snapshot.calendarCleanupPending)
|
||||
TextButton(
|
||||
onPressed: c.retryCalendarCleanup,
|
||||
child: const Text('重试清理课程日程'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
_heading('学期安排'),
|
||||
SurfaceCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text(
|
||||
'学期开始日',
|
||||
style: TextStyle(fontSize: 15),
|
||||
),
|
||||
subtitle: Text(
|
||||
_start == null
|
||||
? '请选择学校实际开学日期'
|
||||
: '${_start!.year} 年 ${_start!.month} 月 ${_start!.day} 日',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
trailing: const Icon(
|
||||
Icons.date_range_outlined,
|
||||
color: river,
|
||||
),
|
||||
onTap: () async {
|
||||
final date = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _start ?? c.clock(),
|
||||
firstDate: DateTime(2020),
|
||||
lastDate: DateTime(2040),
|
||||
);
|
||||
if (mounted) {
|
||||
_notice(c.lastError ?? '学期设置已保存');
|
||||
if (date != null && mounted) {
|
||||
setState(() => _start = date);
|
||||
}
|
||||
},
|
||||
child: const Text('保存学期设置'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'开始日所在的周一至周日为第 1 周。开始日前不会生成课程。',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.6,
|
||||
color: ink.withValues(alpha: 0.45),
|
||||
if (_dateError != null)
|
||||
Text(
|
||||
_dateError!,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFFB45D54),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
key: const Key('semester-weeks'),
|
||||
controller: _weeks,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
LengthLimitingTextInputFormatter(2),
|
||||
],
|
||||
decoration: InputDecoration(
|
||||
labelText: '学期总周数',
|
||||
hintText: '1–30',
|
||||
errorText: _weeksError,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: FilledButton(
|
||||
onPressed: () async {
|
||||
final weeks = int.tryParse(_weeks.text);
|
||||
setState(() {
|
||||
_weeksError =
|
||||
weeks == null || weeks < 1 || weeks > 30
|
||||
? '周数应为 1–30'
|
||||
: null;
|
||||
_dateError = _start == null ? '请先选择学期开始日' : null;
|
||||
});
|
||||
if (_weeksError != null || _dateError != null) return;
|
||||
await c.updateSettings(
|
||||
(current) => current.copyWith(
|
||||
semester: Semester(
|
||||
startDate: _start!,
|
||||
totalWeeks: weeks!,
|
||||
),
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
_notice(c.lastError ?? '学期设置已保存');
|
||||
}
|
||||
},
|
||||
child: const Text('保存学期设置'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'开始日所在的周一至周日为第 1 周。开始日前不会生成课程。',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.6,
|
||||
color: ink.withValues(alpha: 0.45),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -53,6 +53,11 @@ class WeekGrid extends StatelessWidget {
|
||||
final scale = scaler.scale(10) / 10;
|
||||
const gutter = 34.0, gap = 16.0;
|
||||
final width = (constraints.maxWidth - gutter) / 7;
|
||||
final spacious = width >= 76;
|
||||
final nameStyle = _nameStyle.copyWith(fontSize: spacious ? 13 : 10.5);
|
||||
final metadataStyle = _metadataStyle.copyWith(
|
||||
fontSize: spacious ? 11.5 : 9.5,
|
||||
);
|
||||
final header = 56.0 * scale.clamp(1, 2.5);
|
||||
final groups = {for (final e in events) e: _group(e)};
|
||||
final defaultStyle = DefaultTextStyle.of(context).style;
|
||||
@@ -84,14 +89,14 @@ class WeekGrid extends StatelessWidget {
|
||||
var entryHeight = 0.0;
|
||||
for (final value in group) {
|
||||
final required =
|
||||
measure(value.course.name, _nameStyle, available, lines: 2) +
|
||||
measure(value.course.teacher, _metadataStyle, available) +
|
||||
measure(value.course.room, _metadataStyle, available) +
|
||||
measure(value.course.name, nameStyle, available, lines: 2) +
|
||||
measure(value.course.teacher, metadataStyle, available) +
|
||||
measure(value.course.room, metadataStyle, available) +
|
||||
21;
|
||||
final periodHeight = group.length > 1
|
||||
? measure(
|
||||
'${value.course.startPeriod}–${value.course.endPeriod}节',
|
||||
_metadataStyle,
|
||||
metadataStyle,
|
||||
available,
|
||||
) +
|
||||
3
|
||||
@@ -101,7 +106,7 @@ class WeekGrid extends StatelessWidget {
|
||||
final first = group.map((v) => v.course.startPeriod).reduce(math.min);
|
||||
final last = group.map((v) => v.course.endPeriod).reduce(math.max);
|
||||
final warning = group.length > 1
|
||||
? measure('冲突列表', _metadataStyle, width - 12) + 8
|
||||
? measure('冲突列表', metadataStyle, width - 12) + 8
|
||||
: 0.0;
|
||||
rowHeight = math.max(
|
||||
rowHeight,
|
||||
@@ -133,8 +138,8 @@ class WeekGrid extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
'${slot.period}',
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
style: TextStyle(
|
||||
fontSize: spacious ? 13 : 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
@@ -143,7 +148,7 @@ class WeekGrid extends StatelessWidget {
|
||||
child: Text(
|
||||
minuteLabel(slot.startMinute),
|
||||
style: TextStyle(
|
||||
fontSize: 8,
|
||||
fontSize: spacious ? 10 : 8,
|
||||
color: ink.withValues(alpha: 0.55),
|
||||
),
|
||||
),
|
||||
@@ -152,7 +157,7 @@ class WeekGrid extends StatelessWidget {
|
||||
child: Text(
|
||||
minuteLabel(slot.endMinute),
|
||||
style: TextStyle(
|
||||
fontSize: 8,
|
||||
fontSize: spacious ? 10 : 8,
|
||||
color: ink.withValues(alpha: 0.4),
|
||||
),
|
||||
),
|
||||
@@ -192,7 +197,7 @@ class WeekGrid extends StatelessWidget {
|
||||
][i],
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontSize: spacious ? 12 : 10,
|
||||
color: active
|
||||
? river
|
||||
: ink.withValues(alpha: 0.6),
|
||||
@@ -211,7 +216,7 @@ class WeekGrid extends StatelessWidget {
|
||||
child: Text(
|
||||
'${date.day}',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontSize: spacious ? 13 : 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: active ? Colors.white : ink,
|
||||
),
|
||||
@@ -258,7 +263,15 @@ class WeekGrid extends StatelessWidget {
|
||||
),
|
||||
for (final e in events)
|
||||
if (groups[e]!.first == e)
|
||||
_block(context, groups[e]!, width, rowHeight, top),
|
||||
_block(
|
||||
context,
|
||||
groups[e]!,
|
||||
width,
|
||||
rowHeight,
|
||||
top,
|
||||
nameStyle,
|
||||
metadataStyle,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -276,6 +289,8 @@ class WeekGrid extends StatelessWidget {
|
||||
double width,
|
||||
double rowHeight,
|
||||
double Function(int) top,
|
||||
TextStyle nameStyle,
|
||||
TextStyle metadataStyle,
|
||||
) {
|
||||
final first = group.map((e) => e.course.startPeriod).reduce(math.min);
|
||||
final last = group.map((e) => e.course.endPeriod).reduce(math.max);
|
||||
@@ -285,7 +300,12 @@ class WeekGrid extends StatelessWidget {
|
||||
width: width - 4,
|
||||
height: (last - first + 1) * rowHeight - 8,
|
||||
child: group.length == 1
|
||||
? _entry(context, group.first)
|
||||
? _entry(
|
||||
context,
|
||||
group.first,
|
||||
nameStyle: nameStyle,
|
||||
metadataStyle: metadataStyle,
|
||||
)
|
||||
: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: river.withValues(alpha: 0.06),
|
||||
@@ -308,7 +328,15 @@ class WeekGrid extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
for (final e in group)
|
||||
Expanded(child: _entry(context, e, inConflict: true)),
|
||||
Expanded(
|
||||
child: _entry(
|
||||
context,
|
||||
e,
|
||||
inConflict: true,
|
||||
nameStyle: nameStyle,
|
||||
metadataStyle: metadataStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -319,6 +347,8 @@ class WeekGrid extends StatelessWidget {
|
||||
BuildContext context,
|
||||
CourseOccurrence e, {
|
||||
bool inConflict = false,
|
||||
required TextStyle nameStyle,
|
||||
required TextStyle metadataStyle,
|
||||
}) => Semantics(
|
||||
label: '${e.course.name},${e.course.teacher},${e.course.room}',
|
||||
button: true,
|
||||
@@ -343,26 +373,24 @@ class WeekGrid extends StatelessWidget {
|
||||
e.course.name,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: _nameStyle,
|
||||
style: nameStyle,
|
||||
),
|
||||
if (inConflict) ...[
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
'${e.course.startPeriod}–${e.course.endPeriod}节',
|
||||
style: _metadataStyle,
|
||||
style: metadataStyle,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
e.course.teacher,
|
||||
style: _metadataStyle.copyWith(
|
||||
color: ink.withValues(alpha: 0.85),
|
||||
),
|
||||
style: metadataStyle.copyWith(color: ink.withValues(alpha: 0.85)),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
e.course.room,
|
||||
style: _metadataStyle.copyWith(color: ink.withValues(alpha: 0.7)),
|
||||
style: metadataStyle.copyWith(color: ink.withValues(alpha: 0.7)),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Fits the current window, retaining child state during split-screen resizing.
|
||||
class AdaptivePage extends StatelessWidget {
|
||||
const AdaptivePage({super.key, required this.child, this.maxWidth = 840});
|
||||
final Widget child;
|
||||
final double maxWidth;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final width = constraints.maxWidth;
|
||||
final contentWidth = width >= 600
|
||||
? math.min(maxWidth, width - 32)
|
||||
: width;
|
||||
return Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: SizedBox(
|
||||
width: contentWidth,
|
||||
height: constraints.maxHeight,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
+254
-197
@@ -19,7 +19,9 @@ class GlassDock extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
||||
static const _width = 264.0, _height = 58.0, _inset = 3.0, _travel = 86.0;
|
||||
static const _height = 58.0, _inset = 3.0;
|
||||
double _width = 264;
|
||||
double get _travel => (_width - _inset * 2) / 3;
|
||||
static const _blue = Color(0xFF007AFF);
|
||||
late final AnimationController _motion = AnimationController.unbounded(
|
||||
vsync: this,
|
||||
@@ -29,9 +31,30 @@ class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
||||
vsync: this,
|
||||
value: 0,
|
||||
);
|
||||
late final AnimationController _tap = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 460),
|
||||
);
|
||||
late final AnimationController _sway = AnimationController.unbounded(
|
||||
vsync: this,
|
||||
);
|
||||
void _swayTo(double target) {
|
||||
if (_reduceMotion) {
|
||||
_sway.value = 0;
|
||||
return;
|
||||
}
|
||||
_sway.animateWith(
|
||||
SpringSimulation(
|
||||
const SpringDescription(mass: 1, stiffness: 220, damping: 18),
|
||||
_sway.value,
|
||||
target,
|
||||
_sway.velocity.clamp(-12, 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _reduceMotion = false;
|
||||
late int _targetIndex;
|
||||
bool _elasticMotion = false;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -58,42 +81,48 @@ class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_reduceMotion = MediaQuery.disableAnimationsOf(context);
|
||||
if (_reduceMotion) {
|
||||
_motion.value = widget.selectedIndex.toDouble();
|
||||
_press.value = 0;
|
||||
_tap.value = 0;
|
||||
_sway.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
double? _drag;
|
||||
double _dragSpeed = 0;
|
||||
double get _position => _drag ?? _motion.value.clamp(-0.12, 2.12);
|
||||
void _moveTo(int index, {bool elastic = false, double velocity = 0}) {
|
||||
void _moveTo(int index, {double velocity = 0}) {
|
||||
_targetIndex = index;
|
||||
_elasticMotion = elastic && !_reduceMotion;
|
||||
if (_reduceMotion) {
|
||||
_motion.value = index.toDouble();
|
||||
return;
|
||||
}
|
||||
if (elastic) {
|
||||
_motion.animateWith(
|
||||
SpringSimulation(
|
||||
const SpringDescription(mass: 1, stiffness: 380, damping: 19),
|
||||
_position,
|
||||
index.toDouble(),
|
||||
velocity.clamp(-8, 8),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
_motion.animateTo(
|
||||
_motion.animateWith(
|
||||
SpringSimulation(
|
||||
const SpringDescription(mass: 1, stiffness: 360, damping: 26),
|
||||
_position,
|
||||
index.toDouble(),
|
||||
duration: const Duration(milliseconds: 320),
|
||||
curve: Curves.easeOutCubic,
|
||||
);
|
||||
}
|
||||
velocity,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _select(int index, {bool elastic = false, double velocity = 0}) {
|
||||
final position = _position;
|
||||
final releaseVelocity = elastic
|
||||
? velocity.clamp(-8.0, 8.0)
|
||||
: _motion.velocity;
|
||||
setState(() => _drag = null);
|
||||
_motion.value = position;
|
||||
_moveTo(index, elastic: elastic, velocity: velocity);
|
||||
_moveTo(index, velocity: releaseVelocity);
|
||||
// Retarget the position spring without resetting an in-flight size pulse.
|
||||
// Restarting that pulse at its peak made the glass edges jump on quick taps.
|
||||
if (!elastic && !_reduceMotion && !_tap.isAnimating) {
|
||||
_tap.forward(from: 0);
|
||||
}
|
||||
_pressTo(0);
|
||||
_swayTo(0);
|
||||
widget.onSelected(index);
|
||||
}
|
||||
|
||||
@@ -103,7 +132,7 @@ class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
||||
// The parent acknowledges onSelected with a rebuild. Restarting here used
|
||||
// to erase the release velocity and start a second spring for the same tab.
|
||||
if (widget.selectedIndex != _targetIndex && _drag == null) {
|
||||
_moveTo(widget.selectedIndex);
|
||||
_moveTo(widget.selectedIndex, velocity: _motion.velocity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +140,8 @@ class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
||||
void dispose() {
|
||||
_motion.dispose();
|
||||
_press.dispose();
|
||||
_tap.dispose();
|
||||
_sway.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -162,194 +193,220 @@ class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
animation: Listenable.merge([_motion, _press]),
|
||||
builder: (context, _) {
|
||||
final press = _pressure;
|
||||
final speed = _reduceMotion
|
||||
? 0.0
|
||||
: (_drag != null
|
||||
? _dragSpeed
|
||||
: _elasticMotion
|
||||
? _motion.velocity
|
||||
: 0.0)
|
||||
.abs();
|
||||
final stretch = (speed / 16).clamp(0.0, 0.14) + press * 0.30;
|
||||
final lensWidth = _travel * (1 + stretch);
|
||||
final lensHeight =
|
||||
(_height - _inset * 2) *
|
||||
(1 + press * 0.31 - (speed / 16).clamp(0.0, 0.07));
|
||||
return SizedBox(
|
||||
width: _width,
|
||||
height: _height,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(40),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0xFF4C6078).withValues(alpha: 0.075),
|
||||
blurRadius: 18,
|
||||
offset: const Offset(0, 6),
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
_width = math.min(
|
||||
constraints.maxWidth,
|
||||
MediaQuery.sizeOf(context).width >= 600 ? 300.0 : 264.0,
|
||||
);
|
||||
return AnimatedBuilder(
|
||||
animation: Listenable.merge([_motion, _press, _tap, _sway]),
|
||||
builder: (context, _) {
|
||||
final press = _pressure;
|
||||
final pulse = _reduceMotion ? 0.0 : math.sin(math.pi * _tap.value);
|
||||
final speed = _reduceMotion
|
||||
? 0.0
|
||||
: (_drag != null ? _dragSpeed : _motion.velocity).abs();
|
||||
final stretch =
|
||||
(speed / 80).clamp(0.0, 0.08) + pulse * 0.10 + press * 0.30;
|
||||
final lensWidth = _travel * (1 + stretch);
|
||||
final lensHeight =
|
||||
(_height - _inset * 2) *
|
||||
(1 +
|
||||
press * 0.31 +
|
||||
pulse * 0.08 -
|
||||
(speed / 180).clamp(0.0, 0.035));
|
||||
// Resize real glass bounds: sampling stays aligned without scaling text.
|
||||
final sway = _reduceMotion ? 0.0 : _sway.value.clamp(-1.2, 1.2);
|
||||
final bodyGrowth = press * 12 + pulse * 3 + sway.abs() * 4;
|
||||
final bodyHeight =
|
||||
_height + press * 5 + pulse * 1.5 - sway.abs() * 0.8;
|
||||
final bodyShift =
|
||||
(_position - 1).clamp(-1.0, 1.0) * press * 2 + sway * 2.5;
|
||||
return SizedBox(
|
||||
width: _width,
|
||||
height: _height,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(40),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0xFF4C6078).withValues(alpha: 0.075),
|
||||
blurRadius: 18,
|
||||
offset: const Offset(0, 6),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Positioned.fill(child: _glass(child: const SizedBox.expand())),
|
||||
Positioned(
|
||||
left: (_inset + _position * _travel - (lensWidth - _travel) / 2)
|
||||
.clamp(1.0, _width - lensWidth - 1),
|
||||
top: (_height - lensHeight) / 2,
|
||||
width: lensWidth,
|
||||
height: lensHeight,
|
||||
child: IgnorePointer(
|
||||
child: _glass(lens: true, child: const SizedBox.expand()),
|
||||
),
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Positioned(
|
||||
left: -bodyGrowth / 2 + bodyShift,
|
||||
top: (_height - bodyHeight) / 2,
|
||||
width: _width + bodyGrowth,
|
||||
height: bodyHeight,
|
||||
child: _glass(child: const SizedBox.expand()),
|
||||
),
|
||||
Positioned(
|
||||
left:
|
||||
(_inset +
|
||||
_position * _travel -
|
||||
(lensWidth - _travel) / 2)
|
||||
.clamp(1.0, _width - lensWidth - 1),
|
||||
top: (_height - lensHeight) / 2,
|
||||
width: lensWidth,
|
||||
height: lensHeight,
|
||||
child: IgnorePointer(
|
||||
child: _glass(lens: true, child: const SizedBox.expand()),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: _inset,
|
||||
right: _inset,
|
||||
top: _inset,
|
||||
bottom: _inset,
|
||||
child: Row(
|
||||
children: [
|
||||
_item(0, Icons.calendar_month_rounded, '课表'),
|
||||
_item(1, Icons.assignment_rounded, '考试'),
|
||||
_item(2, Icons.person_rounded, '个人设置', caption: '我的'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
left: _inset,
|
||||
right: _inset,
|
||||
top: _inset,
|
||||
bottom: _inset,
|
||||
child: Row(
|
||||
children: [
|
||||
_item(0, Icons.calendar_month_rounded, '课表'),
|
||||
_item(1, Icons.assignment_rounded, '考试'),
|
||||
_item(2, Icons.person_rounded, '个人设置', caption: '我的'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
Widget _item(
|
||||
int index,
|
||||
IconData icon,
|
||||
String label, {
|
||||
String? caption,
|
||||
}) => Expanded(
|
||||
child: Semantics(
|
||||
label: label,
|
||||
button: true,
|
||||
selected: index == widget.selectedIndex,
|
||||
excludeSemantics: true,
|
||||
onTap: () => _select(index),
|
||||
child: GestureDetector(
|
||||
key: index == widget.selectedIndex ? const Key('dock-cursor') : null,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTapDown: index == widget.selectedIndex ? (_) => _pressTo(1) : null,
|
||||
onTapCancel: () {
|
||||
if (_drag == null) _pressTo(0);
|
||||
},
|
||||
onTap: () => _select(index),
|
||||
onHorizontalDragStart: index == widget.selectedIndex
|
||||
? (_) {
|
||||
final start = _position.clamp(0.0, 2.0);
|
||||
_motion.stop();
|
||||
_pressTo(1);
|
||||
setState(() {
|
||||
_drag = start;
|
||||
_dragSpeed = 0;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
onHorizontalDragUpdate: index == widget.selectedIndex
|
||||
? (details) => setState(() {
|
||||
_dragSpeed = details.delta.dx / _travel * 60;
|
||||
_drag = (_position + details.delta.dx / _travel).clamp(
|
||||
0.0,
|
||||
2.0,
|
||||
);
|
||||
})
|
||||
: null,
|
||||
onHorizontalDragEnd: index == widget.selectedIndex
|
||||
? (details) => _select(
|
||||
_position.round().clamp(0, 2),
|
||||
elastic: true,
|
||||
velocity: details.velocity.pixelsPerSecond.dx / _travel,
|
||||
)
|
||||
: null,
|
||||
onHorizontalDragCancel: index == widget.selectedIndex
|
||||
? () {
|
||||
if (!mounted) return;
|
||||
final position = _position;
|
||||
setState(() => _drag = null);
|
||||
_motion.value = position;
|
||||
_moveTo(widget.selectedIndex, elastic: true);
|
||||
_pressTo(0);
|
||||
}
|
||||
: null,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AnimatedScale(
|
||||
scale: index == _position.round().clamp(0, 2)
|
||||
? 1 + _pressure * 0.08
|
||||
: 1,
|
||||
duration: const Duration(milliseconds: 130),
|
||||
child: Icon(
|
||||
icon,
|
||||
size: 25,
|
||||
color: index == _position.round().clamp(0, 2)
|
||||
? _blue
|
||||
: _blue.withValues(alpha: 0.72),
|
||||
shadows: [
|
||||
Shadow(
|
||||
color: Colors.white.withValues(
|
||||
alpha: index == _position.round().clamp(0, 2)
|
||||
? 0.60
|
||||
: 0.38,
|
||||
),
|
||||
blurRadius: 8,
|
||||
),
|
||||
Shadow(
|
||||
color: Colors.white.withValues(
|
||||
alpha: index == _position.round().clamp(0, 2)
|
||||
? 0.95
|
||||
: 0.85,
|
||||
),
|
||||
blurRadius: 2.8,
|
||||
),
|
||||
Shadow(
|
||||
color: Colors.white.withValues(
|
||||
alpha: index == _position.round().clamp(0, 2)
|
||||
? 0.34
|
||||
: 0.22,
|
||||
),
|
||||
blurRadius: 1.4,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Flexible(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
caption ?? label,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.1,
|
||||
fontWeight: FontWeight.w600,
|
||||
Widget _item(int index, IconData icon, String label, {String? caption}) =>
|
||||
Expanded(
|
||||
child: Semantics(
|
||||
label: label,
|
||||
button: true,
|
||||
selected: index == widget.selectedIndex,
|
||||
excludeSemantics: true,
|
||||
onTap: () => _select(index),
|
||||
child: GestureDetector(
|
||||
key: index == widget.selectedIndex
|
||||
? const Key('dock-cursor')
|
||||
: null,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTapDown: index == widget.selectedIndex
|
||||
? (_) => _pressTo(_reduceMotion ? 0 : 1)
|
||||
: null,
|
||||
onTapCancel: () {
|
||||
if (_drag == null) _pressTo(0);
|
||||
},
|
||||
onTap: () => _select(index),
|
||||
onHorizontalDragStart: index == widget.selectedIndex
|
||||
? (_) {
|
||||
final start = _position.clamp(0.0, 2.0);
|
||||
_motion.stop();
|
||||
_pressTo(_reduceMotion ? 0 : 1);
|
||||
setState(() {
|
||||
_drag = start;
|
||||
_dragSpeed = 0;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
onHorizontalDragUpdate: index == widget.selectedIndex
|
||||
? (details) => setState(() {
|
||||
_dragSpeed = details.delta.dx / _travel * 60;
|
||||
_swayTo((_dragSpeed / 8).clamp(-1.0, 1.0));
|
||||
_drag = (_position + details.delta.dx / _travel).clamp(
|
||||
0.0,
|
||||
2.0,
|
||||
);
|
||||
})
|
||||
: null,
|
||||
onHorizontalDragEnd: index == widget.selectedIndex
|
||||
? (details) => _select(
|
||||
_position.round().clamp(0, 2),
|
||||
elastic: true,
|
||||
velocity: details.velocity.pixelsPerSecond.dx / _travel,
|
||||
)
|
||||
: null,
|
||||
onHorizontalDragCancel: index == widget.selectedIndex
|
||||
? () {
|
||||
if (!mounted) return;
|
||||
final position = _position;
|
||||
setState(() => _drag = null);
|
||||
_motion.value = position;
|
||||
_moveTo(widget.selectedIndex);
|
||||
_pressTo(0);
|
||||
_swayTo(0);
|
||||
}
|
||||
: null,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AnimatedScale(
|
||||
scale: index == _position.round().clamp(0, 2)
|
||||
? 1 + _pressure * 0.08
|
||||
: 1,
|
||||
duration: const Duration(milliseconds: 130),
|
||||
child: Icon(
|
||||
icon,
|
||||
size: 25,
|
||||
color: index == _position.round().clamp(0, 2)
|
||||
? _blue
|
||||
: _blue.withValues(alpha: 0.62),
|
||||
: _blue.withValues(alpha: 0.72),
|
||||
shadows: [
|
||||
Shadow(
|
||||
color: Colors.white.withValues(
|
||||
alpha: index == _position.round().clamp(0, 2)
|
||||
? 0.60
|
||||
: 0.38,
|
||||
),
|
||||
blurRadius: 8,
|
||||
),
|
||||
Shadow(
|
||||
color: Colors.white.withValues(
|
||||
alpha: index == _position.round().clamp(0, 2)
|
||||
? 0.95
|
||||
: 0.85,
|
||||
),
|
||||
blurRadius: 2.8,
|
||||
),
|
||||
Shadow(
|
||||
color: Colors.white.withValues(
|
||||
alpha: index == _position.round().clamp(0, 2)
|
||||
? 0.34
|
||||
: 0.22,
|
||||
),
|
||||
blurRadius: 1.4,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Flexible(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
caption ?? label,
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.1,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: index == _position.round().clamp(0, 2)
|
||||
? _blue
|
||||
: _blue.withValues(alpha: 0.62),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/// A white, rounded bevel catches light around a translucent milky body.
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
name: hepan_everyday
|
||||
description: TPSchedule 学生课表
|
||||
publish_to: none
|
||||
version: 0.7.8+28
|
||||
version: 0.7.8+29
|
||||
environment:
|
||||
sdk: ^3.13.5
|
||||
dependencies:
|
||||
|
||||
@@ -25,7 +25,7 @@ void main() {
|
||||
await gesture.cancel();
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
testWidgets('tap cursor travels monotonically with no size jitter', (
|
||||
testWidgets('tap has bounded elastic stretch and settles on the new icon', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_dock());
|
||||
@@ -35,17 +35,123 @@ void main() {
|
||||
final target = tester.getCenter(find.byIcon(Icons.assignment_rounded)).dx;
|
||||
await tester.tap(find.byIcon(Icons.assignment_rounded));
|
||||
await tester.pump();
|
||||
var previous = resting.center.dx;
|
||||
for (var frame = 0; frame < 50; frame++) {
|
||||
var widest = resting.width;
|
||||
var furthest = resting.center.dx;
|
||||
for (var frame = 0; frame < 70; frame++) {
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
final rect = tester.getRect(lens);
|
||||
expect(rect.width, closeTo(resting.width, 0.05));
|
||||
expect(rect.height, closeTo(resting.height, 0.05));
|
||||
expect(rect.center.dx, greaterThanOrEqualTo(previous - 0.05));
|
||||
expect(rect.center.dx, lessThanOrEqualTo(target + 0.05));
|
||||
previous = rect.center.dx;
|
||||
widest = widest > rect.width ? widest : rect.width;
|
||||
furthest = furthest > rect.center.dx ? furthest : rect.center.dx;
|
||||
expect(rect.width, lessThan(resting.width * 1.4));
|
||||
expect(rect.center.dx, lessThan(target + 8));
|
||||
}
|
||||
expect(previous, closeTo(target, 0.05));
|
||||
expect(widest, greaterThan(resting.width * 1.06));
|
||||
expect(furthest, greaterThan(target + 0.1));
|
||||
expect(tester.getCenter(lens).dx, closeTo(target, 0.1));
|
||||
expect(tester.getSize(lens).width, closeTo(resting.width, 0.1));
|
||||
});
|
||||
testWidgets('drag deforms the dock body while labels remain readable', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_dock());
|
||||
await tester.pumpAndSettle();
|
||||
final body = find.byType(GlassRefraction).first;
|
||||
final resting = tester.getRect(body);
|
||||
final labelSize = tester.getSize(find.text('考试'));
|
||||
final gesture = await tester.startGesture(
|
||||
tester.getCenter(find.byKey(const Key('dock-cursor'))),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 180));
|
||||
await gesture.moveBy(const Offset(75, 0));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 150));
|
||||
expect(tester.getSize(body).width, greaterThan(resting.width + 5));
|
||||
expect(tester.getSize(body).height, greaterThan(resting.height + 2));
|
||||
expect(tester.getSize(find.text('考试')), labelSize);
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(body), resting.size);
|
||||
});
|
||||
testWidgets(
|
||||
'rapid reverse taps keep position continuous and finish on last tab',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(_dock());
|
||||
await tester.pumpAndSettle();
|
||||
final lens = find.byType(GlassRefraction).last;
|
||||
await tester.tap(find.byIcon(Icons.person_rounded));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 90));
|
||||
final before = tester.getCenter(lens);
|
||||
final beforeSize = tester.getSize(lens);
|
||||
await tester.tap(find.byIcon(Icons.calendar_month_rounded));
|
||||
await tester.pump();
|
||||
expect((tester.getCenter(lens) - before).distance, lessThan(1));
|
||||
expect(tester.getSize(lens).width, closeTo(beforeSize.width, 0.1));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getCenter(lens).dx,
|
||||
closeTo(
|
||||
tester.getCenter(find.byIcon(Icons.calendar_month_rounded)).dx,
|
||||
0.1,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
testWidgets('reversing a tap at the edge preserves glass size and position', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_dock());
|
||||
await tester.pumpAndSettle();
|
||||
final lens = find.byType(GlassRefraction).last;
|
||||
final body = find.byType(GlassRefraction).first;
|
||||
await tester.tap(find.byIcon(Icons.person_rounded));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 230));
|
||||
final before = tester.getRect(lens);
|
||||
final bodyBefore = tester.getRect(body);
|
||||
await tester.tap(find.byIcon(Icons.calendar_month_rounded));
|
||||
await tester.pump();
|
||||
final after = tester.getRect(lens);
|
||||
expect(after.width, closeTo(before.width, 0.1));
|
||||
expect(after.height, closeTo(before.height, 0.1));
|
||||
expect(after.center.dx, closeTo(before.center.dx, 0.1));
|
||||
expect(tester.getSize(body).width, closeTo(bodyBefore.width, 0.1));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getCenter(lens).dx,
|
||||
closeTo(
|
||||
tester.getCenter(find.byIcon(Icons.calendar_month_rounded)).dx,
|
||||
0.1,
|
||||
),
|
||||
);
|
||||
});
|
||||
testWidgets('dock body follows a moving drag and springs back on cancel', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_dock());
|
||||
await tester.pumpAndSettle();
|
||||
final body = find.byType(GlassRefraction).first;
|
||||
final resting = tester.getRect(body);
|
||||
final gesture = await tester.startGesture(
|
||||
tester.getCenter(find.byKey(const Key('dock-cursor'))),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 110));
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
await gesture.moveBy(const Offset(24, 0));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
final held = tester.getRect(body);
|
||||
await gesture.moveBy(const Offset(60, 0));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
expect(tester.getSize(body).width, greaterThan(held.width + 0.5));
|
||||
await gesture.cancel();
|
||||
await tester.pumpAndSettle();
|
||||
final settled = tester.getRect(body);
|
||||
expect(settled.left, closeTo(resting.left, 0.05));
|
||||
expect(settled.top, closeTo(resting.top, 0.05));
|
||||
expect(settled.width, closeTo(resting.width, 0.05));
|
||||
expect(settled.height, closeTo(resting.height, 0.05));
|
||||
});
|
||||
testWidgets('base and selected cursor both refract the live backdrop', (
|
||||
tester,
|
||||
@@ -75,6 +181,44 @@ void main() {
|
||||
expect(tester.getCenter(lens).dx, closeTo(target, 0.05));
|
||||
expect(tester.getSize(lens), resting);
|
||||
});
|
||||
testWidgets(
|
||||
'changing reduced motion during a tap does not leave frozen deformation',
|
||||
(tester) async {
|
||||
final reduced = ValueNotifier(false);
|
||||
var selected = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) => ValueListenableBuilder<bool>(
|
||||
valueListenable: reduced,
|
||||
builder: (context, value, _) => MediaQuery(
|
||||
data: MediaQueryData(disableAnimations: value),
|
||||
child: Center(
|
||||
child: GlassDock(
|
||||
selectedIndex: selected,
|
||||
onSelected: (index) => setState(() => selected = index),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final lens = find.byType(GlassRefraction).last;
|
||||
final size = tester.getSize(lens);
|
||||
await tester.tap(find.byIcon(Icons.assignment_rounded));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 120));
|
||||
reduced.value = true;
|
||||
await tester.pump();
|
||||
reduced.value = false;
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(lens).width, closeTo(size.width, 0.05));
|
||||
expect(tester.getSize(lens).height, closeTo(size.height, 0.05));
|
||||
reduced.dispose();
|
||||
},
|
||||
);
|
||||
testWidgets('held cursor enlarges before dragging and returns on release', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:timezone/data/latest.dart' as tzdata;
|
||||
import 'package:hepan_everyday/app/hepan_app.dart';
|
||||
import 'package:hepan_everyday/features/timetable/week_grid.dart';
|
||||
import 'package:hepan_everyday/features/exams/exams_page.dart';
|
||||
import 'package:hepan_everyday/features/profile/profile_page.dart';
|
||||
import 'package:hepan_everyday/widgets/glass_dock.dart';
|
||||
import 'package:hepan_everyday/features/profile/settings_page.dart';
|
||||
import 'package:hepan_everyday/features/feedback/feedback_page.dart';
|
||||
|
||||
import 'navigation_test.dart' show uiController;
|
||||
|
||||
void main() {
|
||||
setUpAll(tzdata.initializeTimeZones);
|
||||
for (final size in [const Size(800, 1280), const Size(1280, 800)]) {
|
||||
testWidgets('tablet $size fits seven days and limits reading width', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.view.physicalSize = size;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final controller = uiController();
|
||||
await controller.initialize();
|
||||
await controller.showDemo();
|
||||
await tester.pumpWidget(HepanApp(controller: controller));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(tester.getRect(find.text('周一')).left, greaterThan(0));
|
||||
expect(tester.getRect(find.text('周日')).right, lessThan(size.width));
|
||||
final monday = tester.widget<Text>(find.text('周一'));
|
||||
expect(monday.style!.fontSize, greaterThanOrEqualTo(12));
|
||||
expect(tester.getSize(find.byType(GlassDock)).width, 300);
|
||||
expect(tester.getSize(find.byType(GlassDock)).height, 58);
|
||||
await tester.drag(find.text('周三'), const Offset(-160, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('第 2 周'), findsOneWidget);
|
||||
await tester.tap(find.byIcon(Icons.assignment_rounded));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getSize(find.byType(ExamsPage)).width,
|
||||
lessThanOrEqualTo(840),
|
||||
);
|
||||
await tester.tap(find.byIcon(Icons.person_rounded));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getSize(find.byType(ProfilePage)).width,
|
||||
lessThanOrEqualTo(840),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.tap(find.byIcon(Icons.calendar_month_rounded));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('第 2 周'), findsOneWidget);
|
||||
tester.view.physicalSize = const Size(480, 800);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(find.byType(GlassDock)).width, 264);
|
||||
expect(find.text('第 2 周'), findsOneWidget);
|
||||
expect(
|
||||
tester.getRect(find.byType(WeekGrid)).right,
|
||||
lessThanOrEqualTo(480),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
controller.dispose();
|
||||
});
|
||||
}
|
||||
testWidgets(
|
||||
'wide settings and feedback remain centered and usable with large text',
|
||||
(tester) async {
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.view.physicalSize = const Size(1280, 800);
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final controller = uiController();
|
||||
await controller.initialize();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
size: Size(1280, 800),
|
||||
textScaler: TextScaler.linear(1.5),
|
||||
),
|
||||
child: SettingsPage(controller: controller),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(find.byType(ListView)).width, 760);
|
||||
expect(tester.getRect(find.byType(ListView)).center.dx, 640);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
size: Size(1280, 800),
|
||||
textScaler: TextScaler.linear(1.5),
|
||||
),
|
||||
child: const FeedbackPage(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(find.byType(ListView)).width, 760);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.enterText(find.byKey(const Key('feedback-message')), '平板反馈');
|
||||
expect(find.text('平板反馈'), findsOneWidget);
|
||||
controller.dispose();
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -45,7 +45,8 @@ void main() {
|
||||
final a = tester.getRect(find.bySemanticsLabel('A,T,R'));
|
||||
final b = tester.getRect(find.bySemanticsLabel('B,T,R'));
|
||||
final cRect = tester.getRect(find.bySemanticsLabel('C,T,R'));
|
||||
expect(a.overlaps(b), isFalse);
|
||||
expect(b.overlaps(cRect), isFalse);
|
||||
// Fractional Expanded heights can differ by floating-point epsilon.
|
||||
expect(b.top, greaterThanOrEqualTo(a.bottom - 0.001));
|
||||
expect(cRect.top, greaterThanOrEqualTo(b.bottom - 0.001));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user