Skip to content

Commit 384c157

Browse files
committed
refactor: avoid using dynamic in class Utils as much as possible
1 parent 37c0d8d commit 384c157

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

lib/utils/utils.dart

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Utils {
6464
return Uri.https('www.coolapk1s.com', '${type.name}/$id');
6565
}
6666

67-
static void report(dynamic id, ReportType reportType) {
67+
static void report(String id, ReportType reportType) {
6868
String c = reportType == ReportType.User ? 'user' : 'feed';
6969
String type = switch (reportType) {
7070
ReportType.Feed => '&type=feed',
@@ -311,13 +311,11 @@ class Utils {
311311
}
312312
}
313313

314-
static String numFormat(dynamic number) {
314+
static String numFormat(num number) {
315315
if (number == null) {
316316
return '0';
317317
}
318-
if (number is String) {
319-
return number;
320-
}
318+
321319
final String res = (number / 10000).toString();
322320
if (int.parse(res.split('.')[0]) >= 1) {
323321
return '${(number / 10000).toStringAsFixed(1)}万';
@@ -326,11 +324,8 @@ class Utils {
326324
}
327325
}
328326

329-
static String timeFormat(dynamic time) {
327+
static String timeFormat(int time) {
330328
// 1小时内
331-
if (time is String && time.contains(':')) {
332-
return time;
333-
}
334329
if (time < 3600) {
335330
if (time == 0) {
336331
return '00:00';
@@ -424,8 +419,8 @@ class Utils {
424419
String timeStr =
425420
(DateTime.fromMillisecondsSinceEpoch(timestamp * 1000)).toString();
426421

427-
dynamic dateArr = timeStr.split(' ')[0];
428-
dynamic timeArr = timeStr.split(' ')[1];
422+
var dateArr = timeStr.split(' ')[0];
423+
var timeArr = timeStr.split(' ')[1];
429424

430425
var [year, month, day] = dateArr.split('-');
431426
var [hour, minute, second] = timeArr.split(':');

0 commit comments

Comments
 (0)