Dart common utils library. DateUtil, EncryptUtil, JsonUtil, LogUtil, MoneyUtil, NumUtil, ObjectUtil, RegexUtil, TextUtil, TimelineUtil, TimerUtil.

Last update: May 26, 2022

Language: English | 中文简体

Pub      Pub

Dart常用工具类库。包含日期,正则,倒计时,时间轴等工具类。如果你有好的工具类欢迎PR.

1、如果您是纯Dart项目,可以直接引用本库。

dependencies:
  common_utils: ^2.0.2

2、如果您是Flutter项目,请使用Flutter常用工具类库 flustars,该库依赖于本项目。flustars库为大家提供更多的工具类,例如SpUtil,ScreenUtil, DirectoryUtil等等。

dependencies:
  flustars: ^2.0.1  

Dart常用工具类库 common_utils

  1. TimelineUtil : 时间轴.
  2. TimerUtil : 倒计时,定时任务.
  3. MoneyUtil : 精确转换,元转分,分转元,支持格式输出.
  4. LogUtil : 简单封装打印日志.
  5. DateUtil : 日期转换格式化输出.
  6. RegexUtil : 正则验证手机号,身份证,邮箱等等.
  7. NumUtil : 保留x位小数, 精确加、减、乘、除, 防止精度丢失.
  8. ObjectUtil : 判断对象是否为空(String List Map),判断两个List是否相等.
  9. EncryptUtil : 异或对称加/解密,md5加密,Base64加/解密.
  10. TextUtil : 银行卡号每隔4位加空格,每隔3三位加逗号,隐藏手机号等等.
  11. JsonUtil : 简单封装json字符串转对象.

Flutter常用工具类库 flustars

  1. SpUtil : 单例"同步"SharedPreferences工具类。支持get传入默认值,支持存储对象,支持存储对象数组。
  2. ScreenUtil : 屏幕适配,获取屏幕宽、高、密度,AppBar高,状态栏高度,屏幕方向.
  3. WidgetUtil : 监听Widget渲染状态,获取Widget宽高,在屏幕上的坐标,获取网络/本地图片尺寸.
  4. ImageUtil : 获取网络/本地图片尺寸.
  5. DirectoryUtil : 文件目录工具类.
  6. DioUtil : 单例Dio网络工具类(已迁移至此处DioUtil)。

APIs

  • SpUtil 强大易用的SharedPreferences工具类,详细使用请参考原仓库flustars
City.fromJson(v)); print("City: " + (hisCity == null ? "null" : hisCit.toString())); /// 存储实体对象list示例。 List list = new List(); list.add(new City(name: "成都市")); list.add(new City(name: "北京市")); SpUtil.putObjectList("loc_city_list", list); List _cityList = SpUtil.getObjList("loc_city_list", (v) => City.fromJson(v)); print("City list: " + (_cityList == null ? "null" : _cityList.toString()));">
/// 等待Sp初始化完成。
await SpUtil.getInstance();  
  
/// 同步使用Sp。支付默认值。
String name = SpUtil.putString("key_username", "Sky24n");
bool isShow = SpUtil.getBool("key_show", defValue: true);
  
/// 存储实体对象示例。
City city = new City();
city.name = "成都市";
SpUtil.putObject("loc_city", city);
    
City hisCity = SpUtil.getObj("loc_city", (v) => City.fromJson(v));
print("City: " + (hisCity == null ? "null" : hisCit.toString()));
  
/// 存储实体对象list示例。
List<City> list = new List();
list.add(new City(name: "成都市"));
list.add(new City(name: "北京市"));
SpUtil.putObjectList("loc_city_list", list);
    
