diff --git a/example/lib/main.dart b/example/lib/main.dart index 29ee067..23faaa7 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -139,7 +139,7 @@ void main() { LogUtil.e("TimerTick: " + value.toString()); }); timerUtil.startTimer(); - if (timerUtil != null) timerUtil.cancel(); //dispose() + timerUtil.cancel(); //dispose() TimerUtil timerCountDown; //倒计时test diff --git a/lib/src/json_util.dart b/lib/src/json_util.dart index b10b5a8..6ecf85f 100644 --- a/lib/src/json_util.dart +++ b/lib/src/json_util.dart @@ -18,7 +18,7 @@ class JsonUtil { static T? getObj(String? source, T f(Map v)) { if (source == null || source.isEmpty) return null; try { - Map map = json.decode(source); + Map map = json.decode(source) as Map; return f(map); } catch (e) { print('JsonUtil convert error, Exception:${e.toString()}'); @@ -32,9 +32,9 @@ class JsonUtil { try { Map map; if (source is String) { - map = json.decode(source); + map = json.decode(source) as Map; } else { - map = source; + map = source as Map; } return f(map); } catch (e) { @@ -47,12 +47,12 @@ class JsonUtil { static List? getObjList(String? source, T f(Map v)) { if (source == null || source.isEmpty) return null; try { - List list = json.decode(source); - return list.map((value) { + List list = json.decode(source) as List; + return list.map((dynamic value) { if (value is String) { value = json.decode(value); } - return f(value); + return f(value as Map); }).toList(); } catch (e) { print('JsonUtil convert error, Exception:${e.toString()}'); @@ -66,15 +66,15 @@ class JsonUtil { try { List list; if (source is String) { - list = json.decode(source); + list = json.decode(source) as List; } else { - list = source; + list = source as List; } - return list.map((value) { + return list.map((dynamic value) { if (value is String) { value = json.decode(value); } - return f(value); + return f(value as Map); }).toList(); } catch (e) { print('JsonUtil convert error, Exception:${e.toString()}'); @@ -88,11 +88,11 @@ class JsonUtil { static List? getList(dynamic source) { List? list; if (source is String) { - list = json.decode(source); + list = json.decode(source) as List; } else { - list = source; + list = source as List; } - return list?.map((v) { + return list.map((dynamic v) { return v as T; }).toList(); } diff --git a/lib/src/money_util.dart b/lib/src/money_util.dart index 2f6b398..2da7e9c 100644 --- a/lib/src/money_util.dart +++ b/lib/src/money_util.dart @@ -84,7 +84,7 @@ class MoneyUtil { /// yuan to fen. /// 元 转 分, static int changeY2F(Object yuan) { - return NumUtil.multiplyDecStr(yuan.toString(), '100').toInt(); + return NumUtil.multiplyDecStr(yuan.toString(), '100').toBigInt().toInt(); } /// with unit. diff --git a/lib/src/num_util.dart b/lib/src/num_util.dart index 84ed4ef..3b9b5e7 100644 --- a/lib/src/num_util.dart +++ b/lib/src/num_util.dart @@ -1,4 +1,5 @@ import 'package:decimal/decimal.dart'; +import 'package:rational/rational.dart'; /** * @Author: Sky24n @@ -131,7 +132,8 @@ class NumUtil { /// 除 static Decimal divideDecStr(String a, String b) { - return Decimal.parse(a) / Decimal.parse(b); + Rational value = Decimal.parse(a) / Decimal.parse(b); + return value.toDecimal(); } /// 余数