Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a48433f01d | ||
|
|
f2ae0c70b6 | ||
|
|
57f3029018 |
No files matched your search
@@ -0,0 +1,20 @@
|
||||
# 收藏卡片简介
|
||||
|
||||
## 目标
|
||||
|
||||
- 收藏卡片在标题/标签下方显示后端 `synopsis`,最多 2 行并省略溢出。
|
||||
- 空白简介不创建文本节点、不占高度,不显示 `null/undefined`。
|
||||
- 保持封面 80x106 和现有卡片高度,不引入布局溢出。
|
||||
|
||||
## 实现
|
||||
|
||||
1. `_FavoriteCard` 对 synopsis 做 trim 后条件渲染。
|
||||
2. 简介使用 `Flexible` 占据标题、标签与底部统计之间的剩余空间,
|
||||
`maxLines: 2`、`TextOverflow.ellipsis`、次要文案色和字号。
|
||||
3. 无简介时继续使用原 Spacer,保持原布局。
|
||||
4. widget 测试覆盖有简介、空简介和卡片高度稳定性。
|
||||
|
||||
## 约束
|
||||
|
||||
- 不改接口、后端、收藏分页。
|
||||
- 不新增依赖,不提交现有 `pubspec.lock`,不启停服务、不操作真机。
|
||||
@@ -698,3 +698,35 @@ $ flutter test --no-pub
|
||||
解读:有 dramaTitle 时不触发详情请求、点击时才加载详情、空标题兜底、
|
||||
第 2 页追加去重和 hasMore 行为均通过;全量分析零告警,630 项通过、1 项旧服务
|
||||
能力探测跳过。`pubspec.lock` 既有改动未提交。
|
||||
|
||||
## 2026-10-22 收藏卡片简介
|
||||
|
||||
- 分支:`feature/favorite-card-synopsis`
|
||||
- 基线:`develop` / `origin/develop` = `9093700`
|
||||
- 计划:`docs/plans/2026-10-22-favorite-card-synopsis.md`
|
||||
|
||||
### 实现
|
||||
|
||||
- `_FavoriteCard` 在标题/标签下方条件渲染 `drama.synopsis.trim()`。
|
||||
- 简介最多 2 行、`TextOverflow.ellipsis`,使用 `AppColors.muted`、12 号字和
|
||||
`1.15` 行高,由 `Flexible` 占据剩余空间,保持封面与卡片原高度。
|
||||
- 简介为空或纯空白时不创建文本节点,继续使用原 Spacer,不占高度。
|
||||
- 未改接口、后端和收藏分页逻辑。
|
||||
|
||||
### 门禁
|
||||
|
||||
```text
|
||||
$ flutter test --no-pub test/library/favorites_page_test.dart
|
||||
00:01 +7: All tests passed!
|
||||
|
||||
$ dart analyze lib test
|
||||
Analyzing lib, test...
|
||||
No issues found!
|
||||
|
||||
$ flutter test --no-pub
|
||||
00:51 +631 ~1: All tests passed!
|
||||
```
|
||||
|
||||
解读:有简介时文本最多 2 行并省略,空简介不渲染且卡片高度与正常卡片一致;
|
||||
全量静态分析零告警,631 项通过、1 项运行中旧后端能力探测跳过。
|
||||
`pubspec.lock` 既有改动未提交。
|
||||
@@ -3,6 +3,8 @@
|
||||
import 'json_numbers.dart';
|
||||
|
||||
/// 服务端标准分页响应 `{total, list}`。
|
||||
///
|
||||
/// 兼容旧版「data 直接是数组」的响应:按数组长度作为 total,避免列表空白。
|
||||
class PageResult<T> {
|
||||
const PageResult({this.total = 0, this.list = const []});
|
||||
|
||||
@@ -14,10 +16,32 @@ class PageResult<T> {
|
||||
Map<String, dynamic> json,
|
||||
T Function(Map<String, dynamic>) parseItem,
|
||||
) {
|
||||
final items = (json['list'] as List? ?? const [])
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(parseItem)
|
||||
.toList(growable: false);
|
||||
final items = _parseItemMaps(json['list']).map(parseItem).toList(
|
||||
growable: false,
|
||||
);
|
||||
return PageResult(total: jsonToInt(json['total']), list: items);
|
||||
}
|
||||
|
||||
/// 兼容分页 Map 与旧版纯 List;其它类型视为空页。
|
||||
factory PageResult.parse(
|
||||
Object? data,
|
||||
T Function(Map<String, dynamic>) parseItem,
|
||||
) {
|
||||
if (data is Map) {
|
||||
return PageResult.fromJson(Map<String, dynamic>.from(data), parseItem);
|
||||
}
|
||||
if (data is List) {
|
||||
final items = _parseItemMaps(data).map(parseItem).toList(growable: false);
|
||||
return PageResult(total: items.length, list: items);
|
||||
}
|
||||
return PageResult<T>();
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> _parseItemMaps(Object? raw) {
|
||||
if (raw is! List) return const [];
|
||||
return [
|
||||
for (final item in raw)
|
||||
if (item is Map) Map<String, dynamic>.from(item),
|
||||
];
|
||||
}
|
||||
@@ -29,10 +29,8 @@ class LibraryApi {
|
||||
'/app/favorites',
|
||||
query: {'pageIndex': '$pageIndex', 'pageSize': '$pageSize'},
|
||||
);
|
||||
if (data is Map<String, dynamic>) {
|
||||
return PageResult.fromJson(data, Drama.fromCardJson);
|
||||
}
|
||||
return const PageResult();
|
||||
// 线上可能仍返回 List;分页壳与纯数组都要能渲染。
|
||||
return PageResult.parse(data, Drama.fromCardJson);
|
||||
}
|
||||
|
||||
Future<void> removeFavorite(String dramaId) async {
|
||||
|
||||
@@ -49,10 +49,8 @@ class WatchApi {
|
||||
'/app/watch/recent',
|
||||
query: {'pageIndex': '$pageIndex', 'pageSize': '$pageSize'},
|
||||
);
|
||||
if (data is Map<String, dynamic>) {
|
||||
return PageResult.fromJson(data, WatchProgress.fromJson);
|
||||
}
|
||||
return const PageResult();
|
||||
// 线上可能仍返回 List;分页壳与纯数组都要能渲染。
|
||||
return PageResult.parse(data, WatchProgress.fromJson);
|
||||
}
|
||||
|
||||
/// 删除某部剧的观看记录(记录页清单条用)。
|
||||
|
||||
@@ -34,6 +34,9 @@ const double _removeIconSize = 20;
|
||||
const double _statsFontSize = 12;
|
||||
const double _metaFontSize = 11;
|
||||
const double _titleFontSize = 15;
|
||||
const double _synopsisFontSize = 12;
|
||||
const double _synopsisLineHeight = 1.15;
|
||||
const double _synopsisGap = 4;
|
||||
const int _maxTags = 2;
|
||||
const double _emptyListHeight = 360;
|
||||
const double _loadMoreThreshold = 240;
|
||||
@@ -252,6 +255,7 @@ class _FavoriteCard extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final tags = _tags();
|
||||
final synopsis = drama.synopsis.trim();
|
||||
return Container(
|
||||
key: ValueKey('favorite-card-${drama.id}'),
|
||||
decoration: BoxDecoration(
|
||||
@@ -345,7 +349,25 @@ class _FavoriteCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (synopsis.isNotEmpty) ...[
|
||||
const SizedBox(height: _synopsisGap),
|
||||
Flexible(
|
||||
child: Text(
|
||||
synopsis,
|
||||
key: ValueKey(
|
||||
'favorite-synopsis-${drama.id}',
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.muted,
|
||||
fontSize: _synopsisFontSize,
|
||||
height: _synopsisLineHeight,
|
||||
),
|
||||
),
|
||||
),
|
||||
] else
|
||||
const Spacer(),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/page_result.dart';
|
||||
|
||||
void main() {
|
||||
group('PageResult.parse', () {
|
||||
test('should_parse_page_map_when_total_and_list_present', () {
|
||||
final page = PageResult.parse({
|
||||
'total': '3',
|
||||
'list': [
|
||||
{'id': '1', 'title': 'A'},
|
||||
{'id': '2', 'title': 'B'},
|
||||
],
|
||||
}, _item);
|
||||
|
||||
expect(page.total, 3);
|
||||
expect(page.list.map((e) => e['id']), ['1', '2']);
|
||||
});
|
||||
|
||||
test('should_parse_legacy_list_when_data_is_array', () {
|
||||
final page = PageResult.parse([
|
||||
{'id': '9', 'title': '收藏剧'},
|
||||
{'id': '8', 'title': '另一部'},
|
||||
], _item);
|
||||
|
||||
expect(page.total, 2);
|
||||
expect(page.list, hasLength(2));
|
||||
expect(page.list.first['title'], '收藏剧');
|
||||
});
|
||||
|
||||
test('should_return_empty_page_when_data_is_null_or_empty_list', () {
|
||||
expect(PageResult.parse(null, _item).total, 0);
|
||||
expect(PageResult.parse(null, _item).list, isEmpty);
|
||||
expect(PageResult.parse(const <Object>[], _item).total, 0);
|
||||
expect(PageResult.parse(const <Object>[], _item).list, isEmpty);
|
||||
});
|
||||
|
||||
test('should_return_empty_page_when_payload_is_invalid', () {
|
||||
final page = PageResult.parse('broken', _item);
|
||||
expect(page.total, 0);
|
||||
expect(page.list, isEmpty);
|
||||
});
|
||||
|
||||
test('should_skip_non_map_entries_in_legacy_list', () {
|
||||
final page = PageResult.parse([
|
||||
{'id': '1'},
|
||||
'noise',
|
||||
42,
|
||||
{'id': '2'},
|
||||
], _item);
|
||||
|
||||
expect(page.total, 2);
|
||||
expect(page.list.map((e) => e['id']), ['1', '2']);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Map<String, dynamic> _item(Map<String, dynamic> json) => json;
|
||||
@@ -32,10 +32,10 @@ import '../support/fake_interaction_repositories.dart';
|
||||
import '../support/fake_notice_repository.dart';
|
||||
import '../support/widget_player.dart';
|
||||
|
||||
Drama _card(String id) => Drama(
|
||||
Drama _card(String id, {String synopsis = 'synopsis'}) => Drama(
|
||||
id: id,
|
||||
title: 'Drama $id',
|
||||
synopsis: 'synopsis',
|
||||
synopsis: synopsis,
|
||||
posterUrl: '/files/$id.png',
|
||||
totalEpisodes: 12,
|
||||
);
|
||||
@@ -73,6 +73,14 @@ void main() {
|
||||
);
|
||||
expect(title.style?.color, AppColors.onSurface);
|
||||
expect(title.style?.fontSize, 15);
|
||||
final synopsis = tester.widget<Text>(
|
||||
find.byKey(const Key('favorite-synopsis-signal')),
|
||||
);
|
||||
expect(synopsis.data, 'synopsis');
|
||||
expect(synopsis.maxLines, 2);
|
||||
expect(synopsis.overflow, TextOverflow.ellipsis);
|
||||
expect(synopsis.style?.color, AppColors.muted);
|
||||
expect(synopsis.style?.fontSize, 12);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('favorite-cover-signal'))),
|
||||
const Size(80, 106),
|
||||
@@ -100,6 +108,38 @@ void main() {
|
||||
expect(find.byKey(const Key('favorite-card-signal')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('should_hide_blank_synopsis_without_changing_card_height', (
|
||||
tester,
|
||||
) async {
|
||||
final auth = await _auth(signedIn: true);
|
||||
final longSynopsis = List.filled(12, '很长的剧情简介').join();
|
||||
final favorites = FavoriteController(
|
||||
InMemoryFavoriteRepository(
|
||||
saved: {'with-synopsis', 'without-synopsis'},
|
||||
cards: [
|
||||
_card('with-synopsis', synopsis: longSynopsis),
|
||||
_card('without-synopsis', synopsis: ' '),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
await _pumpPage(tester, auth: auth, favorites: favorites);
|
||||
|
||||
final withSynopsis = tester.widget<Text>(
|
||||
find.byKey(const Key('favorite-synopsis-with-synopsis')),
|
||||
);
|
||||
expect(withSynopsis.maxLines, 2);
|
||||
expect(withSynopsis.overflow, TextOverflow.ellipsis);
|
||||
expect(
|
||||
find.byKey(const Key('favorite-synopsis-without-synopsis')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('favorite-card-with-synopsis'))),
|
||||
tester.getSize(find.byKey(const Key('favorite-card-without-synopsis'))),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should_keep_card_and_show_failure_when_remove_fails', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -38,4 +38,67 @@ void main() {
|
||||
expect(page.list.single.id, '9');
|
||||
expect(page.list.single.title, '收藏剧');
|
||||
});
|
||||
|
||||
test('should_parse_favorites_when_server_returns_legacy_list', () async {
|
||||
final adapter = FakeHttpAdapter(
|
||||
(_) async => FakeHttpResponse(
|
||||
jsonEncode({
|
||||
'code': 0,
|
||||
'message': 'ok',
|
||||
'data': [
|
||||
{'id': '5', 'title': '闪婚后', 'cover': '/files/5.png'},
|
||||
{'id': '4', 'title': '另一部', 'cover': '/files/4.png'},
|
||||
],
|
||||
}),
|
||||
),
|
||||
);
|
||||
final api = LibraryApi(
|
||||
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
||||
);
|
||||
|
||||
final page = await api.favorites();
|
||||
|
||||
expect(page.total, 2);
|
||||
expect(page.list.map((drama) => drama.id), ['5', '4']);
|
||||
expect(page.list.first.title, '闪婚后');
|
||||
});
|
||||
|
||||
test('should_return_empty_favorites_when_data_is_null', () async {
|
||||
final adapter = FakeHttpAdapter(
|
||||
(_) async => FakeHttpResponse(
|
||||
jsonEncode({'code': 0, 'message': 'ok', 'data': null}),
|
||||
),
|
||||
);
|
||||
final api = LibraryApi(
|
||||
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
||||
);
|
||||
|
||||
final page = await api.favorites();
|
||||
|
||||
expect(page.total, 0);
|
||||
expect(page.list, isEmpty);
|
||||
});
|
||||
|
||||
test('should_throw_api_exception_when_favorites_business_code_failed', () async {
|
||||
final adapter = FakeHttpAdapter(
|
||||
(_) async => FakeHttpResponse(
|
||||
jsonEncode({'code': 401, 'message': '未登录或登录已过期', 'data': null}),
|
||||
),
|
||||
);
|
||||
final api = LibraryApi(
|
||||
ApiClient(
|
||||
baseUrl: 'http://127.0.0.1:8081',
|
||||
adapter: adapter,
|
||||
// 无刷新回调时,401 直接抛业务异常,避免重试逻辑。
|
||||
tokenRefresher: null,
|
||||
),
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
() => api.favorites(),
|
||||
throwsA(
|
||||
isA<ApiException>().having((e) => e.code, 'code', 401),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -50,4 +50,52 @@ void main() {
|
||||
expect(page.list.single.episodeNumber, 6);
|
||||
expect(page.list.single.totalEpisodes, 68);
|
||||
});
|
||||
|
||||
test('should_parse_recent_when_server_returns_legacy_list', () async {
|
||||
final adapter = FakeHttpAdapter(
|
||||
(_) async => FakeHttpResponse(
|
||||
jsonEncode({
|
||||
'code': 0,
|
||||
'message': 'ok',
|
||||
'data': [
|
||||
{
|
||||
'dramaId': '5',
|
||||
'episodeId': '7',
|
||||
'positionMs': '203904',
|
||||
'durationMs': '227882',
|
||||
'finished': false,
|
||||
'playCount': 8,
|
||||
'updatedAt': '2026-10-21T15:17:05.419',
|
||||
},
|
||||
],
|
||||
}),
|
||||
),
|
||||
);
|
||||
final api = WatchApi(
|
||||
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
||||
);
|
||||
|
||||
final page = await api.recent();
|
||||
|
||||
expect(page.total, 1);
|
||||
expect(page.list.single.dramaId, '5');
|
||||
expect(page.list.single.episodeId, '7');
|
||||
expect(page.list.single.position.inMilliseconds, 203904);
|
||||
});
|
||||
|
||||
test('should_return_empty_recent_when_data_is_null', () async {
|
||||
final adapter = FakeHttpAdapter(
|
||||
(_) async => FakeHttpResponse(
|
||||
jsonEncode({'code': 0, 'message': 'ok', 'data': null}),
|
||||
),
|
||||
);
|
||||
final api = WatchApi(
|
||||
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
||||
);
|
||||
|
||||
final page = await api.recent();
|
||||
|
||||
expect(page.total, 0);
|
||||
expect(page.list, isEmpty);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user