Skip to content

Commit c0ab5f7

Browse files
committed
style: format
1 parent 57afad4 commit c0ab5f7

File tree

5 files changed

+119
-112
lines changed

5 files changed

+119
-112
lines changed

lib/ads/widgets/in_article_ad_loader_widget.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class _InArticleAdLoaderWidgetState extends State<InArticleAdLoaderWidget> {
105105
'Disposing old ad for slot "${oldWidget.slotType.name}" '
106106
'before loading new one.',
107107
);
108-
_adService.disposeAd(_loadedAd!);
108+
_adService.disposeAd(_loadedAd);
109109
}
110110

111111
// Immediately set the widget to a loading state to prevent UI flicker.
@@ -133,7 +133,7 @@ class _InArticleAdLoaderWidgetState extends State<InArticleAdLoaderWidget> {
133133
'Disposing in-article ad for slot "${widget.slotType.name}" '
134134
'as widget is being disposed.',
135135
);
136-
_adService.disposeAd(_loadedAd!);
136+
_adService.disposeAd(_loadedAd);
137137
}
138138

139139
// Cancel any pending ad loading operation when the widget is disposed.

lib/app/bloc/app_bloc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import 'package:data_repository/data_repository.dart';
66
import 'package:equatable/equatable.dart';
77
import 'package:flex_color_scheme/flex_color_scheme.dart';
88
import 'package:flutter/material.dart';
9-
import 'package:flutter_news_app_mobile_client_full_source_code/ads/inline_ad_cache_service.dart';
109
import 'package:flutter_bloc/flutter_bloc.dart';
10+
import 'package:flutter_news_app_mobile_client_full_source_code/ads/inline_ad_cache_service.dart';
1111
import 'package:flutter_news_app_mobile_client_full_source_code/app/models/app_life_cycle_status.dart';
1212
import 'package:flutter_news_app_mobile_client_full_source_code/app/models/initialization_result.dart';
1313
import 'package:flutter_news_app_mobile_client_full_source_code/app/services/app_initializer.dart';

lib/headlines-feed/bloc/headlines_feed_bloc.dart

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
6767
required InlineAdCacheService inlineAdCacheService,
6868
required FeedCacheService feedCacheService,
6969
UserContentPreferences? initialUserContentPreferences,
70-
}) : _headlinesRepository = headlinesRepository,
71-
_feedDecoratorService = feedDecoratorService,
72-
_appBloc = appBloc,
73-
_inlineAdCacheService = inlineAdCacheService,
74-
_feedCacheService = feedCacheService,
75-
_logger = Logger('HeadlinesFeedBloc'),
76-
super(
77-
HeadlinesFeedState(
78-
savedFilters:
79-
initialUserContentPreferences?.savedFilters ?? const [],
80-
),
81-
) {
70+
}) : _headlinesRepository = headlinesRepository,
71+
_feedDecoratorService = feedDecoratorService,
72+
_appBloc = appBloc,
73+
_inlineAdCacheService = inlineAdCacheService,
74+
_feedCacheService = feedCacheService,
75+
_logger = Logger('HeadlinesFeedBloc'),
76+
super(
77+
HeadlinesFeedState(
78+
savedFilters:
79+
initialUserContentPreferences?.savedFilters ?? const [],
80+
),
81+
) {
8282
// Subscribe to AppBloc to react to global state changes, primarily for
8383
// keeping the feed's list of saved filters synchronized with the global
8484
// app state.
@@ -244,17 +244,18 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
244244
);
245245

