generateRandomStringByLength static method

String generateRandomStringByLength({
  1. int length = 10,
})

生成指定长度随机字符串

Implementation

static String generateRandomStringByLength({int length = 10}) {
  const characters =
      '1234567890AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz';
  Random random = Random();
  return String.fromCharCodes(Iterable.generate(length,
      (_) => characters.codeUnitAt(random.nextInt(characters.length))));
}