Skip to content

Commit 4d97b76

Browse files
committed
feat(shared): add headline actions bottom sheet
- Create HeadlineActionsBottomSheet widget for sharing and bookmarking headlines - Update imports in headlines_feed_page.dart - Add export for headline_actions_bottom_sheet.dart in widgets.dart
1 parent 93179f4 commit 4d97b76

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

lib/headlines-feed/view/headlines_feed_page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/b
1111
import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/widgets/feed_sliver_app_bar.dart';
1212
import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/widgets/saved_filters_bar.dart';
1313
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
14-
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/feed_core/feed_core.dart';
14+
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
15+
import 'package:flutter_news_app_mobile_client_full_source_code/shared/shared.dart';
1516
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/headline_actions_bottom_sheet.dart';
1617
import 'package:go_router/go_router.dart';
1718
import 'package:ui_kit/ui_kit.dart';
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import 'package:core/core.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_bloc/flutter_bloc.dart';
4+
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
5+
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
6+
import 'package:share_plus/share_plus.dart';
7+
import 'package:ui_kit/ui_kit.dart';
8+
9+
/// {@template headline_actions_bottom_sheet}
10+
/// A modal bottom sheet that displays actions for a given headline, such as
11+
/// sharing and bookmarking.
12+
/// {@endtemplate}
13+
class HeadlineActionsBottomSheet extends StatelessWidget {
14+
/// {@macro headline_actions_bottom_sheet}
15+
const HeadlineActionsBottomSheet({required this.headline, super.key});
16+
17+
/// The headline for which to display actions.
18+
final Headline headline;
19+
20+
@override
21+
Widget build(BuildContext context) {
22+
final l10n = AppLocalizationsX(context).l10n;
23+
return BlocBuilder<AppBloc, AppState>(
24+
builder: (context, state) {
25+
final isBookmarked = state.userContentPreferences?.savedHeadlines
26+
.any((saved) => saved.id == headline.id) ??
27+
false;
28+
29+
return Wrap(
30+
children: [
31+
Padding(
32+
padding: const EdgeInsets.all(AppSpacing.md),
33+
child: Text(
34+
l10n.headlineActionsModalTitle,
35+
style: Theme.of(context).textTheme.titleLarge,
36+
),
37+
),
38+
ListTile(
39+
leading: const Icon(Icons.share_outlined),
40+
title: Text(l10n.shareActionLabel),
41+
onTap: () {
42+
Navigator.of(context).pop();
43+
Share.share(headline.url);
44+
},
45+
),
46+
ListTile(
47+
leading: Icon(
48+
isBookmarked
49+
? Icons.bookmark_added
50+
: Icons.bookmark_add_outlined,
51+
),
52+
title: Text(
53+
isBookmarked
54+
? l10n.removeBookmarkActionLabel
55+
: l10n.bookmarkActionLabel,
56+
),
57+
onTap: () {
58+
final userContentPreferences = state.userContentPreferences;
59+
if (userContentPreferences == null) return;
60+
61+
final currentSaved =
62+
List<Headline>.from(userContentPreferences.savedHeadlines);
63+
64+
if (isBookmarked) {
65+
currentSaved.removeWhere((h) => h.id == headline.id);
66+
} else {
67+
currentSaved.insert(0, headline);
68+
}
69+
70+
context.read<AppBloc>().add(
71+
AppUserContentPreferencesChanged(
72+
preferences: userContentPreferences.copyWith(
73+
savedHeadlines: currentSaved,
74+
),
75+
),
76+
);
77+
Navigator.of(context).pop();
78+
},
79+
),
80+
],
81+
);
82+
},
83+
);
84+
}
85+
}

lib/shared/widgets/widgets.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export 'confirmation_dialog.dart';
22
export 'content_limitation_bottom_sheet.dart';
33
export 'feed_core/feed_core.dart';
4+
export 'headline_actions_bottom_sheet.dart';
45
export 'multi_select_search_page.dart';
56
export 'notification_indicator.dart';
67
export 'user_avatar.dart';

0 commit comments

Comments
 (0)