From 8be275151a733c2c5ba1c23f168f1686a0ef6c36 Mon Sep 17 00:00:00 2001 From: pc Date: Tue, 30 Nov 2021 19:50:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/main.dart | 2 +- lib/src/json_util.dart | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) 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(); } From 5aded4521c9b2e532449fb08ab74ca927199bf2c Mon Sep 17 00:00:00 2001 From: pc Date: Tue, 30 Nov 2021 19:50:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=80=82=E9=85=8DDecimal=202.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/money_util.dart | 2 +- lib/src/num_util.dart | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) 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(); } /// 余数