List<City> _cityList = SpUtil.getObjList("loc_city_list", (v) => City.fromJson(v));
print("City list: " + (_cityList == null ? "null" : _cityList.toString()));
yyyy/yy month -> MM/M day -> dd/d /// hour -> HH/H minute -> mm/m second -> ss/s class DataFormats { static String full = "yyyy-MM-dd HH:mm:ss"; static String y_mo_d_h_m = "yyyy-MM-dd HH:mm"; static String y_mo_d = "yyyy-MM-dd"; static String y_mo = "yyyy-MM"; static String mo_d = "MM-dd"; static String mo_d_h_m = "MM-dd HH:mm"; static String h_m_s = "HH:mm:ss"; static String h_m = "HH:mm"; static String zh_full = "yyyy年MM月dd日 HH时mm分ss秒"; static String zh_y_mo_d_h_m = "yyyy年MM月dd日 HH时mm分"; static String zh_y_mo_d = "yyyy年MM月dd日"; static String zh_y_mo = "yyyy年MM月"; static String zh_mo_d = "MM月dd日"; static String zh_mo_d_h_m = "MM月dd日 HH时mm分"; static String zh_h_m_s = "HH时mm分ss秒"; static String zh_h_m = "HH时mm分"; } getDateTimeByMs : . getDateMsByTimeStr : . getNowDateMs : 获取现在 毫秒. getNowDateStr : 获取现在 日期字符串.(yyyy-MM-dd HH:mm:ss) formatDate : 格式化日期 DateTime. formatDateStr : 格式化日期 字符串. formatDateMs : 格式化日期 毫秒. getWeekday : 获取星期几. getDayOfYear : 在今年的第几天. isToday : 是否是今天. isYesterday : 是否是昨天. isWeek : 是否是本周. yearIsEqual : 是否同年. isLeapYear : 是否是闰年. // example DateUtil.formatDateMs(dateMs, format: DateFormats.full); //2019-07-09 16:16:16 DateUtil.formatDateStr('2019-07-09 16:16:16', format: "yyyy/M/d HH:mm:ss"); //2019/7/9 16:16:16 DateUtil.formatDate(DateTime.now(), format: DateFormats.zh_full); //2019年07月09日 16时16分16秒">
/// 一些常用格式参照。可以自定义格式,例如:"yyyy/MM/dd HH:mm:ss","yyyy/M/d HH:mm:ss"。
/// 格式要求
/// year -> yyyy/yy   month -> MM/M    day -> dd/d
/// hour -> HH/H      minute -> mm/m   second -> ss/s
class DataFormats {
  static String full = "yyyy-MM-dd HH:mm:ss";
  static String y_mo_d_h_m = "yyyy-MM-dd HH:mm";
  static String y_mo_d = "yyyy-MM-dd";
  static String y_mo = "yyyy-MM";
  static String mo_d = "MM-dd";
  static String mo_d_h_m = "MM-dd HH:mm";
  static String h_m_s = "HH:mm:ss";
  static String h_m = "HH:mm";

  static String zh_full = "yyyy年MM月dd日 HH时mm分ss秒";
  static String zh_y_mo_d_h_m = "yyyy年MM月dd日 HH时mm分";
  static String zh_y_mo_d = "yyyy年MM月dd日";
  static String zh_y_mo = "yyyy年MM月";
  static String zh_mo_d = "MM月dd日";
  static String zh_mo_d_h_m = "MM月dd日 HH时mm分";
  static String zh_h_m_s = "HH时mm分ss秒";
  static String zh_h_m = "HH时mm分";
}

getDateTimeByMs                 : .
getDateMsByTimeStr              : .
getNowDateMs                    : 获取现在 毫秒.
getNowDateStr                   : 获取现在 日期字符串.(yyyy-MM-dd HH:mm:ss)
formatDate                      : 格式化日期 DateTime.
formatDateStr                   : 格式化日期 字符串.
formatDateMs                    : 格式化日期 毫秒.
getWeekday                      : 获取星期几.
getDayOfYear                    : 在今年的第几天.
isToday                         : 是否是今天.
isYesterday                     : 是否是昨天.
isWeek                          : 是否是本周.
yearIsEqual                     : 是否同年.
isLeapYear                      : 是否是闰年.

