Commit 7d417b0451b36a787cb66be9e1bf1c7cc5d9fe1d
1 parent
60c14061
feat:fix用户vip到期日问题
Showing
2 changed files
with
17 additions
and
1 deletions
lib/models/user_entity.dart
@@ -68,6 +68,22 @@ class UserEntity { | @@ -68,6 +68,22 @@ class UserEntity { | ||
68 | return valid ?? false; | 68 | return valid ?? false; |
69 | } | 69 | } |
70 | 70 | ||
71 | + // 计算用户vip到期日 | ||
72 | + String? getEffectiveDate() { | ||
73 | + if (effectiveDate == null) { | ||
74 | + return null; | ||
75 | + } | ||
76 | + DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(int.parse(effectiveDate!)); | ||
77 | + // 获取年、月、日 | ||
78 | + String year = dateTime.year.toString(); | ||
79 | + String month = dateTime.month.toString().padLeft(2, '0'); // 如果月份是个位数,则在前面加上0,使其两位数 | ||
80 | + String day = dateTime.day.toString().padLeft(2, '0'); // 如果日期是个位数,则在前面加上0,使其两位数 | ||
81 | + | ||
82 | + // 拼接成日期字符串 | ||
83 | + String formattedDate = '$year-$month-$day'; | ||
84 | + return formattedDate; | ||
85 | + } | ||
86 | + | ||
71 | UserEntity copyWith({ | 87 | UserEntity copyWith({ |
72 | int? id, | 88 | int? id, |
73 | String? name, | 89 | String? name, |
lib/pages/user/user_page.dart
@@ -114,7 +114,7 @@ class _UserView extends StatelessWidget { | @@ -114,7 +114,7 @@ class _UserView extends StatelessWidget { | ||
114 | child: Row( | 114 | child: Row( |
115 | children: [ | 115 | children: [ |
116 | Text( | 116 | Text( |
117 | - "${user.effectiveDate} 到期", | 117 | + "${user.getEffectiveDate()} 到期", |
118 | style: TextStyle( | 118 | style: TextStyle( |
119 | color: const Color(0xFFE11212), | 119 | color: const Color(0xFFE11212), |
120 | fontSize: 17.sp, | 120 | fontSize: 17.sp, |