Skip to content

Commit b32640b

Browse files
committed
style: misc
1 parent 25887dc commit b32640b

15 files changed

+284
-220
lines changed

lib/account/bloc/account_bloc.dart

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,36 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
7878
emit(
7979
state.copyWith(status: AccountStatus.success, preferences: preferences),
8080
);
81-
} on NotFoundException { // Specifically handle NotFound
81+
} on NotFoundException {
82+
// Specifically handle NotFound
8283
emit(
8384
state.copyWith(
8485
status: AccountStatus.success, // It's a success, just no data
85-
preferences: UserContentPreferences(id: event.userId), // Provide default/empty
86+
preferences: UserContentPreferences(
87+
id: event.userId,
88+
), // Provide default/empty
8689
),
8790
);
88-
} on HtHttpException catch (e) { // Handle other HTTP errors
91+
} on HtHttpException catch (e) {
92+
// Handle other HTTP errors
8993
emit(
9094
state.copyWith(
9195
status: AccountStatus.failure,
9296
errorMessage: 'Failed to load preferences: ${e.message}',
93-
preferences: UserContentPreferences(id: event.userId), // Provide default
97+
preferences: UserContentPreferences(
98+
id: event.userId,
99+
), // Provide default
94100
),
95101
);
96-
} catch (e) { // Catch-all for other unexpected errors
102+
} catch (e) {
103+
// Catch-all for other unexpected errors
97104
emit(
98105
state.copyWith(
99106
status: AccountStatus.failure,
100107
errorMessage: 'An unexpected error occurred: $e',
101-
preferences: UserContentPreferences(id: event.userId), // Provide default
108+
preferences: UserContentPreferences(
109+
id: event.userId,
110+
), // Provide default
102111
),
103112
);
104113
}
@@ -117,27 +126,37 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
117126
);
118127
return;
119128
}
120-
print('[AccountBloc._persistPreferences] Attempting to persist preferences for user ${state.user!.id}');
121-
print('[AccountBloc._persistPreferences] Preferences to save: ${preferences.toJson()}');
129+
print(
130+
'[AccountBloc._persistPreferences] Attempting to persist preferences for user ${state.user!.id}',
131+
);
132+
print(
133+
'[AccountBloc._persistPreferences] Preferences to save: ${preferences.toJson()}',
134+
);
122135
try {
123136
await _userContentPreferencesRepository.update(
124137
id: state.user!.id, // ID of the preferences object is the user's ID
125138
item: preferences,
126139
userId: state.user!.id,
127140
);
128-
print('[AccountBloc._persistPreferences] Successfully persisted preferences for user ${state.user!.id}');
141+
print(
142+
'[AccountBloc._persistPreferences] Successfully persisted preferences for user ${state.user!.id}',
143+
);
129144
// Optimistic update already done, emit success if needed for UI feedback
130145
// emit(state.copyWith(status: AccountStatus.success));
131146
} on HtHttpException catch (e) {
132-
print('[AccountBloc._persistPreferences] HtHttpException while persisting: ${e.message}');
147+
print(
148+
'[AccountBloc._persistPreferences] HtHttpException while persisting: ${e.message}',
149+
);
133150
emit(
134151
state.copyWith(
135152
status: AccountStatus.failure,
136153
errorMessage: 'Failed to save preferences: ${e.message}',
137154
),
138155
);
139156
} catch (e) {
140-
print('[AccountBloc._persistPreferences] Unknown error while persisting: $e');
157+
print(
158+
'[AccountBloc._persistPreferences] Unknown error while persisting: $e',
159+
);
141160
emit(
142161
state.copyWith(
143162
status: AccountStatus.failure,

lib/account/bloc/available_countries_bloc.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class AvailableCountriesBloc
1212
extends Bloc<AvailableCountriesEvent, AvailableCountriesState> {
1313
AvailableCountriesBloc({
1414
required HtDataRepository<Country> countriesRepository,
15-
}) : _countriesRepository = countriesRepository,
16-
super(const AvailableCountriesState()) {
15+
}) : _countriesRepository = countriesRepository,
16+
super(const AvailableCountriesState()) {
1717
on<FetchAvailableCountries>(_onFetchAvailableCountries);
1818
}
1919

lib/account/bloc/available_countries_state.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class AvailableCountriesState extends Equatable {
3838

3939
@override
4040
List<Object?> get props => [
41-
status,
42-
availableCountries,
43-
error,
44-
// hasMore, // Add if pagination is implemented
45-
// cursor, // Add if pagination is implemented
46-
];
41+
status,
42+
availableCountries,
43+
error,
44+
// hasMore, // Add if pagination is implemented
45+
// cursor, // Add if pagination is implemented
46+
];
4747
}

lib/account/bloc/available_sources_bloc.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ part 'available_sources_state.dart';
1010

1111
class AvailableSourcesBloc
1212
extends Bloc<AvailableSourcesEvent, AvailableSourcesState> {
13-
AvailableSourcesBloc({
14-
required HtDataRepository<Source> sourcesRepository,
15-
}) : _sourcesRepository = sourcesRepository,
16-
super(const AvailableSourcesState()) {
13+
AvailableSourcesBloc({required HtDataRepository<Source> sourcesRepository})
14+
: _sourcesRepository = sourcesRepository,
15+
super(const AvailableSourcesState()) {
1716
on<FetchAvailableSources>(_onFetchAvailableSources);
1817
}
1918

2019
final HtDataRepository<Source> _sourcesRepository;
2120
// Consider adding a limit if the number of sources can be very large.
22-
// static const _sourcesLimit = 50;
21+
// static const _sourcesLimit = 50;
2322

2423
Future<void> _onFetchAvailableSources(
2524
FetchAvailableSources event,
@@ -36,8 +35,8 @@ class AvailableSourcesBloc
3635
// Assuming readAll without parameters fetches all items.
3736
// Add pagination if necessary for very large datasets.
3837
final response = await _sourcesRepository.readAll(
39-
// limit: _sourcesLimit, // Uncomment if pagination is needed
40-
);
38+
// limit: _sourcesLimit, // Uncomment if pagination is needed
39+
);
4140
emit(
4241
state.copyWith(
4342
status: AvailableSourcesStatus.success,

lib/account/bloc/available_sources_state.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class AvailableSourcesState extends Equatable {
3838

3939
@override
4040
List<Object?> get props => [
41-
status,
42-
availableSources,
43-
error,
44-
// hasMore, // Add if pagination is implemented
45-
// cursor, // Add if pagination is implemented
46-
];
41+
status,
42+
availableSources,
43+
error,
44+
// hasMore, // Add if pagination is implemented
45+
// cursor, // Add if pagination is implemented
46+
];
4747
}

lib/account/view/manage_followed_items/categories/add_category_to_follow_page.dart

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ class AddCategoryToFollowPage extends StatelessWidget {
1919
Widget build(BuildContext context) {
2020
final l10n = context.l10n;
2121
return BlocProvider(
22-
create: (context) => CategoriesFilterBloc(
23-
categoriesRepository: context.read<HtDataRepository<Category>>(),
24-
)..add(CategoriesFilterRequested()),
22+
create:
23+
(context) => CategoriesFilterBloc(
24+
categoriesRepository: context.read<HtDataRepository<Category>>(),
25+
)..add(CategoriesFilterRequested()),
2526
child: Scaffold(
26-
appBar: AppBar(
27-
title: Text(l10n.addCategoriesPageTitle),
28-
),
27+
appBar: AppBar(title: Text(l10n.addCategoriesPageTitle)),
2928
body: BlocBuilder<CategoriesFilterBloc, CategoriesFilterState>(
3029
builder: (context, categoriesState) {
3130
if (categoriesState.status == CategoriesFilterStatus.loading) {
@@ -34,15 +33,17 @@ class AddCategoryToFollowPage extends StatelessWidget {
3433
if (categoriesState.status == CategoriesFilterStatus.failure) {
3534
var errorMessage = l10n.categoryFilterError;
3635
if (categoriesState.error is HtHttpException) {
37-
errorMessage = (categoriesState.error! as HtHttpException).message;
36+
errorMessage =
37+
(categoriesState.error! as HtHttpException).message;
3838
} else if (categoriesState.error != null) {
3939
errorMessage = categoriesState.error.toString();
4040
}
4141
return FailureStateWidget(
4242
message: errorMessage,
43-
onRetry: () => context
44-
.read<CategoriesFilterBloc>()
45-
.add(CategoriesFilterRequested()),
43+
onRetry:
44+
() => context.read<CategoriesFilterBloc>().add(
45+
CategoriesFilterRequested(),
46+
),
4647
);
4748
}
4849
if (categoriesState.categories.isEmpty) {
@@ -52,9 +53,11 @@ class AddCategoryToFollowPage extends StatelessWidget {
5253
}
5354

5455
return BlocBuilder<AccountBloc, AccountState>(
55-
buildWhen: (previous, current) =>
56-
previous.preferences?.followedCategories != current.preferences?.followedCategories ||
57-
previous.status != current.status,
56+
buildWhen:
57+
(previous, current) =>
58+
previous.preferences?.followedCategories !=
59+
current.preferences?.followedCategories ||
60+
previous.status != current.status,
5861
builder: (context, accountState) {
5962
final followedCategories =
6063
accountState.preferences?.followedCategories ?? [];
@@ -64,44 +67,49 @@ class AddCategoryToFollowPage extends StatelessWidget {
6467
itemCount: categoriesState.categories.length,
6568
itemBuilder: (context, index) {
6669
final category = categoriesState.categories[index];
67-
final isFollowed = followedCategories
68-
.any((fc) => fc.id == category.id);
70+
final isFollowed = followedCategories.any(
71+
(fc) => fc.id == category.id,
72+
);
6973

7074
return Card(
7175
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
7276
child: ListTile(
73-
leading: category.iconUrl != null &&
74-
Uri.tryParse(category.iconUrl!)?.isAbsolute ==
75-
true
76-
? SizedBox(
77-
width: 36,
78-
height: 36,
79-
child: Image.network(
80-
category.iconUrl!,
81-
fit: BoxFit.contain,
82-
errorBuilder:
83-
(context, error, stackTrace) =>
84-
const Icon(Icons.category_outlined),
85-
),
86-
)
87-
: const Icon(Icons.category_outlined),
77+
leading:
78+
category.iconUrl != null &&
79+
Uri.tryParse(
80+
category.iconUrl!,
81+
)?.isAbsolute ==
82+
true
83+
? SizedBox(
84+
width: 36,
85+
height: 36,
86+
child: Image.network(
87+
category.iconUrl!,
88+
fit: BoxFit.contain,
89+
errorBuilder:
90+
(context, error, stackTrace) =>
91+
const Icon(Icons.category_outlined),
92+
),
93+
)
94+
: const Icon(Icons.category_outlined),
8895
title: Text(category.name),
8996
trailing: IconButton(
90-
icon: isFollowed
91-
? Icon(
92-
Icons.check_circle,
93-
color: Theme.of(context).colorScheme.primary,
94-
)
95-
: const Icon(Icons.add_circle_outline),
96-
tooltip: isFollowed
97-
? l10n.unfollowCategoryTooltip(category.name)
98-
: l10n.followCategoryTooltip(category.name),
97+
icon:
98+
isFollowed
99+
? Icon(
100+
Icons.check_circle,
101+
color:
102+
Theme.of(context).colorScheme.primary,
103+
)
104+
: const Icon(Icons.add_circle_outline),
105+
tooltip:
106+
isFollowed
107+
? l10n.unfollowCategoryTooltip(category.name)
108+
: l10n.followCategoryTooltip(category.name),
99109
onPressed: () {
100110
context.read<AccountBloc>().add(
101-
AccountFollowCategoryToggled(
102-
category: category,
103-
),
104-
);
111+
AccountFollowCategoryToggled(category: category),
112+
);
105113
},
106114
),
107115
),

lib/account/view/manage_followed_items/categories/followed_categories_list_page.dart

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class FollowedCategoriesListPage extends StatelessWidget {
4747
onRetry: () {
4848
if (state.user?.id != null) {
4949
context.read<AccountBloc>().add(
50-
AccountLoadContentPreferencesRequested(
51-
userId: state.user!.id,
52-
),
53-
);
50+
AccountLoadContentPreferencesRequested(
51+
userId: state.user!.id,
52+
),
53+
);
5454
}
5555
},
5656
);
@@ -94,19 +94,22 @@ class FollowedCategoriesListPage extends StatelessWidget {
9494
return Card(
9595
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
9696
child: ListTile(
97-
leading: category.iconUrl != null &&
98-
Uri.tryParse(category.iconUrl!)?.isAbsolute == true
99-
? SizedBox(
100-
width: 36,
101-
height: 36,
102-
child: Image.network(
103-
category.iconUrl!,
104-
fit: BoxFit.contain,
105-
errorBuilder: (context, error, stackTrace) =>
106-
const Icon(Icons.category_outlined),
107-
),
108-
)
109-
: const Icon(Icons.category_outlined),
97+
leading:
98+
category.iconUrl != null &&
99+
Uri.tryParse(category.iconUrl!)?.isAbsolute ==
100+
true
101+
? SizedBox(
102+
width: 36,
103+
height: 36,
104+
child: Image.network(
105+
category.iconUrl!,
106+
fit: BoxFit.contain,
107+
errorBuilder:
108+
(context, error, stackTrace) =>
109+
const Icon(Icons.category_outlined),
110+
),
111+
)
112+
: const Icon(Icons.category_outlined),
110113
title: Text(category.name),
111114
trailing: IconButton(
112115
icon: Icon(
@@ -116,8 +119,8 @@ class FollowedCategoriesListPage extends StatelessWidget {
116119
tooltip: l10n.unfollowCategoryTooltip(category.name),
117120
onPressed: () {
118121
context.read<AccountBloc>().add(
119-
AccountFollowCategoryToggled(category: category),
120-
);
122+
AccountFollowCategoryToggled(category: category),
123+
);
121124
},
122125
),
123126
),

0 commit comments

Comments
 (0)