// example
DateUtil.formatDateMs(dateMs, format: DateFormats.full); //2019-07-09 16:16:16
DateUtil.formatDateStr('2019-07-09 16:16:16', format: "yyyy/M/d HH:mm:ss"); //2019/7/9 16:16:16
DateUtil.formatDate(DateTime.now(), format: DateFormats.zh_full); //2019年07月09日 16时16分16秒
  • EncryptUtil
encodeMd5                   : md5 加密.
encodeBase64                : Base64加密.
decodeBase64()              : Base64解密.
xorCode()                   : 异或对称加密.
xorBase64Encode()           : 异或对称 Base64 加密.
xorBase64Decode()           : 异或对称 Base64 解密.

const String key = '11, 22, 33, 44, 55, 66';
String userName = 'Sky24n';
String encode = EncryptUtil.xorBase64Encode(userName, key); // WH1YHgMs
String decode = EncryptUtil.xorBase64Decode(encode, key); // Sky24n
  • JsonUtil
City.fromJson(v)); String listStr = "[{\"name\":\"成都市\"}, {\"name\":\"北京市\"}]"; List cityList = JsonUtil.getObjList(listStr, (v) => City.fromJson(v));">
encodeObj                   : object to json string.
getObj                      : json string to object.
getObject                   : json string / map to object.
getObjList                  : json string list to object list.
getObjectList               : json string / map list to object list.

String objStr = "{\"name\":\"成都市\"}";
City hisCity = JsonUtil.getObj(objStr, (v) => City.fromJson(v));
String listStr = "[{\"name\":\"成都市\"}, {\"name\":\"北京市\"}]";
List
    
      cityList = JsonUtil.getObjList(listStr, (v) => City.fromJson(v));

    
  • LogUtil
init(tag, isDebug, maxLen)  : tag 标签, isDebug: 模式, maxLen 每行最大长度.
e(object, tag)              : 日志e
v(object, tag)              : 日志v,只在debug模式输出.

//超长log查看
common_utils e  — — — — — — — — — — — — — — — — st — — — — — — — — — — — — — — — —
common_utils e | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,
common_utils e | 7,988,989,990,991,992,993,994,995,996,997,998,999,
common_utils e  — — — — — — — — — — — — — — — — ed — — — — — — — — — — — — — — — —
  • MoneyUtil 精确转换,防止精度丢失 -> Example
changeF2Y                   : 分 转 元, format格式输出.
changeFStr2YWithUnit        : 分字符串 转 元, format 与 unit 格式 输出.
changeF2YWithUnit           : 分 转 元, format 与 unit 格式 输出.
changeYWithUnit             : 元, format 与 unit 格式 输出.
changeY2F                   : 元 转 分. 
getIntByValueStr            : 数字字符串转int.
getDoubleByValueStr         : 数字字符串转double.
getNumByValueStr            : 保留x位小数 by 数字字符串.
getNumByValueDouble         : 保留x位小数 by double.
isZero                      : 是否为0.
add                         : 加(精确相加,防止精度丢失).
subtract                    : 减(精确相减,防止精度丢失).
multiply                    : 乘(精确相乘,防止精度丢失).
divide                      : 除(精确相除,防止精度丢失).
remainder                   : 余.
lessThan                    : < .
thanOrEqual                 : <= .
greaterThan                 : > .
greaterOrEqual              : >= .
isEmptyString             : 判断String是否为空.
isEmptyList               : 判断List是否为空.
isEmptyMap                : 判断Map是否为空.
isEmpty                   : 判断对象是否为空.(String List Map).
isNotEmpty                : 判断对象是否非空.(String List Map).
twoListIsEqual            : 判断两个List是否相等.
isMobileSimple            : 简单验证手机号
isMobileExact             : 精确验证手机号
isTel                     : 验证电话号码
isIDCard                  : 验证身份证号码
isIDCard15                : 验证身份证号码 15 位
isIDCard18                : 简单验证身份证号码 18 位
isIDCard18Exact           : 精确验证身份证号码 18 位
isEmail                   : 验证邮箱
isURL                     : 验证 URL
isZh                      : 验证汉字
isDate                    : 验证 yyyy-MM-dd 格式的日期校验,已考虑平闰年
isIP                      : 验证 IP 地址
isUserName                : 验证用户名
isQQ                      : 验证 QQ
  • TextUtil