246246
// For pagination, only inject ad placeholders, not feed actions.
247-
final newProcessedFeedItems =
248-
await _feedDecoratorService.injectAdPlaceholders(
249-
feedItems: headlineResponse.items,
250-
user: currentUser,
251-
adConfig: remoteConfig.adConfig,
252-
imageStyle:
253-
_appBloc.state.settings!.feedPreferences.headlineImageStyle,
254-
adThemeStyle: event.adThemeStyle,
255-
processedContentItemCount:
256-
cachedFeed.feedItems.whereType<Headline>().length,
257-
);
247+
final newProcessedFeedItems = await _feedDecoratorService
248+
.injectAdPlaceholders(
249+
feedItems: headlineResponse.items,
250+
user: currentUser,
251+
adConfig: remoteConfig.adConfig,
252+
imageStyle:
253+
_appBloc.state.settings!.feedPreferences.headlineImageStyle,
254+
adThemeStyle: event.adThemeStyle,
255+
processedContentItemCount: cachedFeed.feedItems
256+
.whereType<Headline>()
257+
.length,
258+
);
258259

259260
_logger.fine(
260261
'Pagination: Appending ${newProcessedFeedItems.length} new items to '
@@ -298,8 +299,9 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
298299

299300
// Apply throttling logic.
300301
if (cachedFeed != null) {
301-
final timeSinceLastRefresh =
302-
DateTime.now().difference(cachedFeed.lastRefreshedAt);
302+
final timeSinceLastRefresh = DateTime.now().difference(
303+
cachedFeed.lastRefreshedAt,
304+
);
303305
if (timeSinceLastRefresh < _refreshThrottleDuration) {
304306
_logger.info(
305307
'Refresh throttled for filter "$filterKey". '
@@ -339,8 +341,9 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
339341

340342
if (cachedHeadlines.isNotEmpty) {
341343
final firstCachedHeadlineId = cachedHeadlines.first.id;
342-
final matchIndex =
343-
newHeadlines.indexWhere((h) => h.id == firstCachedHeadlineId);
344+
final matchIndex = newHeadlines.indexWhere(
345+
(h) => h.id == firstCachedHeadlineId,
346+
);
344347

345348
if (matchIndex != -1) {
346349
// Prepend only the new items found before the match.
@@ -469,25 +472,23 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
469472
if (event.savedFilter != null) {
470473
newActiveFilterId = event.savedFilter!.id;
471474
} else {
472-
final matchingSavedFilter = state.savedFilters.firstWhereOrNull(
473-
(savedFilter) {
474-
final appliedTopics = event.filter.topics?.toSet() ?? {};
475-
final savedTopics = savedFilter.topics.toSet();
476-
final appliedSources = event.filter.sources?.toSet() ?? {};
477-
final savedSources = savedFilter.sources.toSet();
478-
final appliedCountries = event.filter.eventCountries?.toSet() ?? {};
479-
final savedCountries = savedFilter.countries.toSet();
480-
481-
return const SetEquality<Topic>()
482-
.equals(appliedTopics, savedTopics) &&
483-
const SetEquality<Source>()
484-
.equals(appliedSources, savedSources) &&
485-
const SetEquality<Country>().equals(
486-
appliedCountries,
487-
savedCountries,
488-
);
489-
},
490-
);
475+
final matchingSavedFilter = state.savedFilters.firstWhereOrNull((
476+
savedFilter,
477+
) {
478+
final appliedTopics = event.filter.topics?.toSet() ?? {};
479+
final savedTopics = savedFilter.topics.toSet();
480+
final appliedSources = event.filter.sources?.toSet() ?? {};
481+
final savedSources = savedFilter.sources.toSet();
482+
final appliedCountries = event.filter.eventCountries?.toSet() ?? {};
483+
final savedCountries = savedFilter.countries.toSet();
484+
485+
return const SetEquality<Topic>().equals(appliedTopics, savedTopics) &&
486+
const SetEquality<Source>().equals(appliedSources, savedSources) &&
487+
const SetEquality<Country>().equals(
488+
appliedCountries,
489+
savedCountries,
490+
);
491+
});
491492

492493
newActiveFilterId = matchingSavedFilter?.id ?? 'custom';
493494
}

lib/headlines-feed/view/headlines_feed_page.dart

Lines changed: 68 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage>
5353
// A flag ensures this logic runs only once for the widget's lifecycle.
5454
if (!_isInitialFetchDispatched) {
5555
context.read<HeadlinesFeedBloc>().add(
56-
HeadlinesFeedStarted(
57-
adThemeStyle: AdThemeStyle.fromTheme(Theme.of(context)),
58-
),
59-
);
56+
HeadlinesFeedStarted(
57+
adThemeStyle: AdThemeStyle.fromTheme(Theme.of(context)),
58+
),
59+
);
6060
_isInitialFetchDispatched = true;
6161
}
6262
}
@@ -81,10 +81,10 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage>
8181
state.hasMore &&
8282
state.status != HeadlinesFeedStatus.loadingMore) {
8383
context.read<HeadlinesFeedBloc>().add(
84-
HeadlinesFeedFetchRequested(
85-
adThemeStyle: AdThemeStyle.fromTheme(Theme.of(context)),
86-
),
87-
);
84+
HeadlinesFeedFetchRequested(
85+
adThemeStyle: AdThemeStyle.fromTheme(Theme.of(context)),
86+
),
87+
);
8888
}
8989
}
9090

@@ -154,20 +154,20 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage>
154154
return FailureStateWidget(
155155
exception: state.error ?? UnknownException(l10n.unknownError),
156156
onRetry: () => context.read<HeadlinesFeedBloc>().add(
157-
HeadlinesFeedRefreshRequested(
158-
adThemeStyle: AdThemeStyle.fromTheme(theme),
159-
),
160-
),
157+
HeadlinesFeedRefreshRequested(
158+
adThemeStyle: AdThemeStyle.fromTheme(theme),
159+
),
160+
),
161161
);
162162
}
163163

