From a28270ee22380c1add25a883d82ee58bc1681420 Mon Sep 17 00:00:00 2001 From: Sang-oh Kim Date: Wed, 13 Mar 2024 15:29:41 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EC=B5=9C=EC=83=81=EB=8B=A8=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EB=82=A0=EC=A7=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 항상 '오늘'로 표시되는 것이 아니라 알림의 날짜를 확인하고 실제로 오늘과 같을 시에만 오늘로 표시되도록 변경. --- lib/pages/notification_page.dart | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/pages/notification_page.dart b/lib/pages/notification_page.dart index b1f20922..8ca95ad9 100644 --- a/lib/pages/notification_page.dart +++ b/lib/pages/notification_page.dart @@ -262,9 +262,9 @@ class _NotificationPageState extends State { : SizedBox( height: 35, child: Text( - LocaleKeys - .notificationPage_today - .tr(), + getFormattedDate( + _modelList[0].created_at, + context.locale), style: const TextStyle( fontSize: 14, fontWeight: FontWeight.w500, @@ -460,7 +460,8 @@ class _NotificationPageState extends State { _setIsLoadingTotal(false); } } else { - requestInfoSnackBar(LocaleKeys.notificationPage_allNotificationsChecked.tr()); + requestInfoSnackBar( + LocaleKeys.notificationPage_allNotificationsChecked.tr()); } }, backgroundColor: Colors.white, @@ -481,6 +482,29 @@ class _NotificationPageState extends State { ); } + /// 가장 상단 알림의 날짜 출력을 위해 사용됨. + String getFormattedDate(String dateTimeStr, Locale locale) { + DateTime targetDateTime = DateTime.parse(dateTimeStr).toLocal(); + final now = DateTime.now(); + final today = DateTime(now.year, now.month, now.day); + if (targetDateTime.year == today.year && + targetDateTime.month == today.month && + targetDateTime.day == today.day) { + return LocaleKeys.notificationPage_today.tr(); + } else { + String dateTextInKorean = + "${(targetDateTime.year != now.year ? "${targetDateTime.year}년 " : "")}${targetDateTime.month}월 ${targetDateTime.day}일"; + + String dateTextInEnglish = DateFormat( + "MMMM d${targetDateTime.year != now.year ? ", yyyy" : ""}", + "en_US") + .format(targetDateTime); + return (locale == const Locale('ko') + ? dateTextInKorean + : dateTextInEnglish); + } + } + /// 현재 date와 알림 생성 date의 차이를 계산하여 문자열로 변경해줌. Widget _buildDateInfo(String strDate1, String strDate2) { DateTime now = DateTime.now();