isEmpty                     : isEmpty.
formatSpace4                : 每隔4位加空格,格式化银行卡.
formatComma3                : 每隔3三位加逗号.
formatDoubleComma3          : 每隔3三位加逗号.
hideNumber                  : 隐藏号码.
replace                     : replace.
split                       : split.
reverse                     : reverse.
  
/// example
String phoneNo = TextUtil.formatSpace4("15845678910"); // 1584 5678 910
String num     = TextUtil.formatComma3("1234"); // 123,4
String phoneNo = TextUtil.hideNumber("15845678910")// 158****8910
///(xx)为可配置输出
enum DayFormat {
  ///(小于30s->刚刚)、x分钟、x小时、(昨天)、x天.
  Simple,
  ///(小于30s->刚刚)、x分钟、x小时、[今年: (昨天/1天前)、(2天前)、MM-dd],[往年: yyyy-MM-dd].
  Common,
  ///小于30s->刚刚)、x分钟、x小时、[今年: (昨天 HH:mm/1天前)、(2天前)、MM-dd HH:mm],[往年: yyyy-MM-dd HH:mm].
  Full,
}
///Timeline信息配置.
abstract class TimelineInfo {
  String suffixAgo(); //suffix ago(后缀 后).
  String suffixAfter(); //suffix after(后缀 前).
  int maxJustNowSecond() => 30; // max just now second.
  String lessThanOneMinute() => ''; //just now(刚刚).
  String customYesterday() => ''; //Yesterday(昨天).优先级高于keepOneDay
  bool keepOneDay(); //保持1天,example: true -> 1天前, false -> MM-dd.
  bool keepTwoDays(); //保持2天,example: true -> 2天前, false -> MM-dd.
  String oneMinute(int minutes); //a minute(1分钟).
  String minutes(int minutes); //x minutes(x分钟).
  String anHour(int hours); //an hour(1小时).
  String hours(int hours); //x hours(x小时).
  String oneDay(int days); //a day(1天).
  String days(int days); //x days(x天).
}
setLocaleInfo               : 自定义设置配置信息.
formatByDateTime            : 格式输出时间轴信息 by DateTime .
format                      : 格式输出时间轴信息.
formatA                     : 格式输出时间轴信息. like QQ.
setInterval                 : 设置Timer间隔.
setTotalTime                : 设置倒计时总时间.
startTimer()                : 启动定时Timer.
startCountDown              : 启动倒计时Timer.
updateTotalTime             : 重设倒计时总时间.
cancel                      : 取消计时器.
setOnTimerTickCallback      : 计时器回调.
isActive                    : Timer是否启动.

Flutter Demos

  • |--demos
    • |-- city_select_page.dart 城市列表(索引&悬停)示例
    • |-- date_page.dart 日期格式化示例
    • |-- image_size_page.dart 获取网络/本地图片尺寸示例
    • |-- money_page.dart 金额(元转分/分转元)示例
    • |-- pinyin_page.dart 汉字转拼音示例
    • |-- regex_page.dart 正则工具类示例
    • |-- round_portrait_page.dart 圆形圆角头像示例
    • |-- timeline_page.dart 时间轴示例
    • |-- timer_page.dart 倒计时/定时器示例
    • |-- widget_page.dart 获取Widget尺寸/屏幕坐标示例

Thanks

本库部分源码参考,正则,时间轴。
Blankj AndroidUtilCode 强大易用的安卓工具类库。
Andres Araujo timeago Dart时间轴库。
a14n decimal 精确运算,避免精度丢失。

关于作者

GitHub : Sky24n
掘金     : Sky24n
简书     : Sky24n

Changelog

Please see the Changelog page to know what's recently changed.

Apps

flutter_wanandroid
Moss.
A GitHub client app developed with Flutter, which supports Android iOS Web.
Web :Flutter Web.

