Skip to content

Commit 6a0fd2b

Browse files
authored
Merge pull request #129 from flutter-news-app-full-source-code/refactore/ui-enhancement
Refactore/UI enhancement
2 parents 746d750 + 0769dfa commit 6a0fd2b

File tree

9 files changed

+85
-61
lines changed

9 files changed

+85
-61
lines changed

lib/app/view/app.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ class _AppViewState extends State<_AppView> {
291291
return MaterialApp(
292292
debugShowCheckedModeBanner: false,
293293
theme: lightTheme(
294-
scheme: FlexScheme.material,
294+
scheme: state.flexScheme,
295295
appTextScaleFactor: state.appTextScaleFactor,
296296
appFontWeight: state.appFontWeight,
297297
fontFamily: state.fontFamily,
298298
),
299299
darkTheme: darkTheme(
300-
scheme: FlexScheme.material,
300+
scheme: state.flexScheme,
301301
appTextScaleFactor: state.appTextScaleFactor,
302302
appFontWeight: state.appFontWeight,
303303
fontFamily: state.fontFamily,
@@ -358,13 +358,13 @@ class _AppViewState extends State<_AppView> {
358358
return MaterialApp(
359359
debugShowCheckedModeBanner: false,
360360
theme: lightTheme(
361-
scheme: FlexScheme.material,
361+
scheme: state.flexScheme,
362362
appTextScaleFactor: state.appTextScaleFactor,
363363
appFontWeight: state.appFontWeight,
364364
fontFamily: state.fontFamily,
365365
),
366366
darkTheme: darkTheme(
367-
scheme: FlexScheme.material,
367+
scheme: state.flexScheme,
368368
appTextScaleFactor: state.appTextScaleFactor,
369369
appFontWeight: state.appFontWeight,
370370
fontFamily: state.fontFamily,
@@ -385,13 +385,13 @@ class _AppViewState extends State<_AppView> {
385385
return MaterialApp(
386386
debugShowCheckedModeBanner: false,
387387
theme: lightTheme(
388-
scheme: FlexScheme.material,
388+
scheme: state.flexScheme,
389389
appTextScaleFactor: state.appTextScaleFactor,
390390
appFontWeight: state.appFontWeight,
391391
fontFamily: state.fontFamily,
392392
),
393393
darkTheme: darkTheme(
394-
scheme: FlexScheme.material,
394+
scheme: state.flexScheme,
395395
appTextScaleFactor: state.appTextScaleFactor,
396396
appFontWeight: state.appFontWeight,
397397
fontFamily: state.fontFamily,
@@ -417,13 +417,13 @@ class _AppViewState extends State<_AppView> {
417417
return MaterialApp(
418418
debugShowCheckedModeBanner: false,
419419
theme: lightTheme(
420-
scheme: FlexScheme.material,
420+
scheme: state.flexScheme,
421421
appTextScaleFactor: state.appTextScaleFactor,
422422
appFontWeight: state.appFontWeight,
423423
fontFamily: state.fontFamily,
424424
),
425425
darkTheme: darkTheme(
426-
scheme: FlexScheme.material,
426+
scheme: state.flexScheme,
427427
appTextScaleFactor: state.appTextScaleFactor,
428428
appFontWeight: state.appFontWeight,
429429
fontFamily: state.fontFamily,

lib/entity_details/view/entity_details_page.dart

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,6 @@ class _EntityDetailsViewState extends State<EntityDetailsView> {
156156
appBarTitleText = l10n.detailsPageTitle;
157157
}
158158

159-
final description = state.entity is Topic
160-
? (state.entity! as Topic).description
161-
: state.entity is Source
162-
? (state.entity! as Source).description
163-
: state.entity is Country
164-
? (state.entity! as Country)
165-
.name // Using name as description for country
166-
: null;
167-
168159
final followButton = IconButton(
169160
icon: Icon(
170161
state.isFollowing ? Icons.check_circle : Icons.add_circle_outline,
@@ -191,28 +182,29 @@ class _EntityDetailsViewState extends State<EntityDetailsView> {
191182
children: [
192183
if (entityIconUrl != null)
193184
Padding(
194-
padding: const EdgeInsets.only(right: AppSpacing.sm),
185+
padding: Directionality.of(context) == TextDirection.ltr
186+
? const EdgeInsets.only(right: AppSpacing.md)
187+
: const EdgeInsets.only(left: AppSpacing.md),
195188
child: ClipRRect(
196189
borderRadius: BorderRadius.circular(AppSpacing.xs),
197190
child: Image.network(
198191
entityIconUrl,
199-
width: kToolbarHeight - AppSpacing.lg,
200-
height: kToolbarHeight - AppSpacing.lg,
192+
width: AppSpacing.xxl,
193+
height: AppSpacing.xxl,
201194
fit: BoxFit.contain,
202-
errorBuilder: (context, error, stackTrace) => Icon(
203-
appBarIconData ?? Icons.info_outline,
204-
size: kToolbarHeight - AppSpacing.xl,
205-
color: colorScheme.onSurfaceVariant,
206-
),
195+
errorBuilder: (context, error, stackTrace) =>
196+
const SizedBox(),
207197
),
208198
),
209199
)
210-
else if (appBarIconData != null)
200+
else if (state.entity is Source && appBarIconData != null)
211201
Padding(
212-
padding: const EdgeInsets.only(right: AppSpacing.sm),
202+
padding: Directionality.of(context) == TextDirection.ltr
203+
? const EdgeInsets.only(right: AppSpacing.md)
204+
: const EdgeInsets.only(left: AppSpacing.md),
213205
child: Icon(
214206
appBarIconData,
215-
size: kToolbarHeight - AppSpacing.xl,
207+
size: AppSpacing.xxl,
216208
color: colorScheme.onSurface,
217209
),
218210
),
@@ -251,33 +243,6 @@ class _EntityDetailsViewState extends State<EntityDetailsView> {
251243
const SizedBox(width: AppSpacing.sm),
252244
],
253245
),
254-
SliverPadding(
255-
padding: const EdgeInsets.all(AppSpacing.paddingMedium),
256-
sliver: SliverList(
257-
delegate: SliverChildListDelegate([
258-
if (description != null && description.isNotEmpty) ...[
259-
Text(
260-
description,
261-
style: textTheme.bodyLarge?.copyWith(
262-
color: colorScheme.onSurfaceVariant,
263-
height: 1.5,
264-
),
265-
),
266-
const SizedBox(height: AppSpacing.lg),
267-
],
268-
if (state.feedItems.isNotEmpty ||
269-
state.status == EntityDetailsStatus.loadingMore) ...[
270-
Text(
271-
l10n.headlinesSectionTitle,
272-
style: textTheme.titleLarge?.copyWith(
273-
fontWeight: FontWeight.bold,
274-
),
275-
),
276-
const Divider(height: AppSpacing.lg, thickness: 1),
277-
],
278-
]),
279-
),
280-
),
281246
if (state.feedItems.isEmpty &&
282247
state.status != EntityDetailsStatus.initial &&
283248
state.status != EntityDetailsStatus.loadingMore &&
@@ -299,8 +264,10 @@ class _EntityDetailsViewState extends State<EntityDetailsView> {
299264
)
300265
else
301266
SliverPadding(
302-
padding: const EdgeInsets.symmetric(
303-
horizontal: AppSpacing.paddingMedium,
267+
padding: const EdgeInsets.only(
268+
top: AppSpacing.paddingMedium,
269+
left: AppSpacing.paddingMedium,
270+
right: AppSpacing.paddingMedium,
304271
),
305272
sliver: SliverList.separated(
306273
itemCount:

lib/l10n/app_localizations.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,18 @@ abstract class AppLocalizations {
16931693
/// In en, this message translates to:
16941694
/// **'Loading Filters'**
16951695
String get headlinesFeedFilterLoadingHeadline;
1696+
1697+
/// Title for the suggested topics content collection.
1698+
///
1699+
/// In en, this message translates to:
1700+
/// **'Suggested Topics'**
1701+
String get suggestedTopicsTitle;
1702+
1703+
/// Title for the suggested sources content collection.
1704+
///
1705+
/// In en, this message translates to:
1706+
/// **'Suggested Sources'**
1707+
String get suggestedSourcesTitle;
16961708
}
16971709

16981710
class _AppLocalizationsDelegate

lib/l10n/app_localizations_ar.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,4 +883,10 @@ class AppLocalizationsAr extends AppLocalizations {
883883

884884
@override
885885
String get headlinesFeedFilterLoadingHeadline => 'جاري تحميل الفلاتر';
886+
887+
@override
888+
String get suggestedTopicsTitle => 'مواضيع مقترحة';
889+
890+
@override
891+
String get suggestedSourcesTitle => 'مصادر مقترحة';
886892
}

lib/l10n/app_localizations_en.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,4 +885,10 @@ class AppLocalizationsEn extends AppLocalizations {
885885

886886
@override
887887
String get headlinesFeedFilterLoadingHeadline => 'Loading Filters';
888+
889+
@override
890+
String get suggestedTopicsTitle => 'Suggested Topics';
891+
892+
@override
893+
String get suggestedSourcesTitle => 'Suggested Sources';
888894
}

lib/l10n/arb/app_ar.arb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,5 +1152,13 @@
11521152
"headlinesFeedFilterLoadingHeadline": "جاري تحميل الفلاتر",
11531153
"@headlinesFeedFilterLoadingHeadline": {
11541154
"description": "Headline for the loading state when fetching filter options on the headlines filter page."
1155+
},
1156+
"suggestedTopicsTitle": "مواضيع مقترحة",
1157+
"@suggestedTopicsTitle": {
1158+
"description": "عنوان لمجموعة المواضيع المقترحة."
1159+
},
1160+
"suggestedSourcesTitle": "مصادر مقترحة",
1161+
"@suggestedSourcesTitle": {
1162+
"description": "عنوان لمجموعة المصادر المقترحة."
11551163
}
11561164
}

lib/l10n/arb/app_en.arb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,5 +1152,13 @@
11521152
"headlinesFeedFilterLoadingHeadline": "Loading Filters",
11531153
"@headlinesFeedFilterLoadingHeadline": {
11541154
"description": "Headline for the loading state when fetching filter options on the headlines filter page."
1155+
},
1156+
"suggestedTopicsTitle": "Suggested Topics",
1157+
"@suggestedTopicsTitle": {
1158+
"description": "Title for the suggested topics content collection."
1159+
},
1160+
"suggestedSourcesTitle": "Suggested Sources",
1161+
"@suggestedSourcesTitle": {
1162+
"description": "Title for the suggested sources content collection."
11551163
}
11561164
}

lib/shared/widgets/feed_decorators/content_collection_decorator_widget.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ class ContentCollectionDecoratorWidget extends StatelessWidget {
4343
final l10n = AppLocalizationsX(context).l10n;
4444
final theme = Theme.of(context);
4545

46+
String getTitle() {
47+
switch (item.decoratorType) {
48+
case FeedDecoratorType.suggestedTopics:
49+
return l10n.suggestedTopicsTitle;
50+
case FeedDecoratorType.suggestedSources:
51+
return l10n.suggestedSourcesTitle;
52+
// The following cases are for call-to-action types and should not
53+
// appear in a content collection, but we handle them gracefully.
54+
case FeedDecoratorType.linkAccount:
55+
case FeedDecoratorType.upgrade:
56+
case FeedDecoratorType.rateApp:
57+
case FeedDecoratorType.enableNotifications:
58+
return item.title;
59+
}
60+
}
61+
4662
return Card(
4763
margin: const EdgeInsets.symmetric(
4864
horizontal: AppSpacing.lg,
@@ -58,7 +74,7 @@ class ContentCollectionDecoratorWidget extends StatelessWidget {
5874
children: [
5975
Expanded(
6076
child: Text(
61-
item.title,
77+
getTitle(),
6278
style: theme.textTheme.titleLarge,
6379
maxLines: 1,
6480
overflow: TextOverflow.ellipsis,

lib/shared/widgets/feed_decorators/suggestion_item_widget.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class SuggestionItemWidget extends StatelessWidget {
5151
}
5252

5353
return Card(
54+
color: theme.colorScheme.surfaceVariant,
5455
margin: const EdgeInsets.symmetric(horizontal: AppSpacing.sm),
5556
child: SizedBox(
5657
width: 160,
@@ -64,7 +65,7 @@ class SuggestionItemWidget extends StatelessWidget {
6465
width: 64,
6566
height: 64,
6667
decoration: BoxDecoration(
67-
color: theme.colorScheme.surfaceVariant,
68+
color: theme.colorScheme.surface,
6869
borderRadius: BorderRadius.circular(AppSpacing.sm),
6970
),
7071
child: imageUrl.isNotEmpty
@@ -75,14 +76,14 @@ class SuggestionItemWidget extends StatelessWidget {
7576
fit: BoxFit.cover,
7677
errorBuilder: (context, error, stackTrace) => Icon(
7778
Icons.broken_image,
78-
color: theme.colorScheme.onSurfaceVariant,
79+
color: theme.colorScheme.onSurface,
7980
),
8081
),
8182
)
8283
: Icon(
8384
// Use a more specific icon for sources as a fallback.
8485
item is Source ? Icons.source : Icons.category,
85-
color: theme.colorScheme.onSurfaceVariant,
86+
color: theme.colorScheme.onSurface,
8687
),
8788
),
8889
const SizedBox(height: AppSpacing.md),

0 commit comments

Comments
 (0)