randomColor static method

Color randomColor()

随机生成一个颜色

使用Dart内置的Random.secure生成RGB三通道的0~254随机色(透明度始终为255)。

示例:

Color color = CommonUtil.randomColor();
print(color); // 例如:Color(0xffff67ad)

返回值: 返回一个随机生成的Color

Implementation

static Color randomColor() {
  return Color.fromARGB(255, Random.secure().nextInt(255),
      Random.secure().nextInt(255), Random.secure().nextInt(255));
}