GitHub

https://github.com/Sky24n/common_utils
Comments
  • 1. 编译报错

    ../../../../development/flutter/.pub-cache/hosted/pub.flutter-io.cn/common_utils-2.0.2/lib/src/money_util.dart:87:59: Error: The method 'toInt' isn't defined for the class 'Decimal'.

    • 'Decimal' is from 'package:decimal/decimal.dart' ('../../../../development/flutter/.pub-cache/hosted/pub.flutter-io.cn/decimal-2.0.0/lib/decimal.dart'). Try correcting the name to the name of an existing method, or defining a method named 'toInt'. return NumUtil.multiplyDecStr(yuan.toString(), '100').toInt(); ^^^^^ ../../../../development/flutter/.pub-cache/hosted/pub.flutter-io.cn/common_utils-2.0.2/lib/src/num_util.dart:134:29: Error: A value of type 'Rational' can't be returned from a function with return type 'Decimal'.
    • 'Rational' is from 'package:rational/rational.dart' ('../../../../development/flutter/.pub-cache/hosted/pub.flutter-io.cn/rational-2.0.0/lib/rational.dart').
    • 'Decimal' is from 'package:decimal/decimal.dart' ('../../../../development/flutter/.pub-cache/hosted/pub.flutter-io.cn/decimal-2.0.0/lib/decimal.dart'). return Decimal.parse(a) / Decimal.parse(b); ^
    Reviewed by iLoveNintendo at 2021-11-30 04:38
  • 2. MissingPluginException

    你好,我使用了你的库里面的日志打印,出现了MissingPluginException(No implementation found for method logE on channel x_log) 请问是什么原因导致的,是我的配置不对吗? 环境: sdk: ">=2.1.0 <3.0.0" common_utils: ^1.1.3

    具体的日志内容如下: E/flutter (20889): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method logE on channel x_log) E/flutter (20889): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7) E/flutter (20889): E/flutter (20889): #1 Log.e (package:ddw/utils/log_utils.dart:39:16) E/flutter (20889): #2 HttpUtil._onError (package:ddw/framework/net/http_util.dart:174:9) E/flutter (20889): #3 HttpUtil.requestNetwork. (package:ddw/framework/net/http_util.dart:120:9) E/flutter (20889): #4 _rootRunUnary (dart:async/zone.dart:1132:38) E/flutter (20889): #5 _CustomZone.runUnary (dart:async/zone.dart:1029:19) E/flutter (20889): #6 _FutureListener.handleValue (dart:async/future_impl.dart:137:18) E/flutter (20889): #7 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45) E/flutter (20889): #8 Future._propagateToListeners (dart:async/future_impl.dart:707:32) E/flutter (20889): #9 Future._completeWithValue (dart:async/future_impl.dart:522:5) E/flutter (20889): #10 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15) E/flutter (20889): #11 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13) E/flutter (20889): #12 HttpUtil._request (package:ddw/framework/net/http_util.dart) E/flutter (20889): E/flutter (20889): #13 HttpUtil.requestNetwork (package:ddw/framework/net/http_util.dart:103:18) E/flutter (20889): E/flutter (20889): #14 _LoginPageState._login (package:ddw/pages/login/page/login_page.dart:143:29) E/flutter (20889): E/flutter (20889): #15 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14) E/flutter (20889): #16 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:729:32) E/flutter (20889): #17 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) E/flutter (20889): #18 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11) E/flutter (20889): #19 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:312:7) E/flutter (20889): #20 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27) E/flutter (20889): #21 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20) E/flutter (20889): #22 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22) E/flutter (20889): #23 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7) E/flutter (20889): #24 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7) E/flutter (20889): #25 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7) E/flutter (20889): #26 _rootRunUnary (dart:async/zone.dart:1136:13) E/flutter (20889): #27 _CustomZone.runUnary (dart:async/zone.dart:1029:19) E/flutter (20889): #28 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7) E/flutter (20889): #29 _invoke1 (dart:ui/hooks.dart:263:10) E/flutter (20889): #30 _dispatchPointerDataPacket (dart:ui/hooks.dart:172:5) E/flutter (20889):

    Reviewed by jisuz at 2019-09-17 03:56
  • 3. decimal >=2.0.0 break

    • Return type changed https://github.com/a14n/dart-decimal/commit/d03e865f30e81889ea85d1899d974cc3d0c39671#diff-f1c57ad606ae249192fad6d5c8d3837d2af89a04d1a03a8b6067c51f1bc1671dR110
    • toInt deleted https://github.com/a14n/dart-decimal/commit/d03e865f30e81889ea85d1899d974cc3d0c39671#diff-f1c57ad606ae249192fad6d5c8d3837d2af89a04d1a03a8b6067c51f1bc1671dL176

    If we want use > 2.0.0, we should to release v3.

    Reviewed by Runrioter at 2021-12-23 05:12
  • 4. DateUtil.getDateStrByMs在1.2版本中不存在

    我项目使用的是flustars: ^0.2.6+1,使用的是common_utils1.1.3,在新环境flutter pub get 拉取的是1.2版本,报错DateUtil.getDateStrByMs不存在。在yaml文件添加common_utils1.1.3插件依赖版本还是不行,请问要怎么处理啊

    Reviewed by byteslaves at 2020-05-29 15:17
  • 5. dateTimeSeparate 分隔符替换无效

    你好 我这边使用DateUtils的时候,替换日期和时间中间的分隔符未起作用

    DateUtil.getDateStrByDateTime(
            date,
            format: DateFormat.NORMAL,
            dateSeparate: "/",
            timeSeparate: ".",
          );
    
    Reviewed by realchen at 2018-09-28 09:11
  • 6. flutter Decimal 升级2.0.1 报错

       ^
    

    /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:70:10: Error: Type 'Decimal' not found. static Decimal addDec(num a, num b) { ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:76:10: Error: Type 'Decimal' not found. static Decimal subtractDec(num a, num b) { ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:82:10: Error: Type 'Decimal' not found. static Decimal multiplyDec(num a, num b) { ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:88:10: Error: Type 'Decimal' not found. static Decimal divideDec(num a, num b) { ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:93:10: Error: Type 'Decimal' not found. static Decimal remainder(num a, num b) { ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:118:10: Error: Type 'Decimal' not found. static Decimal addDecStr(String a, String b) { ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:123:10: Error: Type 'Decimal' not found. static Decimal subtractDecStr(String a, String b) { ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:128:10: Error: Type 'Decimal' not found. static Decimal multiplyDecStr(String a, String b) { ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:133:10: Error: Type 'Decimal' not found. static Decimal divideDecStr(String a, String b) { ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:138:10: Error: Type 'Decimal' not found. static Decimal remainderDecStr(String a, String b) { ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:119:12: Error: Undefined name 'Decimal'. return Decimal.parse(a) + Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:119:31: Error: Undefined name 'Decimal'. return Decimal.parse(a) + Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:124:12: Error: Undefined name 'Decimal'. return Decimal.parse(a) - Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:124:31: Error: Undefined name 'Decimal'. return Decimal.parse(a) - Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:129:12: Error: Undefined name 'Decimal'. return Decimal.parse(a) * Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:129:31: Error: Undefined name 'Decimal'. return Decimal.parse(a) * Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:134:12: Error: Undefined name 'Decimal'. return Decimal.parse(a) / Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:134:31: Error: Undefined name 'Decimal'. return Decimal.parse(a) / Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:139:12: Error: Undefined name 'Decimal'. return Decimal.parse(a) % Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:139:31: Error: Undefined name 'Decimal'. return Decimal.parse(a) % Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:144:12: Error: Undefined name 'Decimal'. return Decimal.parse(a) < Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:144:31: Error: Undefined name 'Decimal'. return Decimal.parse(a) < Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:149:12: Error: Undefined name 'Decimal'. return Decimal.parse(a) <= Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:149:32: Error: Undefined name 'Decimal'. return Decimal.parse(a) <= Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:154:12: Error: Undefined name 'Decimal'. return Decimal.parse(a) > Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:154:31: Error: Undefined name 'Decimal'. return Decimal.parse(a) > Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:159:12: Error: Undefined name 'Decimal'. return Decimal.parse(a) >= Decimal.parse(b); ^^^^^^^ /D:/flutter_windows_2.0.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/common_utils-2.0.2/lib/src/num_util.dart:159:32: Error: Undefined name 'Decimal'. return Decimal.parse(a) >= Decimal.parse(b);

    Reviewed by yangchaoxun at 2022-02-11 07:58
  • 7. 在Flutter2.8.0上报错了

    ../../Develop/flutter/.pub-cache/hosted/pub.flutter-io.cn/common_utils-2.0.2/lib/src/money_util.dart:87:59: Error: The method 'toInt' isn't defined for the class 'Decimal'. - 'Decimal' is from 'package:decimal/decimal.dart' ('../../Develop/flutter/.pub-cache/hosted/pub.flutter-io.cn/decimal-2.0.0/lib/decimal.dart'). Try correcting the name to the name of an existing method, or defining a method named 'toInt'. return NumUtil.multiplyDecStr(yuan.toString(), '100').toInt();

    Reviewed by flutting at 2021-12-11 09:42
  • 8. README里formatComma3的输出是不对的

    README中 String num = TextUtil.formatComma3("12345678"); // 123,456,78 应为 String num = TextUtil.formatComma3("12345678"); // 12,345,678

    Reviewed by WeiCongcong at 2020-04-09 09:18
  • 9. [text_util.dart]格式化参数存在问题

    /// 每隔 x位 加 pattern, 从末尾开始 static String formatDigitPatternEnd(String text, {int digit = 4, String pattern = ' '}) { String temp = reverse(text); temp = formatDigitPattern(temp, digit: 3, pattern: ','); temp = reverse(temp); return temp; }

    pattern 参数问题

    Reviewed by yunhe-lin at 2019-12-09 03:48
  • 10. isActive 无法返回布尔值

    bool _setTime() {

      if(timerCountDown.isActive()){ return false;}
      timerCountDown = new TimerUtil(mInterval: 1000, mTotalTime: 90 * 1000);
      timerCountDown.setOnTimerTickCallback((int value) {
        double tick = (value / 1000);
        setState(() {
          timeOut = tick.toInt().toString();
        });
      });
      timerCountDown.startCountDown();
    

    }

    v 1.0.9

    Reviewed by js1121302139 at 2018-12-25 12:46
  • 11. MoneyUtil 现在只支持,int 的数据类型,为什么不支持为 double 类型呢,保留两位小数位的精度呢?

    ` /// fen to yuan, format output. /// 分 转 元, format格式输出.

    static String changeF2Y(int amount, {MoneyFormat format = MoneyFormat.NORMAL}) { if (amount == null) return null; String moneyTxt; double yuan = NumUtil.divide(amount, 100); switch (format) { case MoneyFormat.NORMAL: moneyTxt = yuan.toStringAsFixed(2); break; case MoneyFormat.END_INTEGER: if (amount % 100 == 0) { moneyTxt = yuan.toInt().toString(); } else if (amount % 10 == 0) { moneyTxt = yuan.toStringAsFixed(1); } else { moneyTxt = yuan.toStringAsFixed(2); } break; case MoneyFormat.YUAN_INTEGER: moneyTxt = (amount % 100 == 0) ? yuan.toInt().toString() : yuan.toStringAsFixed(2); break; } return moneyTxt; }

    `

    建议将 参数 amount 的类型调整为 double

    Reviewed by hqwlkj at 2020-06-27 01:56
  • 12. NumUtil.divide 存在的问题

    NumUtil.divide 方法,当 a/b = 1/3 时,

    报错信息如下:

    'package:decimal/decimal.dart': Failed assertion: line 27 pos 38: '_rational.hasFinitePrecision': is not true.
    

    image

    使用 toDecimal() 方法需要添加 scaleOnInfinitePrecision 参数

    Reviewed by LiWenHui96 at 2022-02-14 06:04
  • 13. 会显示一分之后,是什么原因

    int elapsed = _locTimeMs - ms; String suffix; if (elapsed < 0) { suffix = _info.suffixAfter(); // suffix after is empty. user just now. if (suffix.isNotEmpty) { elapsed = elapsed.abs(); _dayFormat = DayFormat.Simple; } else { return _info.lessThanOneMinute(); } }

    Reviewed by shenggen1987 at 2021-08-20 10:14

Related

A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

Nov 17, 2021
A Dart library to parse Portable Executable (PE) format

pefile A Dart library to parse Portable Executable (PE) format Usage A simple usage example: var pe = pefile.parse('C:\\Windows\\System32\\notepad.exe

Dec 25, 2021
An alternative random library for Dart.

Randt Randt library for Dart... Description Use Randt to get a random integer from a list, generate random integer in a specific range and generate ra

Nov 21, 2021
The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.
The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

Oct 8, 2021
A comprehensive, cross-platform path manipulation library for Dart.

A comprehensive, cross-platform path manipulation library for Dart. The path package provides common operations for manipulating paths: joining, split

May 12, 2022
A fast algorithm for finding polygon pole of inaccessibility implemented as a Dart library.

polylabel Dart port of https://github.com/mapbox/polylabel. A fast algorithm for finding polygon pole of inaccessibility implemented as a Dart library

Nov 13, 2021
Dart library for unescaping HTML-encoded strings

html_unescape A Dart library for unescaping HTML-encoded strings. Supports: Named Character References ( ) 2099 of them Decimal Character Referen

Mar 10, 2022
This is a dart library covering nearly 100% of the latest Planning Center public API.

Planning Center API for Dart Planning Center is an online platform for church management. It provides multiple apps for things like check-ins, service

Mar 17, 2022
A JMAP client library in Dart to make JMAP method calls and process the responses

JMAP Dart client A JMAP client library to make JMAP method calls and process the responses. We most notably use it to write the TMail Flutter applicat

May 26, 2022
Library for help you make userbot or bot telegram and support tdlib telegram database and only support nodejs dart and google-apps-script

To-Do telegram client dart ✅️ support multi token ( bot / userbot ) ✅️ support bot and userbot ✅️ support telegram-bot-api local server ✅️ support tel

Apr 30, 2022
A Pure Dart Utility library that checks for an Active Internet connection

This Code comes from https://github.com/komapeb/data_connection_checker * ?? Internet Connection Checker A Pure Dart Utility library that checks for a

May 26, 2022
Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques

Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques. The use of dynamic reflection is constrained in order to ensure that the specialized code can be generated and will have a reasonable size.

May 18, 2022
A library for Dart that generates fake data

faker A library for Dart that generates fake data. faker is heavily inspired by the Python package faker, and the Ruby package ffaker. Usage A simple

May 16, 2022
Dart wrapper via dart:ffi for https://github.com/libusb/libusb

libusb Dart wrapper via dart:ffi for https://github.com/libusb/libusb Environment Windows(10) macOS Linux(Ubuntu 18.04 LTS) Usage Checkout example Fea

May 18, 2022
Extensible Dart interpreter for Dart with full interop

dart_eval is an extensible interpreter for the Dart language, written in Dart. It's powered under the hood by the Dart analyzer, so it achieves 100% c

May 24, 2022
Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

May 19, 2022
Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.
Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

May 19, 2022
This library contains methods that make it easy to consume Mpesa Api.

This library contains methods that make it easy to consume Mpesa Api. It's multi-platform, and supports CLI, server, mobile, desktop, and the browser.

Dec 15, 2021
Scribble is a lightweight library for freehand drawing in Flutter supporting pressure, variable line width and more!
Scribble is a lightweight library for freehand drawing in Flutter supporting pressure, variable line width and more!

Scribble Scribble is a lightweight library for freehand drawing in Flutter supporting pressure, variable line width and more! A

May 26, 2022