# flutter_kit **Repository Path**: flutter-library/flutter_kit ## Basic Information - **Project Name**: flutter_kit - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-09-12 - **Last Updated**: 2024-11-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## flutter kit usages document #### 1、事件 #### 1.1 事件快速点击处理 ```dart //使用示例 void onEvent(){ if(ClickEvent.isFastClick()){ return; } //这里处理你的业务逻辑... } ``` #### 2、系统方法 #### 2.1 剪贴板使用 ```dart //获取剪贴板数据 ClipboardUtils.getClipboardData().then((text) => { //text剪贴板内容 }); //或 var text = await ClipboardUtils.getClipboardData(); //设置剪贴板数据 ClipboardUtils.setClipboardData(text); ``` #### 3、常用工具类 #### 3.1 json工具类 ```dart JsonUtils.toJson(Object? obj) //将对象转换为json字符串 Map map = JsonUtils.fromJson(String data) //从json字符串转换为map对象 List list = JsonUtils.fromList(String data) //从json字符串转换为list列表 /// 从json字符串得到某个属性值 /// 示例: /// JsonUtils.getValue("name",'{"name":"china","date":"2024"}') //输出china /// [keyName] 属性名 /// [json] json内容 /// [isFillWhitespace] 是否去除json字符串的空格或换行符 var value = JsonUtils.getValue({String keyName = "", String json = "", bool isFillWhitespace = false}) ``` #### 3.2 SoftUtils工具类 ```dart SoftUtils.hideSoft(BuildContext context) //隐藏软键盘 ``` #### 3.3 倒计时工具类 ```dart var countdown = CountdownTimer(); /// 根据剩余时间倒计时 /// [restOfTime] 剩余时间(单位毫秒) /// [callback] 回调(null时不做计时处理) /// [step] 计时步长默认1秒回调一次 countdown.startCountdown(int restOfTime, CountdownCallback? callback, {int step = 1000}) /// 根据开始结束时间倒计时 /// [startTime] 开始时间(单位毫秒) /// [endTime] 结束时间(单位毫秒) /// [callback] 回调 /// [step] 计时步长默认1秒回调一次 countdown.start(int startTime, int endTime, CountdownCallback callback, {int step = 1000}) /// 停止倒计时 countdown.stop() /// 剩余时间差 countdown.diffTime ``` #### 3.4 按天、小时、分、秒计时器 ```dart var timing = TimingCount(); //开始计时 timing.start(void Function(int days, int hours, int minutes, int seconds) callback, {int step = 1000}) timing.stop() //停止计时 timing.duration; //计时持续时间 ``` #### 4、扩展 #### 4.1 dynamic扩展 ```dart var result = "false"; var status = result.isTrue; //输出true or false enum Gender { male, female } Gender.female.name //name扩展,输出枚举名称 var num = "111"; var digit = num.isNumeric; //判断是否为数字类型,输出true or false ``` #### 4.2 Object扩展 ``` var result = "11" result.toDouble() //输出11.0 ``` #### 4.3 String扩展 ```dart var uri = "xxxx?name=11&age=2" uri.toMap("&",secondSplit:"=",true) //输出map类型:{"name":"11","age":"2"} //根据连接字符拼接的字符串转换成list "2&71&3&25".toList("&") //url参数合并,返回合并后url var uri = "xxxx?name=11&age=2" var uri2 = "xxxx?name2=22" uri2.toMergeUrl(uri) //输出:uri="xxxx?name=11&age=2&name2=22" //数字字符转换为num(eg. for long float) 2.toNum() //金额格式化 "20.3".toFormatString("#.##") //输出: 20.30 //sha1加密 "123456".toSha1 //输出:7c4a8d09ca3762af61e59520943dc26494f8941b //sha256加密 "123456".toSha256 //输出:8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92 //生成md5 "123456".generateMd5 //输出:e10adc3949ba59abbe56e057f20f883e ``` #### 4.4 double扩展 ```dart var n=12.3; n.doubleInt; //输出:12 //double is null or 0 n.isNullOrZero; //输出:false //-- n.reduce(3); //输出:9.3 //++ n.add(3); //输出:15.3 //保留小数位数 n.toFormatString("#.##"); //输出:12.30 ``` #### 4.5 int扩展 ```dart var n=12; //int is null or 0 n.isNullOrZero; //输出:false //-- n.reduce(3); //输出:9 //++ n.add(3); //输出:15 //时间戳转换本地时间 var timestamp = xxxxx; timestamp.toLocalTime(isUtc:true); //DateTime格式 ``` *其它扩展参考代码extend目录文件代码*