flutter 產(chǎn)生隨機(jī)顏色
- 相關(guān)代碼如下:
static Color slRandomColor({int r = 255, int g = 255, int b = 255, a = 255}) {
if (r == 0 || g == 0 || b == 0) return Colors.black;
if (a == 0) return Colors.white;
return Color.fromARGB(
a,
r != 255 ? r : Random.secure().nextInt(r),
g != 255 ? g : Random.secure().nextInt(g),
b != 255 ? b : Random.secure().nextInt(b),
);
}
需要導(dǎo)入以下兩個
import 'package:flutter/material.dart';
import 'dart:math';
有了隨機(jī)顏色媽媽再也不用但心選擇顏色了~ 哈哈哈哈哈
6666666~