@@ -34,15 +34,15 @@ import 'package:url_launcher/url_launcher.dart';
3434typedef StringList = List <String >;
3535
3636class CommonUtils {
37- static final double MILLIS_LIMIT = 1000.0 ;
37+ static const double MILLIS_LIMIT = 1000.0 ;
3838
39- static final double SECONDS_LIMIT = 60 * MILLIS_LIMIT ;
39+ static const double SECONDS_LIMIT = 60 * MILLIS_LIMIT ;
4040
41- static final double MINUTES_LIMIT = 60 * SECONDS_LIMIT ;
41+ static const double MINUTES_LIMIT = 60 * SECONDS_LIMIT ;
4242
43- static final double HOURS_LIMIT = 24 * MINUTES_LIMIT ;
43+ static const double HOURS_LIMIT = 24 * MINUTES_LIMIT ;
4444
45- static final double DAYS_LIMIT = 30 * HOURS_LIMIT ;
45+ static const double DAYS_LIMIT = 30 * HOURS_LIMIT ;
4646
4747 static Locale ? curLocale;
4848
@@ -66,44 +66,38 @@ class CommonUtils {
6666 static String getNewsTimeStr (DateTime date) {
6767 int subTimes =
6868 DateTime .now ().millisecondsSinceEpoch - date.millisecondsSinceEpoch;
69-
70- if (subTimes < MILLIS_LIMIT ) {
71- return (curLocale != null )
69+ return switch (subTimes) {
70+ < MILLIS_LIMIT => (curLocale != null )
7271 ? (curLocale! .languageCode != "zh" )
7372 ? "right now"
7473 : "刚刚"
75- : "刚刚" ;
76- } else if (subTimes < SECONDS_LIMIT ) {
77- return (subTimes / MILLIS_LIMIT ).round ().toString () +
74+ : "刚刚" ,
75+ < SECONDS_LIMIT => (subTimes / MILLIS_LIMIT ).round ().toString () +
7876 ((curLocale != null )
7977 ? (curLocale! .languageCode != "zh" )
8078 ? " seconds ago"
8179 : " 秒前"
82- : " 秒前" );
83- } else if (subTimes < MINUTES_LIMIT ) {
84- return (subTimes / SECONDS_LIMIT ).round ().toString () +
80+ : " 秒前" ),
81+ < MINUTES_LIMIT => (subTimes / SECONDS_LIMIT ).round ().toString () +
8582 ((curLocale != null )
8683 ? (curLocale! .languageCode != "zh" )
8784 ? " min ago"
8885 : " 分钟前"
89- : " 分钟前" );
90- } else if (subTimes < HOURS_LIMIT ) {
91- return (subTimes / MINUTES_LIMIT ).round ().toString () +
86+ : " 分钟前" ),
87+ < HOURS_LIMIT => (subTimes / MINUTES_LIMIT ).round ().toString () +
9288 ((curLocale != null )
9389 ? (curLocale! .languageCode != "zh" )
9490 ? " hours ago"
9591 : " 小时前"
96- : " 小时前" );
97- } else if (subTimes < DAYS_LIMIT ) {
98- return (subTimes / HOURS_LIMIT ).round ().toString () +
92+ : " 小时前" ),
93+ < DAYS_LIMIT => (subTimes / HOURS_LIMIT ).round ().toString () +
9994 ((curLocale != null )
10095 ? (curLocale! .languageCode != "zh" )
10196 ? " days ago"
10297 : " 天前"
103- : " 天前" );
104- } else {
105- return getDateStr (date);
106- }
98+ : " 天前" ),
99+ _ => getDateStr (date)
100+ };
107101 }
108102
109103 static getLocalPath () async {
@@ -326,18 +320,21 @@ class CommonUtils {
326320
327321 if (parseUrl.host == "github.com" && parseUrl.path.length > 0 ) {
328322 StringList pathnames = parseUrl.path.split ("/" );
329- if (pathnames.length == 2 ) {
330- //解析人
331- String userName = pathnames[1 ];
332- NavigatorUtils .goPerson (context, userName);
333- } else if (pathnames.length >= 3 ) {
334- //解析仓库
335- if (pathnames.length == 3 ) {
336- var [_, userName, repoName] = pathnames;
337- NavigatorUtils .goReposDetail (context, userName, repoName);
338- } else {
339- launchWebView (context, "" , url);
340- }
323+ switch (pathnames.length) {
324+ case == 2 :
325+ //解析人
326+ String userName = pathnames[1 ];
327+ NavigatorUtils .goPerson (context, userName);
328+ break ;
329+ case >= 3 :
330+ //解析仓库
331+ if (pathnames.length == 3 ) {
332+ var [_, userName, repoName] = pathnames;
333+ NavigatorUtils .goReposDetail (context, userName, repoName);
334+ } else {
335+ launchWebView (context, "" , url);
336+ }
337+ break ;
341338 }
342339 } else if (url.startsWith ("http" )) {
343340 launchWebView (context, "" , url);
0 commit comments