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+ }
0 commit comments