From 524b7f5b358a162125e076e07a6fe3c8731395dd Mon Sep 17 00:00:00 2001 From: Zhou Weidong <502333560@qq.com> Date: Tue, 20 Oct 2026 13:11:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(flutter):=20=E9=A6=96=E9=A1=B5=E9=A1=B6?= =?UTF-8?q?=E6=A0=8F=E6=94=B9=E4=B8=BA=E9=80=9A=E7=9F=A5=E9=93=83=E9=93=9B?= =?UTF-8?q?=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/widgets/home_browse_header.dart | 49 ++++++++++--------- test/home/home_preview_layout_test.dart | 31 +++++++++++- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/lib/pages/home/widgets/home_browse_header.dart b/lib/pages/home/widgets/home_browse_header.dart index 71f6208..e6554a4 100644 --- a/lib/pages/home/widgets/home_browse_header.dart +++ b/lib/pages/home/widgets/home_browse_header.dart @@ -5,10 +5,11 @@ import 'package:flutter/material.dart'; import '../../../core/theme/app_colors.dart'; import '../../../core/theme/app_dimens.dart'; import '../../../l10n/app_localizations.dart'; +import '../../notices/notices_page.dart'; const double _searchHeight = 36; -/// 首页固定顶栏:搜索、星期与头像入口。 +/// 首页固定顶栏:搜索、通知与头像入口。 class HomeBrowseHeader extends StatelessWidget { const HomeBrowseHeader({ super.key, @@ -22,7 +23,6 @@ class HomeBrowseHeader extends StatelessWidget { @override Widget build(BuildContext context) { final l10n = AppLocalizations.of(context)!; - final weekday = _weekday(l10n); return SizedBox( height: AppDimens.contentHeaderHeight, child: Padding( @@ -33,7 +33,7 @@ class HomeBrowseHeader extends StatelessWidget { children: [ Expanded(child: _search(l10n, onSearch)), const SizedBox(width: AppDimens.spaceSm), - _weekdayText(weekday), + _notifications(context, l10n), const SizedBox(width: AppDimens.spaceSm), _profile(l10n), ], @@ -42,18 +42,6 @@ class HomeBrowseHeader extends StatelessWidget { ); } - String _weekday(AppLocalizations l10n) { - return switch (DateTime.now().weekday) { - DateTime.monday => l10n.weekdayMon, - DateTime.tuesday => l10n.weekdayTue, - DateTime.wednesday => l10n.weekdayWed, - DateTime.thursday => l10n.weekdayThu, - DateTime.friday => l10n.weekdayFri, - DateTime.saturday => l10n.weekdaySat, - _ => l10n.weekdaySun, - }; - } - Widget _search(AppLocalizations l10n, VoidCallback onTap) { return Semantics( button: true, @@ -95,14 +83,29 @@ class HomeBrowseHeader extends StatelessWidget { ); } - Widget _weekdayText(String value) { - return Text( - value, - key: const Key('home-weekday'), - style: const TextStyle( - color: AppColors.muted, - fontSize: AppDimens.caption, - fontWeight: FontWeight.w600, + Widget _notifications(BuildContext context, AppLocalizations l10n) { + return Semantics( + button: true, + label: l10n.notices, + child: InkWell( + key: const Key('home-notifications'), + customBorder: const CircleBorder(), + onTap: () => Navigator.of( + context, + ).push(MaterialPageRoute(builder: (_) => const NoticesPage())), + child: Container( + width: AppDimens.tapTarget, + height: AppDimens.tapTarget, + decoration: const BoxDecoration( + color: AppColors.card, + shape: BoxShape.circle, + ), + child: const Icon( + Icons.notifications_none_rounded, + color: AppColors.onSurface, + size: AppDimens.accountIcon, + ), + ), ), ); } diff --git a/test/home/home_preview_layout_test.dart b/test/home/home_preview_layout_test.dart index 279abd3..c706c7a 100644 --- a/test/home/home_preview_layout_test.dart +++ b/test/home/home_preview_layout_test.dart @@ -63,7 +63,7 @@ void main() { expect(find.byKey(const Key('home-search')), findsOneWidget); expect(find.byKey(const Key('home-profile')), findsOneWidget); - expect(find.byKey(const Key('home-weekday')), findsOneWidget); + expect(find.byKey(const Key('home-notifications')), findsOneWidget); for (final channel in ['hot', 'free', 'newReleases', 'ranking']) { expect(find.byKey(Key('home-channel-$channel')), findsOneWidget); } @@ -76,6 +76,35 @@ void main() { expect(tester.takeException(), isNull); }); + testWidgets('should_open_notices_when_bell_is_tapped', (tester) async { + SharedPreferencesAsyncPlatform.instance = + InMemorySharedPreferencesAsync.empty(); + tester.view.physicalSize = const Size(390, 844); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + final catalog = FakeCatalogRepository(); + await tester.pumpWidget( + LumaDramaApp( + playerFactory: createWidgetPlayer, + catalogRepository: catalog, + categoryRepository: FakeCategoryRepository(catalog: catalog), + watchHistoryRepository: InMemoryWatchHistoryRepository(), + favoriteRepository: InMemoryFavoriteRepository(cards: catalog.dramas), + playbackRepository: FakePlaybackRepository(), + commentRepository: FakeCommentRepository(), + interactionRepository: FakeInteractionRepository(), + noticeRepository: FakeNoticeRepository(), + haptics: FakeHaptics(), + ), + ); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key('home-notifications'))); + await tester.pumpAndSettle(); + expect(find.byKey(const Key('notices-page')), findsOneWidget); + }); + testWidgets('should_use_episode_title_then_drama_title_as_fallback', ( tester, ) async {