//先定义一个非常low的常量 const _charsAll = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; //然后定义一个随机生成字符串的方法 String getRandomString(){ String code = ""; for (var i = 0; i < widget.vCodeNum; i++) { code = code + _charsAll[Random().nextInt(_charsAll.length)]; } return code; }
Flutter 一个随机生成字符串的方法
19 min read