Flutter工具集插件kt_utils的使用
Flutter工具集插件kt_utils的使用
使用
只需导入kt_utils.dart
import 'package:kt_utils/kt_utils.dart';
字符串方法
plus
- 合并文本toCapitalize
- 首字母大写toInt
- 转换为整数toDouble
- 转换为双精度浮点数reversed
- 反转文本toTitleCase
- 首字母大写所有单词containsDigit
- 检查是否包含数字isEmailValid
- 检查电子邮件是否有效encodeBase64
- 将文本编码为Base64decodeBase64
- 从Base64解码为可读文本isDigit
- 检查文本是否只包含数字isLowerCase
- 检查所有字母是否小写isUpperCase
- 检查所有字母是否大写isAlpha
- 检查文本是否只包含字母swapCase
- 改变给定文本的大小写last
- 获取最后一个字符isNotNullEmpty
- 检查字符串是否不为空且不为null
双精度浮点数方法
roundDouble
- 四舍五入到指定的小数位数
列表方法
forEachIndexed
- 带有索引的forEachlastIndex
- 列表的最后一个索引random
- 返回随机对象count
- 返回给定项的数量
示例代码
import 'package:kt_utils/kt_utils.dart';
void main(List<String> args) {
// 字符串
print('lorem'.toCapitalize()); // 输出 "Lorem"
print('Lorem'.plus(' Ipsum')); // 输出 "Lorem Ipsum"
print('Lorem Ipsum'.reversed()); // 输出 "muspi merol"
print('10'.toInt()); // 输出 10
print('10.3'.toDouble()); // 输出 10.3
print('lorem ipsum dolor'.toTitleCase()); // 输出 "Lorem Ipsum Dolor"
print('123abc'.containsDigit()); // 输出 true
print('abc@abc.test'.isEmailValid()); // 输出 true
print('hello world'.encodeBase64()); // 输出 "aGVsbG8gd29ybGQ="
print('aGVsbG8gd29ybGQ='.decodeBase64()); // 输出 "hello world"
print('10'.isDigit()); // 输出 true
print('lorem ipsum'.isLowerCase()); // 输出 true
print('LOREM IPSUM'.isUpperCase()); // 输出 true
print('ŹŻŚĄ å abcd'.isAlpha()); // 输出 false
print('LorEM IpsUM'.swapCase()); // 输出 "lOREm iPSum"
print('example'.last()); // 输出 "e"
// 双精度浮点数
print(5.432.roundDouble(1)); // 输出 5.4
print(7.6.roundDouble(0)); // 输出 8.0
// 列表
List<String> ls = ['A', 'B', 'C', 'D', 'A', 'D', 'A'];
ls.forEachIndexed((index, element) {
print('Index $index - Element $element');
}); // 输出多个索引和元素
print(ls.random()); // 输出一个随机元素
print(ls.lastIndex); // 输出 6
print(ls.count((e) => e == 'A')); // 输出 3
}
更多关于Flutter工具集插件kt_utils的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复