fix(flutter): 调整收藏页星标操作

This commit is contained in:
Zhou Weidong committed 2026-10-20 16:36:56 +08:00
1 parent f62324084e
commit 1d8582dfaa
9 files changed
+28 -49

No files matched your search

-1
View File
@@ -512,7 +512,6 @@
"count": {"type": "int"} "count": {"type": "int"}
} }
}, },
"favoriteLongPressHint": "Long press a card to remove",
"clearWatchHistoryTitle": "Clear watch history?", "clearWatchHistoryTitle": "Clear watch history?",
"clearWatchHistoryMessage": "This removes the watch history from your account.", "clearWatchHistoryMessage": "This removes the watch history from your account.",
"confirmClear": "Clear", "confirmClear": "Clear",
-1
View File
@@ -476,7 +476,6 @@
"clearAll": "Hapus semua", "clearAll": "Hapus semua",
"watchRecordsCount": "{count} riwayat", "watchRecordsCount": "{count} riwayat",
"favoritesCount": "{count} favorit", "favoritesCount": "{count} favorit",
"favoriteLongPressHint": "Tekan lama kartu untuk menghapus",
"clearWatchHistoryTitle": "Hapus riwayat tontonan?", "clearWatchHistoryTitle": "Hapus riwayat tontonan?",
"clearWatchHistoryMessage": "Semua riwayat akan dihapus dari akun kamu.", "clearWatchHistoryMessage": "Semua riwayat akan dihapus dari akun kamu.",
"confirmClear": "Hapus", "confirmClear": "Hapus",
-6
View File
@@ -2086,12 +2086,6 @@ abstract class AppLocalizations {
/// **'{count} favorites'** /// **'{count} favorites'**
String favoritesCount(int count); String favoritesCount(int count);
/// No description provided for @favoriteLongPressHint.
///
/// In en, this message translates to:
/// **'Long press a card to remove'**
String get favoriteLongPressHint;
/// No description provided for @clearWatchHistoryTitle. /// No description provided for @clearWatchHistoryTitle.
/// ///
/// In en, this message translates to: /// In en, this message translates to:
-3
View File
@@ -1078,9 +1078,6 @@ class AppLocalizationsEn extends AppLocalizations {
return '$count favorites'; return '$count favorites';
} }
@override
String get favoriteLongPressHint => 'Long press a card to remove';
@override @override
String get clearWatchHistoryTitle => 'Clear watch history?'; String get clearWatchHistoryTitle => 'Clear watch history?';
-3
View File
@@ -1078,9 +1078,6 @@ class AppLocalizationsId extends AppLocalizations {
return '$count favorit'; return '$count favorit';
} }
@override
String get favoriteLongPressHint => 'Tekan lama kartu untuk menghapus';
@override @override
String get clearWatchHistoryTitle => 'Hapus riwayat tontonan?'; String get clearWatchHistoryTitle => 'Hapus riwayat tontonan?';
-3
View File
@@ -1059,9 +1059,6 @@ class AppLocalizationsZh extends AppLocalizations {
return '共 $count 部'; return '共 $count 部';
} }
@override
String get favoriteLongPressHint => '长按卡片可取消收藏';
@override @override
String get clearWatchHistoryTitle => '清空观看记录?'; String get clearWatchHistoryTitle => '清空观看记录?';
-1
View File
@@ -438,7 +438,6 @@
"clearAll": "清空", "clearAll": "清空",
"watchRecordsCount": "共 {count} 条", "watchRecordsCount": "共 {count} 条",
"favoritesCount": "共 {count} 部", "favoritesCount": "共 {count} 部",
"favoriteLongPressHint": "长按卡片可取消收藏",
"clearWatchHistoryTitle": "清空观看记录?", "clearWatchHistoryTitle": "清空观看记录?",
"clearWatchHistoryMessage": "这会从当前账号移除全部观看记录。", "clearWatchHistoryMessage": "这会从当前账号移除全部观看记录。",
"confirmClear": "清空", "confirmClear": "清空",
+20 -30
View File
@@ -28,7 +28,7 @@ const double _coverWidth = 80;
const double _coverHeight = 106; const double _coverHeight = 106;
const double _coverRadius = 10; const double _coverRadius = 10;
const double _removeSize = 28; const double _removeSize = 28;
const double _removeIconSize = 15; const double _removeIconSize = 20;
const double _statsFontSize = 12; const double _statsFontSize = 12;
const double _metaFontSize = 11; const double _metaFontSize = 11;
const double _titleFontSize = 15; const double _titleFontSize = 15;
@@ -134,7 +134,7 @@ class _FavoritesBody extends StatelessWidget {
height: _emptyListHeight, height: _emptyListHeight,
child: EmptyState( child: EmptyState(
key: const Key('favorites-empty'), key: const Key('favorites-empty'),
icon: Icons.favorite_border_rounded, icon: Icons.star_border_rounded,
title: l10n.noFavorites, title: l10n.noFavorites,
subtitle: l10n.emptyHint, subtitle: l10n.emptyHint,
), ),
@@ -150,6 +150,7 @@ class _FavoritesBody extends StatelessWidget {
if (index > 0) const SizedBox(height: 10), if (index > 0) const SizedBox(height: 10),
_FavoriteCard( _FavoriteCard(
drama: drama, drama: drama,
isFavorite: favorites.isSaved(drama.id),
onOpen: () => _open(context, drama), onOpen: () => _open(context, drama),
onRemove: () => _remove(context, drama.id), onRemove: () => _remove(context, drama.id),
), ),
@@ -181,30 +182,16 @@ class _FavoritesBody extends StatelessWidget {
} }
Widget _summary(AppLocalizations l10n) { Widget _summary(AppLocalizations l10n) {
return Row( return Align(
children: [ alignment: Alignment.centerLeft,
Text( child: Text(
l10n.favoritesCount(favorites.cards.length), l10n.favoritesCount(favorites.cards.length),
key: const Key('favorites-count'), key: const Key('favorites-count'),
style: const TextStyle( style: const TextStyle(
color: AppColors.muted, color: AppColors.muted,
fontSize: _statsFontSize, fontSize: _statsFontSize,
),
), ),
const Spacer(), ),
Flexible(
child: Text(
l10n.favoriteLongPressHint,
maxLines: 1,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.end,
style: const TextStyle(
color: AppColors.subtle,
fontSize: _metaFontSize,
),
),
),
],
); );
} }
@@ -228,11 +215,13 @@ class _FavoritesBody extends StatelessWidget {
class _FavoriteCard extends StatelessWidget { class _FavoriteCard extends StatelessWidget {
const _FavoriteCard({ const _FavoriteCard({
required this.drama, required this.drama,
required this.isFavorite,
required this.onOpen, required this.onOpen,
required this.onRemove, required this.onRemove,
}); });
final Drama drama; final Drama drama;
final bool isFavorite;
final VoidCallback onOpen; final VoidCallback onOpen;
final VoidCallback onRemove; final VoidCallback onRemove;
@@ -253,7 +242,6 @@ class _FavoriteCard extends StatelessWidget {
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
child: InkWell( child: InkWell(
onTap: onOpen, onTap: onOpen,
onLongPress: onRemove,
child: Padding( child: Padding(
padding: const EdgeInsets.all(_cardPadding), padding: const EdgeInsets.all(_cardPadding),
child: Stack( child: Stack(
@@ -373,7 +361,7 @@ class _FavoriteCard extends StatelessWidget {
child: SizedBox.square( child: SizedBox.square(
dimension: _removeSize, dimension: _removeSize,
child: Material( child: Material(
color: AppColors.badgePink, color: AppColors.raised,
shape: const CircleBorder(), shape: const CircleBorder(),
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
child: IconButton( child: IconButton(
@@ -381,9 +369,11 @@ class _FavoriteCard extends StatelessWidget {
tooltip: l10n.remove, tooltip: l10n.remove,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
onPressed: onRemove, onPressed: onRemove,
icon: const Icon( icon: Icon(
Icons.favorite_rounded, isFavorite
color: AppColors.favorite, ? Icons.star_rounded
: Icons.star_border_rounded,
color: isFavorite ? AppColors.blue : AppColors.muted,
size: _removeIconSize, size: _removeIconSize,
), ),
), ),
+8 -1
View File
@@ -54,7 +54,7 @@ void main() {
tester.widget<Text>(find.byKey(const Key('favorites-count'))).data, tester.widget<Text>(find.byKey(const Key('favorites-count'))).data,
'2 favorites', '2 favorites',
); );
expect(find.text('Long press a card to remove'), findsOneWidget); expect(find.text('Long press a card to remove'), findsNothing);
expect(find.text('Drama signal'), findsOneWidget); expect(find.text('Drama signal'), findsOneWidget);
expect(find.text('Drama city'), findsOneWidget); expect(find.text('Drama city'), findsOneWidget);
final title = tester.widget<Text>( final title = tester.widget<Text>(
@@ -71,12 +71,19 @@ void main() {
tester.getSize(find.byKey(const Key('favorite-remove-signal'))), tester.getSize(find.byKey(const Key('favorite-remove-signal'))),
const Size(28, 28), const Size(28, 28),
); );
expect(find.byIcon(Icons.star_rounded), findsNWidgets(2));
expect(find.byIcon(Icons.favorite_rounded), findsNothing);
final refresh = tester.widget<RefreshIndicator>( final refresh = tester.widget<RefreshIndicator>(
find.byType(RefreshIndicator), find.byType(RefreshIndicator),
); );
expect(refresh.color, AppColors.blue); expect(refresh.color, AppColors.blue);
expect(refresh.backgroundColor, AppColors.card); expect(refresh.backgroundColor, AppColors.card);
expect(refresh.strokeWidth, 2); expect(refresh.strokeWidth, 2);
await tester.tap(find.byKey(const Key('favorite-remove-signal')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('favorite-card-signal')), findsNothing);
}); });
testWidgets('should_keep_card_and_show_failure_when_remove_fails', ( testWidgets('should_keep_card_and_show_failure_when_remove_fails', (