Skip to content

Commit 327b442

Browse files
committed
style: format
1 parent b0a228d commit 327b442

File tree

9 files changed

+153
-137
lines changed

9 files changed

+153
-137
lines changed

lib/app/bloc/app_bloc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import 'package:flutter_news_app_mobile_client_full_source_code/app/models/initi
1313
import 'package:flutter_news_app_mobile_client_full_source_code/app/services/app_initializer.dart';
1414
import 'package:flutter_news_app_mobile_client_full_source_code/notifications/services/push_notification_service.dart';
1515
import 'package:flutter_news_app_mobile_client_full_source_code/shared/extensions/extensions.dart';
16+
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/content_limitation_service.dart';
1617
import 'package:flutter_news_app_mobile_client_full_source_code/user_content/app_review/services/app_review_service.dart';
1718
import 'package:logging/logging.dart';
18-
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/content_limitation_service.dart';
1919

2020
part 'app_event.dart';
2121
part 'app_state.dart';

lib/app/bloc/app_state.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ class AppState extends Equatable {
181181
positiveInteractionCount:
182182
positiveInteractionCount ?? this.positiveInteractionCount,
183183
limitationStatus: limitationStatus ?? this.limitationStatus,
184-
limitedAction:
185-
clearLimitedAction ? null : limitedAction ?? this.limitedAction,
184+
limitedAction: clearLimitedAction
185+
? null
186+
: limitedAction ?? this.limitedAction,
186187
);
187188
}
188189
}

lib/headlines-feed/bloc/headlines_feed_bloc.dart

Lines changed: 84 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
7676
required FeedCacheService feedCacheService,
7777
required ContentLimitationService contentLimitationService,
7878
UserContentPreferences? initialUserContentPreferences,
79-
}) : _headlinesRepository = headlinesRepository,
80-
_feedDecoratorService = feedDecoratorService,
81-
_engagementRepository = engagementRepository,
82-
_adService = adService,
83-
_appBloc = appBloc,
84-
_inlineAdCacheService = inlineAdCacheService,
85-
_feedCacheService = feedCacheService,
86-
_contentLimitationService = contentLimitationService,
87-
_logger = Logger('HeadlinesFeedBloc'),
88-
super(
89-
HeadlinesFeedState(
90-
savedHeadlineFilters:
91-
initialUserContentPreferences?.savedHeadlineFilters ?? const [],
92-
),
93-
) {
79+
}) : _headlinesRepository = headlinesRepository,
80+
_feedDecoratorService = feedDecoratorService,
81+
_engagementRepository = engagementRepository,
82+
_adService = adService,
83+
_appBloc = appBloc,
84+
_inlineAdCacheService = inlineAdCacheService,
85+
_feedCacheService = feedCacheService,
86+
_contentLimitationService = contentLimitationService,
87+
_logger = Logger('HeadlinesFeedBloc'),
88+
super(
89+
HeadlinesFeedState(
90+
savedHeadlineFilters:
91+
initialUserContentPreferences?.savedHeadlineFilters ?? const [],
92+
),
93+
) {
9494
// Subscribe to AppBloc to react to global state changes, primarily for
9595
// keeping the feed's list of saved filters synchronized with the global
9696
// app state.
@@ -224,11 +224,7 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
224224
// Group engagements by their entityId.
225225
return groupBy(response.items, (e) => e.entityId);
226226
} catch (e, s) {
227-
_logger.severe(
228-
'Failed to fetch engagements for headlines.',
229-
e,
230-
s,
231-
);
227+
_logger.severe('Failed to fetch engagements for headlines.', e, s);
232228
return {}; // Return empty map on failure to avoid breaking the feed.
233229
}
234230
}
@@ -311,9 +307,9 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
311307
final newEngagements = await _fetchEngagementsForHeadlines(
312308
headlineResponse.items.map((h) => h.id).toList(),
313309
);
314-
final updatedEngagementsMap =
315-
Map<String, List<Engagement>>.from(cachedFeed.engagementsMap)
316-
..addAll(newEngagements);
310+
final updatedEngagementsMap = Map<String, List<Engagement>>.from(
311+
cachedFeed.engagementsMap,
312+
)..addAll(newEngagements);
317313

