Skip to content

Commit 9f3cc5a

Browse files
committed
fix(feed_core): display relative dates in the correct language
- Add AppBloc dependency to get the current locale - Format relative dates using the current locale - Simplify some widget code by removing unnecessary braces
1 parent aa4e06c commit 9f3cc5a

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

lib/shared/widgets/feed_core/headline_source_row.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter_bloc/flutter_bloc.dart';
44
import 'package:flutter_news_app_mobile_client_full_source_code/ads/interstitial_ad_manager.dart';
5+
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
56
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
67
import 'package:go_router/go_router.dart';
78
import 'package:timeago/timeago.dart' as timeago;
@@ -12,10 +13,7 @@ import 'package:ui_kit/ui_kit.dart';
1213
/// {@endtemplate}
1314
class HeadlineSourceRow extends StatelessWidget {
1415
/// {@macro headline_source_row}
15-
const HeadlineSourceRow({
16-
required this.headline,
17-
super.key,
18-
});
16+
const HeadlineSourceRow({required this.headline, super.key});
1917

2018
/// The headline data to display.
2119
final Headline headline;
@@ -37,8 +35,12 @@ class HeadlineSourceRow extends StatelessWidget {
3735
final theme = Theme.of(context);
3836
final textTheme = theme.textTheme;
3937
final colorScheme = theme.colorScheme;
38+
final currentLocale = context.watch<AppBloc>().state.locale;
4039

41-
final formattedDate = timeago.format(headline.createdAt);
40+
final formattedDate = timeago.format(
41+
headline.createdAt,
42+
locale: currentLocale.languageCode,
43+
);
4244

4345
final sourceTextStyle = textTheme.bodySmall?.copyWith(
4446
color: colorScheme.onSurfaceVariant,
@@ -75,11 +77,7 @@ class HeadlineSourceRow extends StatelessWidget {
7577
),
7678
),
7779
),
78-
if (formattedDate.isNotEmpty)
79-
Text(
80-
formattedDate,
81-
style: dateTextStyle,
82-
),
80+
if (formattedDate.isNotEmpty) Text(formattedDate, style: dateTextStyle),
8381
],
8482
);
8583
}

0 commit comments

Comments
 (0)