164164
return RefreshIndicator(
165165
onRefresh: () async {
166166
context.read<HeadlinesFeedBloc>().add(
167-
HeadlinesFeedRefreshRequested(
168-
adThemeStyle: AdThemeStyle.fromTheme(theme),
169-
),
170-
);
167+
HeadlinesFeedRefreshRequested(
168+
adThemeStyle: AdThemeStyle.fromTheme(theme),
169+
),
170+
);
171171
},
172172
child: CustomScrollView(
173173
controller: _scrollController,
@@ -206,12 +206,12 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage>
206206
ElevatedButton(
207207
onPressed: () =>
208208
context.read<HeadlinesFeedBloc>().add(
209-
HeadlinesFeedFiltersCleared(
210-
adThemeStyle: AdThemeStyle.fromTheme(
211-
theme,
212-
),
213-
),
209+
HeadlinesFeedFiltersCleared(
210+
adThemeStyle: AdThemeStyle.fromTheme(
211+
theme,
214212
),
213+
),
214+
),
215215
child: Text(l10n.headlinesFeedClearFiltersButton),
216216
),
217217
],
@@ -269,27 +269,27 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage>
269269
headline: item,
270270
onHeadlineTap: () =>
271271
HeadlineTapHandler.handleHeadlineTap(
272-
context,
273-
item,
274-
),
272+
context,
273+
item,
274+
),
275275
);
276276
case HeadlineImageStyle.smallThumbnail:
277277
tile = HeadlineTileImageStart(
278278
headline: item,
279279
onHeadlineTap: () =>
280280
HeadlineTapHandler.handleHeadlineTap(
281-
context,
282-
item,
283-
),
281+
context,
282+
item,
283+
),
284284
);
285285
case HeadlineImageStyle.largeThumbnail:
286286
tile = HeadlineTileImageTop(
287287
headline: item,
288288
onHeadlineTap: () =>
289289
HeadlineTapHandler.handleHeadlineTap(
290-
context,
291-
item,
292-
),
290+
context,
291+
item,
292+
),
293293
);
294294
}
295295
return tile;
@@ -319,25 +319,31 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage>
319319
item: item,
320320
onCallToAction: (url) {
321321
context.read<HeadlinesFeedBloc>().add(
322-
CallToActionTapped(url: url),
323-
);
322+
CallToActionTapped(url: url),
323+
);
324324
},
325325
);
326326
} else if (item is ContentCollectionItem) {
327327
// Access AppBloc to get the user's content preferences,
328328
// which is the source of truth for followed items.
329329
final appState = context.watch<AppBloc>().state;
330330
final followedTopics =
331-
appState.userContentPreferences?.followedTopics ??
332-
[];
333-
final followedSources = appState
334-
.userContentPreferences?.followedSources ??
331+
appState
332+
.userContentPreferences
333+
?.followedTopics ??
334+
[];
335+
final followedSources =
336+
appState
337+
.userContentPreferences
338+
?.followedSources ??
335339
[];
336340

337-
final followedTopicIds =
338-
followedTopics.map((t) => t.id).toList();
339-
final followedSourceIds =
340-
followedSources.map((s) => s.id).toList();
341+
final followedTopicIds = followedTopics
342+
.map((t) => t.id)
343+
.toList();
344+
final followedSourceIds = followedSources
345+
.map((s) => s.id)
346+
.toList();
341347

342348
return ContentCollectionDecoratorWidget(
343349
item: item,
@@ -351,47 +357,48 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage>
351357
UserContentPreferences updatedPreferences;
352358

353359
if (toggledItem is Topic) {
354-
final isCurrentlyFollowing =
355-
followedTopicIds.contains(toggledItem.id);
356-
final newFollowedTopics =
357-
List<Topic>.from(followedTopics);
360+
final isCurrentlyFollowing = followedTopicIds
361+
.contains(toggledItem.id);
362+
final newFollowedTopics = List<Topic>.from(
363+
followedTopics,
364+
);
358365
if (isCurrentlyFollowing) {
359366
newFollowedTopics.removeWhere(
360367
(t) => t.id == toggledItem.id,
361368
);
362369
} else {
363370
newFollowedTopics.add(toggledItem);
364371
}
365-
updatedPreferences =
366-
currentUserPreferences.copyWith(
367-
followedTopics: newFollowedTopics,
368-
);
372+
updatedPreferences = currentUserPreferences
373+
.copyWith(
374+
followedTopics: newFollowedTopics,
375+
);
369376
} else if (toggledItem is Source) {
370-
final isCurrentlyFollowing =
371-
followedSourceIds
372-
.contains(toggledItem.id);
373-
final newFollowedSources =
374-
List<Source>.from(followedSources);
377+
final isCurrentlyFollowing = followedSourceIds
378+
.contains(toggledItem.id);
379+
final newFollowedSources = List<Source>.from(
380+
followedSources,
381+
);
375382
if (isCurrentlyFollowing) {
376383
newFollowedSources.removeWhere(
377384
(s) => s.id == toggledItem.id,
378385
);
379386
} else {
380387
newFollowedSources.add(toggledItem);
381388
}
382-
updatedPreferences =
383-
currentUserPreferences.copyWith(
384-
followedSources: newFollowedSources,
385-
);
389+
updatedPreferences = currentUserPreferences
390+
.copyWith(
391+
followedSources: newFollowedSources,
392+
);
386393
} else {
387394
return;
388395
}
389396

390397
context.read<AppBloc>().add(
391-
AppUserContentPreferencesChanged(
392-
preferences: updatedPreferences,
393-
),
394-
);
398+
AppUserContentPreferencesChanged(
399+
preferences: updatedPreferences,
400+
),
401+
);
395402
},
396403
);
397404
}

lib/router/router.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,7 @@ GoRouter createRouter({
527527
appBloc: appBloc,
528528
inlineAdCacheService: context
529529
.read<InlineAdCacheService>(),
530-
feedCacheService: context
531-
.read<FeedCacheService>(),
530+
feedCacheService: context.read<FeedCacheService>(),
532531
initialUserContentPreferences:
533532
initialUserContentPreferences,
534533
);

0 commit comments

Comments
 (0)