randomString method
生成随机字符串
src 生成字符串的来源字符串,默认大小写字母和数字
useNumber 是否使用数值,使用了src将无效
useLowerChars 是否使用小写字母,使用了src将无效
useUpperChars 是否使用大写字母,使用了src将无效
Implementation
String randomString({
String? src,
bool useNumber = true,
bool useLowerChars = true,
bool useUpperChars = true,
}) {
if (this <= 0) return "";
var source = src;
if (source.isNullOrEmpty) {
source = '';
if (useUpperChars) source += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (useLowerChars) source += 'abcdefghijklmnopqrstuvwxyz';
if (useNumber) source += '1234567890';
}
var random = Random();
return List.generate(this, (index) => source![random.nextInt(source.length)]).join();
}