修复:日期录入收口共享层——「今天」快捷键 + 品牌配色 datePickerTheme(M3.5-02)

用户实测已因日期选择器误录:Flutter 原生日历只给年份网格、月份必须靠 < >
逐月点,从 9 月回 4 月要点 5 次,他把当月(2026-09)的就医记录记成了
2026-04-09,进而误判「本月花费 ¥0」是聚合坏了。

新增 lib/core/widgets/app_date_picker.dart,全仓 7 处裸 showDatePicker 收口
(改造后 lib/ 下 showDatePicker 只出现在该文件内部一次):

- pickAppDate(...):calendar 首屏 + 保留头部铅笔切手输;initialDate 自动夹进
  [firstDate, lastDate] 防原生越界断言(调用方常传「当前值 ?? 今天」,而
  「到期日期」的 firstDate 就是今天,历史值可能已越界);返回值统一抹时分秒;
  中文文案一律交给 zh-CN 本地化,不硬编码,避免两处文案漂移。
- AppDateFieldTrailing(...):7 处日期行统一「今天 + 日历图标」。今天越界自动
  隐藏按钮、提交中禁用、触控 44×44、primaryStrong 白底 4.49:1。

入口模式取舍:不用 calendarOnly——它恰好会砍掉手输按钮,把「录一个已知日期」
这条唯一快路堵死;也不用 input 首屏——「记今天」这类高频场景敲 8 个数字更慢。
两条路都留着最省事。

「今天」为何放表单行而非弹窗内:原生 showDatePicker 无法注入自定义动作
(builder 只能包裹整个 Dialog,拿不到内部选中态;塞进 Column 还会因 Dialog
在无界高度下贪心布局而溢出)。放表单行反而更快——一键落值连弹窗都不用开,
把容易走错的月份导航整段绕开,且一次实现 7 处形态完全一致。

各调用点原有的 firstDate/lastDate 业务约束原样传入、一字未改(健康事件
不许未来、到期日不许补记过去、疫苗 allowFuture 双态、生日不许未来),
并由 widget 测试直接断言 DatePickerDialog.firstDate/lastDate 防后续悄悄放宽。

顺带修配色:此前从未定制 datePickerTheme,选中日直接吃 ColorScheme.fromSeed
由珊瑚橙派生的暗红棕,与品牌脱节。新增 _datePickerTheme 只复用 05 号规范
(iteration-2/05、iteration-3/05)已审计的色对,不新造色值:头部
surfaceTint + primaryDark 7.98:1(选中 chip 同款)、选中日/年 primaryStrong
实底白字 4.49:1、今日 primaryStrong 1.5px 描边、星期表头 inkSoft 6.59:1、
越界日 muted(DEBT-2 允许的禁用态用途)。headerHeadlineStyle 取 22px
(默认 32):中文「9月10日周四」在横屏侧栏头部 26px 起就折行。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-10 17:59:52 +08:00
parent 6038901099
commit 294fc4a781
12 changed files with 824 additions and 23 deletions
@@ -1,7 +1,11 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:patbond_flutter/app/app_localization.dart';
import 'package:patbond_flutter/core/network/api_exception.dart';
import 'package:patbond_flutter/core/theme/app_theme.dart';
import 'package:patbond_flutter/core/widgets/app_date_picker.dart';
import 'package:patbond_flutter/features/pets/health_event_form_page.dart';
import 'package:patbond_flutter/features/pets/health_record_analytics.dart';
import 'package:patbond_flutter/features/pets/pet_exceptions.dart';
@@ -34,6 +38,11 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: buildAppTheme(),
// M3.5-01:与生产一致挂 zh-CN delegate,否则测里的日期选择器是
// 英文兜底,测不出用户真机看到的东西。
localizationsDelegates: appLocalizationsDelegates,
supportedLocales: appSupportedLocales,
locale: appLocale,
home: Builder(
builder: (context) => Scaffold(
body: Center(
@@ -192,4 +201,77 @@ void main() {
expect(failed[2]!['failureReason'], 'network_error');
expect(failed[2]!['attemptSeq'], 3);
});
group('M3.5-02 · 日期录入(用户误录 2026-04 的那一格)', () {
testWidgets('点「今天」直接落今天,不开弹窗;同时算首次输入触发 started', (tester) async {
await pumpForm(tester);
final expected = dateToJson(DateTime.now());
// 先把日期改成远月,模拟用户翻错月份后的状态。
await tester.tap(find.widgetWithText(ListTile, '发生日期'));
await tester.pumpAndSettle();
await tester.tap(find.byIcon(Icons.edit_outlined));
await tester.pumpAndSettle();
await tester.enterText(
find.descendant(
of: find.byType(DatePickerDialog),
matching: find.byType(TextField),
),
'2026/04/09',
);
await tester.pumpAndSettle();
await tester.tap(find.text('确定'));
await tester.pumpAndSettle();
expect(find.text('2026-04-09'), findsOneWidget);
// 一键回今天:不经日期选择器。
await tester.tap(find.text('今天'));
await tester.pumpAndSettle();
expect(find.text(expected), findsOneWidget);
expect(find.text('选择日期'), findsNothing);
expect(eventsOf('health_record_create_started'), hasLength(1));
});
testWidgets('选择器为中文,且业务约束不变(firstDate 1990 / lastDate 今天,不许未来)', (
tester,
) async {
await pumpForm(tester);
await tester.tap(find.widgetWithText(ListTile, '发生日期'));
await tester.pumpAndSettle();
expect(find.text('选择日期'), findsOneWidget);
expect(find.text('确定'), findsOneWidget);
expect(find.text('取消'), findsOneWidget);
// 手输快路可达(原生 calendarOnly 会砍掉它)。
expect(find.byIcon(Icons.edit_outlined), findsOneWidget);
final dialog = tester.widget<DatePickerDialog>(
find.byType(DatePickerDialog),
);
expect(dialog.firstDate, DateTime(1990));
expect(dialog.lastDate, dateOnly(DateTime.now()));
});
testWidgets('提交中禁用「今天」快捷键', (tester) async {
final gate = Completer<HealthEvent>();
repository.createHealthEventHandler = (petId, req) => gate.future;
await pumpForm(tester);
await fillValid(tester);
await tester.tap(find.text('保存记录'));
await tester.pump();
expect(
tester
.widget<TextButton>(find.widgetWithText(TextButton, '今天'))
.onPressed,
isNull,
);
gate.complete(buildHealthEvent('he-1'));
await tester.pumpAndSettle();
});
});
}