318314
// For pagination, only inject ad placeholders.
319315
final newProcessedFeedItems = await _adService.injectFeedAdPlaceholders(
@@ -322,8 +318,9 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
322318
remoteConfig: remoteConfig,
323319
imageStyle: _appBloc.state.settings!.feedSettings.feedItemImageStyle,
324320
adThemeStyle: event.adThemeStyle,
325-
processedContentItemCount:
326-
cachedFeed.feedItems.whereType<Headline>().length,
321+
processedContentItemCount: cachedFeed.feedItems
322+
.whereType<Headline>()
323+
.length,
327324
);
328325

329326
_logger.fine(
@@ -370,8 +367,9 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
370367

371368
// Apply throttling logic.
372369
if (cachedFeed != null) {
373-
final timeSinceLastRefresh =
374-
DateTime.now().difference(cachedFeed.lastRefreshedAt);
370+
final timeSinceLastRefresh = DateTime.now().difference(
371+
cachedFeed.lastRefreshedAt,
372+
);
375373
if (timeSinceLastRefresh < _refreshThrottleDuration) {
376374
_logger.info(
377375
'Refresh throttled for filter "$filterKey". '
@@ -408,9 +406,9 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
408406
final newEngagements = await _fetchEngagementsForHeadlines(
409407
headlineResponse.items.map((h) => h.id).toList(),
410408
);
411-
final updatedEngagementsMap =
412-
Map<String, List<Engagement>>.from(cachedFeed?.engagementsMap ?? {})
413-
..addAll(newEngagements);
409+
final updatedEngagementsMap = Map<String, List<Engagement>>.from(
410+
cachedFeed?.engagementsMap ?? {},
411+
)..addAll(newEngagements);
414412

415413
_logger.info(
416414
'Refresh: Fetched ${headlineResponse.items.length} latest headlines '
@@ -423,8 +421,9 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
423421

424422
if (cachedHeadlines.isNotEmpty) {
425423
final firstCachedHeadlineId = cachedHeadlines.first.id;
426-
final matchIndex =
427-
newHeadlines.indexWhere((h) => h.id == firstCachedHeadlineId);
424+
final matchIndex = newHeadlines.indexWhere(
425+
(h) => h.id == firstCachedHeadlineId,
426+
);
428427

429428
if (matchIndex != -1) {
430429
// Prepend only the new items found before the match.
@@ -557,8 +556,9 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
557556
// Case 2: A filter was applied from the filter page ("Apply Only") or
558557
// by applying an un-pinned saved filter.
559558
// We check if the criteria match any *pinned* saved filter.
560-
final matchingPinnedFilter =
561-
state.savedHeadlineFilters.firstWhereOrNull((savedFilter) {
559+
final matchingPinnedFilter = state.savedHeadlineFilters.firstWhereOrNull((
560+
savedFilter,
561+
) {
562562
// Only consider pinned filters for direct ID matching.
563563
if (!savedFilter.isPinned) return false;
564564

@@ -999,14 +999,16 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
999999
}
10001000

10011001
final currentEngagements = state.engagementsMap[event.headlineId] ?? [];
1002-
final userEngagement =
1003-
currentEngagements.firstWhereOrNull((e) => e.userId == userId);
1002+
final userEngagement = currentEngagements.firstWhereOrNull(
1003+
(e) => e.userId == userId,
1004+
);
10041005

10051006
try {
10061007
Engagement? updatedEngagement;
10071008

10081009
if (userEngagement != null) {
1009-
final isTogglingOff = event.reactionType == null ||
1010+
final isTogglingOff =
1011+
event.reactionType == null ||
10101012
userEngagement.reaction?.reactionType == event.reactionType;
10111013

10121014
if (isTogglingOff) {
@@ -1053,16 +1055,16 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
10531055
}
10541056

10551057
// Optimistically update the state
1056-
final newEngagementsForHeadline =
1057-
List<Engagement>.from(currentEngagements)
1058-
..removeWhere((e) => e.userId == userId);
1058+
final newEngagementsForHeadline = List<Engagement>.from(
1059+
currentEngagements,
1060+
)..removeWhere((e) => e.userId == userId);
10591061
if (updatedEngagement != null) {
10601062
newEngagementsForHeadline.add(updatedEngagement);
10611063
}
10621064

1063-
final newEngagementsMap =
1064-
Map<String, List<Engagement>>.from(state.engagementsMap)
1065-
..[event.headlineId] = newEngagementsForHeadline;
1065+
final newEngagementsMap = Map<String, List<Engagement>>.from(
1066+
state.engagementsMap,
1067+
)..[event.headlineId] = newEngagementsForHeadline;
10661068

10671069
// Update the cache with the new engagement map.
10681070
final filterKey = _generateFilterKey(state.activeFilterId!, state.filter);
@@ -1089,8 +1091,9 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
10891091
final language = _appBloc.state.settings?.language;
10901092
if (userId == null || language == null) return;
10911093

1092-
final preCheckStatus =
1093-
await _contentLimitationService.checkAction(ContentAction.postComment);
1094+
final preCheckStatus = await _contentLimitationService.checkAction(
1095+
ContentAction.postComment,
1096+
);
10941097
if (preCheckStatus != LimitationStatus.allowed) {
10951098
_logger.warning('Comment limit reached for user $userId.');
10961099
emit(
@@ -1104,30 +1107,31 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
11041107
}
11051108

11061109
final currentEngagements = state.engagementsMap[event.headlineId] ?? [];
1107-
final userEngagement =
1108-
currentEngagements.firstWhereOrNull((e) => e.userId == userId);
1110+
final userEngagement = currentEngagements.firstWhereOrNull(
1111+
(e) => e.userId == userId,
1112+
);
11091113

11101114
final newComment = Comment(language: language, content: event.content);
1111-
final engagementToUpsert = (userEngagement ??
1112-
Engagement(
1113-
id: const Uuid().v4(),
1114-
userId: userId,
1115-
entityId: event.headlineId,
1116-
entityType: EngageableType.headline,
1117-
createdAt: DateTime.now(),
1118-
updatedAt: DateTime.now(),
1119-
))
1120-
.copyWith(comment: ValueWrapper(newComment));
1115+
final engagementToUpsert =
1116+
(userEngagement ??
1117+
Engagement(
1118+
id: const Uuid().v4(),
1119+
userId: userId,
1120+
entityId: event.headlineId,
1121+
entityType: EngageableType.headline,
1122+
createdAt: DateTime.now(),
1123+
updatedAt: DateTime.now(),
1124+
))
1125+
.copyWith(comment: ValueWrapper(newComment));
11211126

11221127
// Optimistic UI update
1123-
final newEngagementsForHeadline =
1124-
List<Engagement>.from(currentEngagements)
1125-
..removeWhere((e) => e.userId == userId)
1126-
..add(engagementToUpsert);
1128+
final newEngagementsForHeadline = List<Engagement>.from(currentEngagements)
1129+
..removeWhere((e) => e.userId == userId)
1130+
..add(engagementToUpsert);
11271131

1128-
final newEngagementsMap =
1129-
Map<String, List<Engagement>>.from(state.engagementsMap)
1130-
..[event.headlineId] = newEngagementsForHeadline;
1132+
final newEngagementsMap = Map<String, List<Engagement>>.from(
1133+
state.engagementsMap,
1134+
)..[event.headlineId] = newEngagementsForHeadline;
11311135

11321136
final filterKey = _generateFilterKey(state.activeFilterId!, state.filter);
11331137
final cachedFeed = _feedCacheService.getFeed(filterKey);
@@ -1170,8 +1174,9 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
11701174
if (userId == null || language == null) return;
11711175

11721176
final currentEngagements = state.engagementsMap[event.headlineId] ?? [];
1173-
final userEngagement =
1174-
currentEngagements.firstWhereOrNull((e) => e.userId == userId);
1177+
final userEngagement = currentEngagements.firstWhereOrNull(
1178+
(e) => e.userId == userId,
1179+
);
11751180

11761181
// If there's no existing engagement or no comment to update, do nothing.
11771182
if (userEngagement == null || userEngagement.comment == null) {
@@ -1182,20 +1187,21 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
11821187
return;
11831188
}
11841189

1185-
final updatedComment =
1186-
userEngagement.comment!.copyWith(content: event.content);
1187-
final updatedEngagement =
1188-
userEngagement.copyWith(comment: ValueWrapper(updatedComment));
1190+
final updatedComment = userEngagement.comment!.copyWith(
1191+
content: event.content,
1192+
);
1193+
final updatedEngagement = userEngagement.copyWith(
1194+
comment: ValueWrapper(updatedComment),
1195+
);
11891196

11901197
// Optimistic UI update
1191-
final newEngagementsForHeadline =
1192-
List<Engagement>.from(currentEngagements)
1193-
..removeWhere((e) => e.userId == userId)
1194-
..add(updatedEngagement);
1195-
1196-
final newEngagementsMap =
1197-
Map<String, List<Engagement>>.from(state.engagementsMap)
1198-
..[event.headlineId] = newEngagementsForHeadline;
1198+
final newEngagementsForHeadline = List<Engagement>.from(currentEngagements)
1199+
..removeWhere((e) => e.userId == userId)
1200+
..add(updatedEngagement);
1201+
1202+
final newEngagementsMap = Map<String, List<Engagement>>.from(
1203+
state.engagementsMap,
1204+
)..[event.headlineId] = newEngagementsForHeadline;
11991205

12001206
final filterKey = _generateFilterKey(state.activeFilterId!, state.filter);
12011207
final cachedFeed = _feedCacheService.getFeed(filterKey);

lib/headlines-feed/bloc/headlines_feed_state.dart

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,37 +90,40 @@ class HeadlinesFeedState extends Equatable {
9090
cursor: clearCursor ? null : cursor ?? this.cursor,
9191
filter: filter ?? this.filter,
9292
savedHeadlineFilters: savedHeadlineFilters ?? this.savedHeadlineFilters,
93-
activeFilterId:
94-
clearActiveFilterId ? null : activeFilterId ?? this.activeFilterId,
93+
activeFilterId: clearActiveFilterId
94+
? null
95+
: activeFilterId ?? this.activeFilterId,
9596
error: error ?? this.error,
96-
navigationUrl:
97-
clearNavigationUrl ? null : navigationUrl ?? this.navigationUrl,
97+
navigationUrl: clearNavigationUrl
98+
? null
99+
: navigationUrl ?? this.navigationUrl,
98100
navigationArguments: clearNavigationArguments
99101
? null
100102
: navigationArguments ?? this.navigationArguments,
101103
adThemeStyle: adThemeStyle ?? this.adThemeStyle,
102104
engagementsMap: engagementsMap ?? this.engagementsMap,
103105
limitationStatus: limitationStatus ?? this.limitationStatus,
104-
limitedAction:
105-
clearLimitedAction ? null : limitedAction ?? this.limitedAction,
106+
limitedAction: clearLimitedAction
107+
? null
108+
: limitedAction ?? this.limitedAction,
106109
);
107110
}
108111

109112
@override
110113
List<Object?> get props => [
111-
status,
112-
feedItems,
113-
hasMore,
114-
cursor,
115-
filter,
116-
savedHeadlineFilters,
117-
activeFilterId,
118-
error,
119-
navigationUrl,
120-
navigationArguments,
121-
adThemeStyle,
122-
engagementsMap,
114+
status,
115+
feedItems,
116+
hasMore,
117+
cursor,
118+
filter,
119+
savedHeadlineFilters,
120+
activeFilterId,
121+
error,
122+
navigationUrl,
123+
navigationArguments,
124+
adThemeStyle,
125+
engagementsMap,
123126
limitationStatus,
124127
limitedAction,
125-
];
128+
];
126129
}

lib/headlines-feed/models/cached_feed.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ class CachedFeed extends Equatable {
5555
}
5656

5757
@override
58-
List<Object?> get props =>
59-
[feedItems, hasMore, cursor, lastRefreshedAt, engagementsMap];
58+
List<Object?> get props => [
59+
feedItems,
60+
hasMore,
61+
cursor,
62+
lastRefreshedAt,
63+
engagementsMap,
64+
];
6065

6166
@override
6267
String toString() {

lib/headlines-feed/view/headlines_feed_page.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ import 'package:flutter_news_app_mobile_client_full_source_code/feed_decorators/
1010
import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/bloc/headlines_feed_bloc.dart';
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';
13-
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
14-
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/content_limitation_bottom_sheet.dart';
15-
import 'package:flutter_news_app_mobile_client_full_source_code/user_content/engagement/view/comments_bottom_sheet.dart';
1613
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
1714
import 'package:flutter_news_app_mobile_client_full_source_code/shared/shared.dart';
15+
import 'package:flutter_news_app_mobile_client_full_source_code/user_content/engagement/view/comments_bottom_sheet.dart';
1816
import 'package:go_router/go_router.dart';
1917
import 'package:ui_kit/ui_kit.dart';
2018

@@ -132,7 +130,7 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage>
132130
// This listener handles navigation actions triggered by the BLoC.
133131
if (state.navigationUrl != null) {
134132
if (state.navigationArguments is Headline) {
135-
final headline = state.navigationArguments as Headline;
133+
final headline = state.navigationArguments! as Headline;
136134
final engagements = state.engagementsMap[headline.id] ?? [];
137135
showModalBottomSheet<void>(
138136
context: context,

0 commit comments

Comments
 (0)